var catOn=0
var pageHasSlideshow=false
	var ua=$.browser;


$(document).ready(function(){

	if(catOn > 0) {
		$("#cat_" + catOn).addClass("catNavOn");
		$("#cat_" + catOn + " span").addClass("arrowDown");
	}
	
	$(".closeIntLink").click(function() {
			$(".theInt").hide();
			$('[id^="cat_"]').removeClass("catNavOn");
			$('[id^="cat_"] span').removeClass("arrowDown");
//			if($.browser.msie && ua.version <= 7) {
//				$(".ie7PromoPanels").css({"padding-top":"0"});
//			}
			return false;
			}
		);
		
	$(".sliderkit-nav-clip ul li a").click(function() {
			$(".galBlackBG").show();
			$("#exGraphics").css({"z-index": -1,  "behavior":"none"});
			$(".msrpBox").css({"z-index": -1,  "behavior":"none"});
			$(".textDescription").css({"z-index": -1,  "behavior":"none"});
		}
	);
	
	//http://api.jquery.com/child-selector/ in the comments
	$(".brandSummary").hover(
	  function () {
		$('> .int-buttons .int-button', this).removeClass("int-button-faded");
		$('> .int-brandName .int-brandNameLink', this).addClass("int-brandNameOn");
	 }, 
	  function () {
		$('> .int-buttons .int-button', this).addClass("int-button-faded");
		$('> .int-brandName .int-brandNameLink', this).removeClass("int-brandNameOn");
	  }
	);
	
	$(".navPanel").hover(
	  function () {
		$('> h6', this).addClass("navPanelH6On");
	 }, 
	  function () {
		$('> h6', this).removeClass("navPanelH6On");
	  }
	);
	
	$(".genContent h3:first-child").css({"margin-top":"0px"});

	$(".paymentsButton").fancybox({
		'overlayShow'	:	true,
		'transitionIn' : 'elastic',
		'speedIn' : 200,
		'speedOut' : 100,
		'type' : 'iframe',
		'width' : 610,
		'height' : 280
	});

});

function extGraphics(i,n) {
	newBG="url(/colors/" + i + ")"
	$(".homeHero").css({"backgroundImage":newBG});
	$('[id^="d_"]').removeClass("exGraphicsNavOn");
	$("#d_" + n).addClass("exGraphicsNavOn");
	return false;
}

function closeGal() {
	$(".galBlackBG").hide();
	$("#exGraphics").css({"z-index": 999,"behavior":"url(/css/pie.htc)"});
	$(".msrpBox").css({"z-index": 999,"behavior":"url(/css/pie.htc)"});
	$(".textDescription").css({"z-index": 999,"behavior":"url(/css/pie.htc)"});
	$(".photosgallery-std .sliderkit-nav-clip ul li").removeClass("sliderkit-selected");
	$("#videoFrame").attr({"src":""});
	$("#videoFrame").attr({"src":"http://www.youtube.com/embed/yf6FdURJ9Ls?wmode=opaque"});
	return false;
}

function showInt(c) {
	$(".theInt").hide();
	$('[id^="cat_"]').removeClass("catNavOn");
	$('[id^="cat_"] span').removeClass("arrowDown");
	$("#int" + c).slideDown(200);
	$("#cat_" + c).addClass("catNavOn");
	$("#cat_" + c + " span").addClass("arrowDown");
	$("#theTour").hide()
	$("#int" + c).hover(
		function () {
			//nothing
		},
		function () {
			$("#theTour").show()
			$(this).hide();
			$('[id^="cat_"]').removeClass("catNavOn");
			$('[id^="cat_"] span').removeClass("arrowDown");
			if(catOn > 0) {
				$("#cat_" + catOn).addClass("catNavOn");
				$("#cat_" + catOn + " span").addClass("arrowDown");
			}
			if(pageHasSlideshow) {
				$('#slideshow').cycle('resume');
			}
		}
	);
	if(pageHasSlideshow) {
		$('#slideshow').cycle('pause');
	}
//	if($.browser.msie && ua.version <= 7) {
//		$(".ie7PromoPanels").css({"padding-top":"480px"});
//	}
	return false;
}

function valchangeOwner() {
	atLeastOneErr=false
	$("input[type=text]").css({ border : "1px solid #ccc"})
	$("label").css({ color : "#666" })
	if(document.changeOwnerForm.coFIN.value=='') { makeError('coFIN','changeOwner'); }
	if(document.changeOwnerForm.coVIN.value=='') { makeError('coVIN','changeOwner'); }
	if(document.changeOwnerForm.coBrandModelYear.value=='') { makeError('coBrandModelYear','changeOwner'); }
	if(document.changeOwnerForm.coMileage.value=='') { makeError('coMileage','changeOwner'); }
	if(document.changeOwnerForm.coNewOwnerName.value=='') { makeError('coNewOwnerName','changeOwner'); }
	if(document.changeOwnerForm.coNewOwnerAddress.value=='') { makeError('coNewOwnerAddress','changeOwner'); }
	if(document.changeOwnerForm.coNewOwnerCSZ.value=='') { makeError('coNewOwnerCSZ','changeOwner'); }
	if(document.changeOwnerForm.coNewOwnerPhone.value=='') { makeError('coNewOwnerPhone','changeOwner'); }
	if(document.changeOwnerForm.coNewOwnerEmail.value=='') { makeError('coNewOwnerEmail','changeOwner'); }
	if(document.changeOwnerForm.purchasedFrom.value=='') { makeError('purchasedFrom','changeOwner'); }
	if(atLeastOneErr) {
		return false;
	}
}

function valBrochure() {
	atLeastOneErr=false
	$("input[type=text],select").css({ border : "1px solid #ccc"})
	$("label").css({ color : "#666" })
	var isEmailOK=$("input[name=emailOK]:checked").val();
	var isPhoneOK=$("input[name=phoneOK]:checked").val();
	if(document.brochureForm.userFirstName.value=='') { makeError('userFirstName','brochure'); }
	if(document.brochureForm.userLastName.value=='') { makeError('userLastName','brochure'); }
	if(document.brochureForm.userAddress.value=='') { makeError('userAddress','brochure'); }
	if(document.brochureForm.userCity.value=='') { makeError('userCity','brochure'); }
	if(document.brochureForm.userState.value=='') { makeError('userState','brochure'); }
	if(document.brochureForm.userPostalCode.value=='') { makeError('userPostalCode','brochure'); }
	if(document.brochureForm.ppID.value=='') { makeError('ppID','brochure'); }
	if(isPhoneOK==1) {
		if(document.brochureForm.userPhone.value=='') { makeError('userPhone','brochure'); }
	}
	if(isEmailOK==1) {
		if(document.brochureForm.userEmail.value=='') { makeError('userEmail','brochure'); }
	}
	if(atLeastOneErr) {
		return false;
	}
}

function valService() {
	atLeastOneErr=false
	$("input[type=text],select,textarea").css({ border : "1px solid #ccc"})
	$("label").css({ color : "#666" })
	if(document.serviceForm.txt_userName.value=='') { makeError('txt_userName','service'); }
	if(document.serviceForm.txt_userEmail.value=='') { makeError('txt_userEmail','service'); }
	if(document.serviceForm.txt_userPhone.value=='') { makeError('txt_userPhone','service'); }
	if(document.serviceForm.txt_userCell.value=='') { makeError('txt_userCell','service'); }
	if(document.serviceForm.txt_arrival.value=='') { makeError('txt_arrival','service'); }
	if(document.serviceForm.txt_rvModel.value=='') { makeError('txt_rvModel','service'); }
	if(document.serviceForm.txt_rvSerialNumber.value=='') { makeError('txt_rvSerialNumber','service'); }
	if(document.serviceForm.txt_rvChassisNumber.value=='') { makeError('txt_rvChassisNumber','service'); }
	if(document.serviceForm.txt_serviceRequest1.value=='') { makeError('txt_serviceRequest1','service'); }
	if(atLeastOneErr) {
		return false;
	}
}


function valContact() {
	atLeastOneErr=false
	$("input[type=text]").css({ border : "1px solid #ccc"})
	$("label").css({ color : "#666" })
	$(".req").css({ color : "#305d33" })
	if(document.contactForm.uName.value=='') { makeError('uName','contact'); }
	if(document.contactForm.uEmail.value=='') { makeError('uEmail','contact'); }
	if(document.contactForm.uAddress.value=='') { makeError('uAddress','contact'); }
	if(document.contactForm.uCSZ.value=='') { makeError('uCSZ','contact'); }
	if(document.contactForm.uCountry.value=='') { makeError('uCountry','contact'); }
	
	var subj=$("input[name=eSubject]:checked").val()
	if(subj <= 5) {
		if(document.contactForm.rvFIN.value=='') { makeError('rvFIN','contact'); }
		if(document.contactForm.rvVIN.value=='') { makeError('rvVIN','contact'); }
		if(document.contactForm.rvYMM.value=='') { makeError('rvYMM','contact'); }
		if(document.contactForm.rvOwnership.value=='') { makeError('rvOwnership','contact'); }
		if(document.contactForm.rvMileage.value=='') { makeError('rvMileage','contact'); }
		if(!$("input[name=rvOwnership]:checked").val()) { makeError('rvOwnership','contact'); }
	}


	if(atLeastOneErr) {
		return false;
	}
}

function valMediaRequest() {
	atLeastOneErr=false
	if($('#theTerms').is(':checked')==false) {
		alert("Please agree to our terms and conditions by checking the box near the bottom of the form.");
		return false;
	}
	$("input[type=text],input[type=password],select").css({ border : "1px solid #ccc"})
	$("label").css({ color : "#666" })
	if(document.mediaForm.mediaFirstName.value=='') { makeError('mediaFirstName','media'); }
	if(document.mediaForm.mediaLastName.value=='') { makeError('mediaLastName','media'); }
	if(document.mediaForm.mediaEmail.value=='') { makeError('mediaEmail','media'); }
	if(document.mediaForm.mediaCompany.value=='') { makeError('mediaCompany','media'); }
	if(document.mediaForm.mediaTitle.value=='') { makeError('mediaTitle','media'); }
	if(document.mediaForm.mediaPhone.value=='') { makeError('mediaPhone','media'); }
	if(document.mediaForm.mediaFax.value=='') { makeError('mediaFax','media'); }
	if(document.mediaForm.mediaPassword.value=='') { makeError('mediaPassword','media'); }
	if(document.mediaForm.mediaPublication.value=='') { makeError('mediaPublication','media'); }
	if(document.mediaForm.mediaPubType.value=='') { makeError('mediaPubType','media'); }
	if(document.mediaForm.mediaURL.value=='') { makeError('mediaURL','media'); }
	if(document.mediaForm.mediaInterest.value=='') { makeError('mediaInterest','media'); }
	if(atLeastOneErr) {
		return false;
	}
}

function makeError(f,theForm) {
	atLeastOneErr=true;
	$("#" + f).css({ border : "1px solid #900"})
	$("#" + f).prev().css({ color : "#900" })
	$("#errBox" + theForm).show();
	window.scrollTo(0,0);
}
