$(document).ready(function() {

	$("#menu1 li a img").mouseover(function() {
		$("#slogan").attr("src", 'themes/parishouse/images/'+ $(this).attr('class') +"roll.gif");
	});

	$("#menu1 li a img").mouseout(function() {
		$("#slogan").attr("src", $("#slogan").attr('class'));
	});
	
	$(".mycarousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 5
		//auto: 5000,
		//speed: 2000,
		
    });

	$("#treeview").treeview({
		collapsed: true
	});
	
	$("#Form_NewsletterForm").validate({
		rules: {
			FirstName: "required",
			Email: {
				required: true,
				email: true
			}
		},
		messages: {
			FirstName: "I would really love to know your name.",
			Email: "It is quite important that you give me your actual email address so I can send you newsletters."
		}
	});
	
	function pulsate() {
		$(".pulsate").animate({opacity: 0.0}, 1000, 'linear').animate({opacity: 1}, 1000, 'linear', pulsate);
	}
	pulsate();
	
	$('.pulsate').mouseenter(function(){
		$(this).animate({opacity: 1}, 1000, 'linear').stop();
	});
	
	$('.pulsate').mouseout(function(){
		$(".pulsate").animate({opacity: 0.0}, 1000, 'linear').animate({opacity: 1}, 1000, 'linear', pulsate);
	});
	
    //clearField("#Form_NewsletterForm");
	//function clearField(form) {
	$('#Form_NewsletterForm').find("input.text, textarea").each(function(){  
		this.defaultValue = this.value;
		$(this).click(function(){
			if(this.value == this.defaultValue){
				$(this).val("");
			}
			return false;
		});
		$(this).blur(function(){
			if(this.value == ""){
				$(this).val(this.defaultValue);
			}
		});
	});
	
	$('li.productimages').each(function(){
		$(this).qtip({
			content: $(this).children('div.productmeta'),
			position: {
				//target: $('div#productmeta'),
				my: 'top center',
				at: 'bottom center'
			},
			style: {
				classes: 'ui-tooltip-jtools'
			}
			
		});
	});
	$('li#productimages').remove('#productmeta');
	
	$('li.rand').each(function(){
		$(this).qtip({
			content: $(this).children('div.productmeta'),
			position: {
				//target: $('div#productmeta'),
				my: 'top center',
				at: 'bottom center'
			},
			style: {
				classes: 'ui-tooltip-jtools'
			}
			
		});
	});
	$('li.rand').remove('#productmeta');
	
	$('#price').change(function() {
        $(this).prev("span").html($(this).val());
    });
	
	$('ul#colors > li:last-child').css('margin-right','0px');
	
	// Image swap on hover
	$('ul#colors li img').hover(function(){
		$('.main-img').attr('src',$(this).attr('src').replace('_resampled/croppedimage100100-',''));
		$('.overlay').attr('src',$(this).attr('src').replace('_resampled/croppedimage100100-',''));
	});
	$('#additionalimages img').hover(function(){
		$('.main-img').attr('src',$(this).attr('src').replace('_resampled/croppedimage5050-',''));
		$('.overlay').attr('src',$(this).attr('src').replace('_resampled/croppedimage5050-',''));
	});
	var imgSwap = [];
	$('ul#colors li img').each(function(){
		imgUrl = this.src.replace('_resampled/croppedimage100100-','$Title/');
		imgSwap.push(imgUrl);
	});
	$('#additionalimages img').each(function(){
		imgUrl = this.src.replace('_resampled/croppedimage5050-','$Title/');
		imgSwap.push(imgUrl);
	});
	$(imgSwap).preload();
	
	
	//$("a[rel=image_overlay]").fancybox({
	//	'transitionIn'		: 'none',
	//	'transitionOut'		: 'none',
	//	'titlePosition' 	: 'none',
	//	'autoScale' : true 
	//});
	
	$(".simpleCart_items").hide();
	$("#cart").hover(
		function() { $(this).children(".simpleCart_items").show(); },
		function() { $(this).children(".simpleCart_items").hide(); },
		function() { $("#checkout").hide(); }
	);
});

$.fn.preload = function(){
	this.each(function(){
		$('<img/>')[0].src = this;
	});
}


