$(document).ready(function(){   

	//-- product slide show
	if ($('#slideshow')) {
		$('#slideshow').cycle({
		prev: '#prev',
		next: '#next',
		timeout: 0
		});
	}
	
	//-- product description
	if ($("#descriptionbox").get(0)) {  //-- check if the actual DOM object exists
		var boxheight = ($("#descriptionbox")[0].clientHeight);
		var contentheight = ($("#descriptionbox")[0].scrollHeight);
		var clicked = false;
		
		if (contentheight > boxheight) {
			$('.moretext').css({ display : "block"});
		}
		
		$("#moretext").click(function(){
			clicked = true;
			
			$('.moretext').css({ display : "none"});
			
			if (contentheight > boxheight) {
				$("#descriptionbox").animate({ 
					opacity: 0.9,
					top: 250,
					height: 250,
					borderWidth: "10px"
				}, 750 , showCloseLink);
			}
		 });
		 
		 
		$("#closetext").click(function(){
			clicked = false;
			$('.closetext').css({ display : "none"});
			$('.moretext').css({ display : "block"});
			$("#descriptionbox").animate({ 
					opacity: 1,
					top: 490,
					height: 41,
					borderWidth: "10px"
				}, 750 );
		 });
		 
		 function showCloseLink() {
			$('.closetext').css({ display : "block"});
		 }
     }
     
    
    //-- validate user details form
   	if ($("#cdetailsForm").get(0)) {  //-- check if the actual DOM object exists
		 // validate userdetailform
		$("#cdetailsForm").validate({
			rules: {
				name: "required",
				surname: "required",
				street_d: "required",
				number_d: "required",
				postcode_d: "required",
				location_d: "required",
				country_d: "required",
				email: {
					required: true,
					email: true
				},
				agree: "required"
			},
			messages: {
				name: "",
				surname: "",
				street_d: "",
				number_d: "",
				postcode_d: "",
				location_d: "",
				country_d: "",
				email: "",
				agree: ""
			}
		});
	}
	
	//-- set focus to the first input field in a page
	$("input:text:first").focus();
	
});