// digitalsuccessgroup.net js functions

//preLoadImages for jQuery
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function(img_array) {
    var args_len = img_array.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = img_array[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


jQuery(function($){ // on page ready  
  
  
  $("span.nav_item").each(function(index){
								  $(this).mouseover(function(){$(this).stop(); $(this).animate({opacity:1}, 100);});
								  $(this).mouseout(function(){$(this).stop(); $(this).animate({opacity:0}, 375);});
								  });
  
if(!$.browser.msie){
  $("a.logo").each(function(index){
								  $(this).mouseover(function(){$(this).stop(); $(this).animate({opacity:1}, 375);});
								  $(this).mouseout(function(){$(this).stop(); $(this).animate({opacity:0}, 375);});
								  });

  
  $("a.findouthow").each(function(index){
								  $(this).mouseover(function(){$(this).stop(); $(this).animate({opacity:1}, 375);});
								  $(this).mouseout(function(){$(this).stop(); $(this).animate({opacity:0}, 375);});
								  });
}
  
  
  $("a.portfolio_screenshot").each(function(index){
								  $(this).click(function(){
										var pss = $("div.portfolio_screenshots");
										pss.stop();
										var target = (parseInt($(this).text()) - 1) * 362;
										pss.animate({top:'-'+target+'px'}, 250, function(){});
										});
								  });
	
  $("#free_consultation_send").click( function(){ submitForm(this.form); return false; } );
  
}); // end on ready


function submitForm(formObj){	
	$("p.formInfo").css( {'backgroundColor': '#0B0'} );
	$("p.formInfo").html('Sending...');
	
	$.post('/index.php/site/freeconsultation', $(formObj).serialize(), function(data){
																				if(data != '1'){
																					$("p.formInfo").stop();
																					$("p.formInfo").css( {'backgroundColor': '#B00'} );
																					$("p.formInfo").html(data);
																				}
																				else{
																					$("p.formInfo").html("Sent!");
																					$("#contact_form_controls").hide();
																				}
																				});
}