$(function() {

$(".scrollable").scrollable();

$(".items img").click(function() {

	// see if same thumb is being clicked
	if ($(this).hasClass("active")) { return; }

	// calclulate large image's URL based on the thumbnail URL (flickr specific)
	var url = $(this).attr("src").replace("_t", "");

	// get handle to element that wraps the image and make it semi-transparent
	var wrap = $("#image_wrap").fadeTo("medium", 0.5);

	// the large image from www.flickr.com
	var img = new Image();


	// call this function after it's loaded
	img.onload = function() {

		// make wrapper fully visible
		wrap.fadeTo("fast", 1);

		// change the image
		wrap.find("img").attr("src", url);

	};

	// begin loading the image from www.flickr.com
	img.src = url;

	// activate item
	$(".items img").removeClass("active");
	$(this).addClass("active");
	
	var fotoDesc = $(this).attr('alt');
	var fotoDescCont = $('<span>'+fotoDesc+'</span>')
	$('.foto-desc').children().remove();
	fotoDescCont.appendTo($('.foto-desc'));

// when page loads simulate a "click" on the first image
}).filter(":first").click();
});

$(document).ready(function() {
	$('.mainnavBlk .navigation').each(function(){
		$(this).children('ul').children().last().remove();
		$(this).children('ul').children().last().addClass('bg-none');
	});
	
	
	
	
	$('.pics-blk .pics-info').appendTo('.prod-desc-btm .pics');
	$('.pics-blk .picsDesk').appendTo('.prod-right-btm .pics');
	
	var maxHeightInfo = 0;
	
	$('.prod-desc-btm .pics .pics-info').each(function(){
		if(maxHeightInfo <= $(this).height()){
			maxHeightInfo = $(this).height();
		}
	});
	
	var maxHeightDesk = 0;
	
	$('.prod-right-btm  .pics .picsDesk').each(function(){
		if(maxHeightDesk <= $(this).height()){
			maxHeightDesk = $(this).height();
		}
	});
	
	$('.prod-desc-btm .scroll').css('height', maxHeightInfo);
	$('.prod-desc-btm .pics').css('height', maxHeightInfo);
	
	$('.prod-right-btm .scroll').css('height', maxHeightDesk+20);
	$('.prod-right-btm .pics').css('height', maxHeightDesk+20);
	
	$(".prod-leftbg-btm .scroll").scrollable().click(function() {
		$(this).data("scrollable").next();	
		$(".prod-desc-btm .scroll").data("scrollable").next();	
		$('.prod-right-btm .scroll').data("scrollable").next();	
	});
	
	$(".prod-desc-btm .scroll").scrollable();
	$('.prod-right-btm .scroll').scrollable();
	
	$('.clickNext').click(function() {
		$(".prod-leftbg-btm .scroll").data("scrollable").next();
		$(".prod-desc-btm .scroll").data("scrollable").next();
		$('.prod-right-btm .scroll').data("scrollable").next();		
		$('.clickPrev').removeClass('active');
		Cufon.replace('.clickPrev', {color: '#666',
			hover: 'true',
			fontFamily : 'Aldo'
	
		});
		$(this).addClass('active');
		$(this).addClass('active');
		Cufon.replace($(this), {color: '#fff',
			hover: 'true',
			fontFamily : 'Aldo'
	
		});		
	});
	$('.clickPrev').click(function() {
		$(".prod-leftbg-btm .scroll").data("scrollable").prev();
		$(".prod-desc-btm .scroll").data("scrollable").prev();
		$('.prod-right-btm .scroll').data("scrollable").prev();
		$('.clickNext').removeClass('active');
		Cufon.replace('.clickNext', {color: '#666',
			hover: 'true',
			fontFamily : 'Aldo'
	
		});
		$(this).addClass('active');
		Cufon.replace($(this), {color: '#fff',
			hover: 'true',
			fontFamily : 'Aldo'
	
		});		
	});
	

	
	$("#commentForm").validate({ 
	        rules: { 
	          name: "required",// simple rule, converted to {required:true} 
	          email: {// compound rule 
	          required: true, 
	          email: true 
	        }, 
	        url: { 
	          url: true 
	        }, 
	        comment: { 
	          required: true 
	        } 
	        }, 
	        messages: { 
	          comment: "Please enter a comment." 
	        }} );	
	
})
