$( function() {

	//Before&After Slideshow
	$('#compare').cycle({ 
		timeout: 5000, 
		speed:   500,
		fx: 'wipe',
		after: function() {
			$('#caption').html(this.alt);
		}
	});
	
	$('#slides ul li a').click(function() { 
		var idx = $(this).attr("href").charAt(1);
		var ba  = $(this).attr("href").charAt(2);
		var trans = 'wipe';
		
		//base index number
		idx = (idx-1)*2;
		
		if( ba == 'A' )
			idx++;
		else
			trans = 'scrollUp';

		$('#compare').cycle(idx, trans); 
		return false; 
	});

	//Quote Slideshow
	var quotes = [ 
								 "<p>Productivity is up, clarity is up and throughput is up.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>We've effectively put a hedge against future electric rates.</p><p style='text-align:right;'>- T&amp;H Lemont - Chicago, IL</p>", 
								 "<p>Productivity is up, clarity is up and throughput is up.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>Our electric bill has been extremely reduced.</p><p style='text-align:right;'>Rockford Toolcraft, Inc. - Rockford, IL</p>",
								 "<p>Much Brighter environment, much stronger, much cleaner.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>We would recommend Axon and we have.</p><p style='text-align:right;'>- T&amp;H Lemont - Chicago, IL</p>",
								 "<p>Our experience with Axon Electric has been wonderful.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>We chose Axon because of the people... a level of trust.</p><p style='text-align:right;'>- T&amp;H Lemont - Chicago, IL</p>",
								 "<p>I'm getting a stronger effort from our employees.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>It's like a new shop out there.</p><p style='text-align:right;'>Rockford Toolcraft, Inc. - Rockford, IL</p>",
								 "<p>There was zero interruption during installation.</p><p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>We've seen a cost savings immediately, over 50% reduction in our lighting cost.</p><p style='text-align:right;'>- T&amp;H Lemont - Chicago, IL</p>",
								 "<p>The biggest drawback of the lighting upgrade was that we had to clean all the walls in our facility. With the greatly improved lighting we could finally see all the dirt around the place. Not a bad problem to have!<p style='text-align:right;'>Amtec Molded Products - Rockford, IL</p>",
								 "<p>We were sold on the savings; However, after the new lighting was installed, we realized the saving were just a small portion of the benefits. We had production increases, quality improvements, and a surge in morale throughout the company.</p><p style='text-align:right;'>Rockford Toolcraft, Inc. - Rockford, IL</p>"
								 
	];
	var iq = Math.floor(Math.random() * quotes.length);
	
	var myTimeout = null;
	$( function(){
		$("#quote div").html( quotes[iq] );
		setTimeout( nextQuote1, 4000 );
	});
	
	function nextQuote1()
	{
		$("#quote div").fadeOut( 1000, nextQuote2 );
	}
	
	function nextQuote2()
	{
		iq = ++iq % quotes.length;
		$("#quote div").html( quotes[iq] );
		$("#quote div").fadeIn( 1000, function(){ setTimeout( nextQuote1, 4000 ); } );
	}



	//Contact form functions
	$('[placeholder]').focus(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		}
	}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
	}).blur();
	
	$('[placeholder]').parents('form').submit(function() {
		$(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
			}
		})
	});

	$("#contactSubmit").click( function(){
		$.ajax(
			{
				url:"mail.asp",
				type: "post",
				dataType: "json",
				data: "fName="      + encodeURIComponent($("#fName"    ).val()) +
							"&fEmail="    + encodeURIComponent($("#fEmail"   ).val()) + 
							"&fQuestion=" + encodeURIComponent($("#fQuestion").val()),
				beforeSend: function(){
					$("#loadingMsg").hide();
					$("#loadingImg").show();
					$("#loadingOverlay").show();
				},
				complete: function(){
					$("#loadingOverlay").fadeOut(3000);
				},
				success: function(response){
					$("#fName"    ).val("");
					$("#fEmail"   ).val("");
					$("#fQuestion").val("");

					$("#loadingMsg").html(response.message);
					$("#loadingMsg").show();
					$("#loadingImg").hide();
				},
				error: function(jqXHR, textStatus, errorThrown){
					 alert(errorThrown);
				}
			}
		);
		return false;
	});

});
