$(document).ready(function(){
	$("body").addClass("jsEnabled");
	var CP = $("body").attr("id");
	
	initValidation(CP);
	initGallery(CP);
	initSlideShow(CP);
	initSliderLock(CP);
});

function initValidation(CP){

	if (CP == "contact-us") {
		$("#directionsForm").validate({
			rules: {
				saddr: "required"
			}
		});
		$("#contactForm").validate({
			rules: {
				name: "required",
				email: {
					required: true,
					email: true
				},
				phone: "required"
			},
			messages: {
				name: "Please enter your Name",
				email: {
					required: "Please enter your Email Address",
					email: "Please enter a valid email address."
				},
				phone: "Please enter your Phone Number"
			}
		});
	}
	if (CP == "blog"){
		$("#commentform").validate({
			rules: {
			name: "required",
			email: {
				required: false,
				email: true
			},
			comments: {
				required: true,
				maxlength: 255
			}
		},
		messages: {
			name: "Please enter your Name",
			email: {
				email: "Please enter a valid email address."
			},
			comments: {
				required: "Please enter you comments!",
				maxlength: "Your comment is too long!"
			}
		}
		});
		
	}
}


function initGallery(CP){
	if ($("body").hasClass("product")){
		$("a", "#ImageList").click(function(){
		
			var imgsrc = $("img", this).attr("src");
			var imgtitle = $("img", this).attr("title");
			var imgcurrent = $("#MainViewer").attr("src");
			
			if (imgcurrent != imgsrc) {
				$(".Current", "#ImageList").removeClass("Current");
				$(this).addClass("Current");
				
				$("#MainViewer").fadeOut(function(){
					$(this).attr("src", imgsrc).attr("title", imgtitle).fadeIn();
				});
			}
			
			return false;
		});
	}
}


function initSlideShow(pid){
	if(pid=="index"){		
		$('#hs-show').cycle({
			next: '#hs-next',
			prev: '#hs-prev',
			timeout: 5000,
			pause : true,
			sync: true
		});
	}
	
}

function initSliderLock(CP){
	if(CP=="blog"){
		// call the plugin on the desired form
        $("#commentform").slideLock({

            // set the options - all are given, not all are required
            labelText: "Slide to Unlock:",
            noteText: "",
            lockText: "Locked",
            unlockText: "Unlocked",
            iconURL: "lib/img/chrome/arrow_right.png",
            inputID: "sliderInput",
            onCSS: "#333",
            offCSS: "#aaa",
            inputValue: 1,
            saltValue: 9,
            checkValue: 10,
            js_check: "js_check",
            submitID: "#submit"

        });
		
	}
	
}
