$(function(){
	$(".contact form").validate({
		rules: {
			"e-mail": {
				required: true,
				email: true
			}
		},
		messages: {
			"e-mail": "Please enter a valid email address"
		}
	});	
	
	$("#phone").mask({mask: "(###) ###-####"});

	
	setTimeout(function(){
		$(".cat-header").fadeOut(500);
	},8000);
		$(".left-carousel").height($(window).height()-90);
	
	var loadimg = function(){
	var k_h=153;
		$(".pic-viewer img").fadeIn(300);
		$(".loader").fadeOut(50);
		if ($(".pic-viewer img").width()<837) {
		$(".loader").width(837);
		$(".pic-viewer").width(837);
		$(".pic-viewer img").css("left",(837 - $(".pic-viewer img").width())/2);
		}
		$(".pic-gallery").everyTime(1, "1", function(){
			var img = $(".pic-viewer img:not(.old)");
			if ((837 / parseInt(x))*parseInt(y) <= $(window).height()-k_h ) {
				img.width(837);				
				$(".pic-viewer").height($(".pic-viewer img").width()*parseInt(y)/parseInt(x));
				img.height($(".pic-viewer img").width()*parseInt(y)/parseInt(x));
			} else if ((($(window).height()-k_h)/ parseInt(y))*parseInt(x) <=837) {
				img.height($(window).height()-k_h);
				$(".pic-viewer").height($(window).height()-k_h);
			img.width($(".pic-viewer img").height()*parseInt(x)/parseInt(y));
			} 

			img.css("left",(837 - $(".pic-viewer img").width())/2);
			$(".loader").height($(window).height()-k_h+1);
			$(".left-carousel").height($(window).height()-k_h);
		});
		$(".pic-viewer img.old").remove();
	}
	
	$(".pic-viewer img").live('load', loadimg);	

	$(".left-carousel .carousel li a").click(function(){
		var src=$(this).attr("href");
		x = $(this).attr("x");
		y = $(this).attr("y");
		$(".loader").fadeIn(50).css('opacity', 0.75);
		$(".pic-viewer img").addClass('old');
		$('<IMG src="'+src+'" />').prependTo(".pic-viewer").load(loadimg).hide();
		return false;
	});
	
	$(".left-carousel .carousel li a:first").click();	
	// default label on input elements;
	$("input[title][type='text'], input[title][type='password'], textarea[title]").each(function(){
		var text = $(this).attr('title');
		var ele = $(this);
		$(this).focus(function(){
			this.value=(this.value==text) ? '' : this.value;
			this.style.color = '#000';
		})
		.blur(function(){
			if (this.value == '') {
				this.value = text;
				this.style.color = '#ccc';
			}
			else {
				this.style.color = '#000';
			}
		})
		.blur();
	});
	$('form').not('[noprocess]').submit(function(){
		$(this).find("input[title][type='text'], input[title][type='password'], textarea[title]").each(function(){
			this.value=(this.value==$(this).attr('title')) ? '' : this.value;
		});
		return true;
	});
	
	// jCarousel
	if ($(".carousel-block .rcarousel li").length > 5) {
		$(".carousel-block .rcarousel").jCarouselLite({
			circular: false,
			btnPrev: ".carousel-block .prev",
			btnNext: ".carousel-block .next",
			visible: 10,
			speed: 500
		});
	}

	/*if ($(".left-carousel .carousel li").length > 5) {
		$(".left-carousel .carousel").jCarouselLite({
			circular: false,
			btnPrev: ".left-carousel .lprev",
			btnNext: ".left-carousel .lnext",
			visible: 5,
			vertical: true,
			speed: 500
		});				
	}*/


	$(".left-carousel a.lprev").mouseenter(function() {
		$(".left-carousel .carousel").everyTime(1, "lprev", function(){
			$(".left-carousel a.lprev").click();
		});
	}).mouseleave(function() {
		$(".left-carousel .carousel").stopTime("lprev");
	});

	$(".left-carousel a.lnext").mouseenter(function() {
		$(".left-carousel .carousel").everyTime(1, "lnext", function(){
				$(".left-carousel a.lnext").click();
		});
	}).mouseleave(function() {
		$(".left-carousel .carousel").stopTime("lnext");
	});

	$(".carousel-block a.prev").mouseenter(function() {
		$(".carousel-block .rcarousel").everyTime(1, "prev", function(){
				$(".carousel-block a.prev").click();
		});
	}).mouseleave(function() {
		$(".carousel-block .rcarousel").stopTime("prev");
	});

	$(".carousel-block a.next").mouseenter(function() {
		$(".carousel-block .rcarousel").everyTime(1, "next", function(){
				$(".carousel-block a.next").click();
		});
	}).mouseleave(function() {
		$(".carousel-block .rcarousel").stopTime("next");
	});
});

$(function() {
		$( "#date" ).datepicker({ changeYear: true });
	});
