$(function() {

		if ($.browser.msie && $.browser.version.substr(0,1)<8) {
			var zIndexNumber = 1000;
			$('div').each(function() {
				$(this).css('zIndex', zIndexNumber);
				zIndexNumber -= 10;
			});
		}
	




	if ($('.two-col').length){
		$('.two-col').easyListSplitter({
		   colNumber: 2,
		   direction: 'vertical'
		});
	}
	
	if ($('.label').length){
		$(".label").inFieldLabels(); 
	}
	$("a[rel]").overlay({
		fixed:false,
		mask:{
				color: '#333',
				loadSpeed: 200,
				opacity: 0.5
			}
	});

if($('#sign-up-form').length){
	$('#sign-up-form').validate();
}
if($('#contact-us-form').length){
	$('#contact-us-form').validate();
}
if($('#customer-log-in-form').length){
	$('#customer-log-in-form').validate();
}
if($('#vendor-log-in-form').length){
	$('#vendor-log-in-form').validate();
}
if($('#become-contractor-form').length){
	$('#become-contractor-form').validate();
}

if($('#dwm-contact-you-form').length){
		$('#dwm-contact-you-form').validate();
		$('#contact-subject').uiSelect({leftOffset: 0, topOffset: -7,addRequired:true,requiredClass:'isRequired'},'subjectList','subjectInput');
		$('.uiOptionMenu a').click(function(){
			$(this).parent().parent().parent().parent().find('label').fadeOut('fast');
		});
}



	if ($('form').length){
		
		//Classes to validate against
		$('.isRequired').each(function(){
			$(this).rules("add", {
				 required: true,
				 messages: {required: "This field is required."}
			});
		});	
		$('.emailRequired').each(function(){
			$(this).rules("add", {
				required: true,
				email: true,
				messages: {
					required: "This field is required.",
					email: "Please enter a VALID email address (e.g. name@company.com)"
				}
			});
		});	
		$('.numRequired').each(function(){
			$(this).rules("add", {
				required: true,
				digits: true,
				messages: {
					required: "This field is required.",
					digits: "Please enter a numerical value only."
				}
			});
		});
		$('.zipRequired').each(function(){
			$(this).rules("add", {
				required: true,
				digits: true,
			    minlength: 5,
			    maxlength: 5,
				messages: {
					required: "This field is required.",
					minlength: "Please enter a valid zip code.",
					maxlength: "Please enter a valid zip code.",
					digits: "Please enter a valid zip code."
				}
			});
		});
	}
	
	    
	
});

/** Function to change the image on the homepage. */
function changeImage(index, delay1, delay2, rightShift, speed1, speed2) {
	if ($('#scrollin-img').children('img').length == 1) {
		return;
	}
	var oldIndex = index;
	index++;
	if (index > $('#scrollin-img').children('img').length) {
		index = 1;
	}
	setTimeout("fadeIn(" + (index) + "," + speed2 + ")", (delay2*1000));
	$('#scrollin-img img:nth-child(' + oldIndex + ')').animate({
    	opacity: 0,
		marginLeft: rightShift + "px"
  	}, (speed1*1000) );
	setTimeout("moveBack(" + oldIndex + "," + rightShift + ")", (speed1*1000+1000));
	setTimeout("changeImage(" + index + ", " + delay1 + ", " + delay2 + ", " + rightShift + ", " + speed1 + ", " + speed2 + ")", (delay1*1000));
}

function fadeIn(index, speed) {
	$('#scrollin-img img:nth-child(' + index + ')').animate({
    		opacity: 1
  	}, (speed*1000) );
}

function moveBack(index, marginShift) {
	$('#scrollin-img img:nth-child(' + index + ')').css('margin-left', '0px');
}

/** Fix for MSIE. */
if ($.browser.msie) {
    $('#scrollin-img img').fadeTo(0, 0);
    $('#scrollin-img img:first-child').fadeTo(0, 1);
}

/**
 * Calls the change image function.
 *
 * @param int index      The index number to start with (typically 1).
 * @param int delay1     The delay between image right-shift events.
 * @param int delay2     The delay between when the image starts to right-shift and the next image starts to fade-in.
 * @param int rightShift The distance, in pixels, that the image should travel to the right.
 * @param int speed1     The speed, in seconds, of the right-shift transformation.
 * @param int speed2     The speed, in seconds, of the fade-in transformation.
 */
setTimeout("changeImage(1, 5, 1, 150, 2, 2)", 5000);

