$(document).ready(function(){

    $(".ProductAttributesFriend").change(displayVals);
	if($(document).find(".ProductAttributesFriend"))
		displayVals();
	
	$(".thumbs").hide();
	$(".play").remove();
	$(".prev").html('<img src="images/up.png" alt="Previous Photo"/>');
	$(".next").html('<img src="images/down.png" alt="Next Photo"/>');
	var bodyHeight = $(document).height();
	bodyHeight = bodyHeight-29-195-141;
	$(".mainContent").css('min-height', bodyHeight);
	$(".ProductOtherTop, .prev").hover(
		function(){
			$(this).find('img').attr('src', 'images/up_active.png');
		},
		function(){
			$(this).find('img').attr('src', 'images/up.png');
		}
	);
	$(".backBtn").hover(
		function(){
			$(this).attr('src', 'images/back_active.png');
		},
		function(){
			$(this).attr('src', 'images/back.png');
		}
	);
	$(".backToShopBtn").hover(
		function(){
			$(this).attr('src', 'images/back_to_shop_active.png');
		},
		function(){
			$(this).attr('src', 'images/back_to_shop.png');
		}
	);
	$(".checkoutBtn").hover(
		function(){
			$(this).attr('src', 'images/checkout_active.png');
		},
		function(){
			$(this).attr('src', 'images/checkout.png');
		}
	);
	$(".checkoutBtn").click(function(){
		var country = $(".countryDD").val();
		if(country == "-1"){
			alert("Please choose a country");
			return false;
		}
		return true;
	});
	$(".addToCart").hover(
		function(){
			$(this).attr('src', 'images/add_to_cart_active.png');
		},
		function(){
			$(this).attr('src', 'images/add_to_cart.png');
		}
	);
	$(".deleteBtn").hover(
		function(){
			$(this).attr('src', 'images/delete_active.png');
		},
		function(){
			$(this).attr('src', 'images/delete.png');
		}
	);
	$(".buyBtn").hover(
		function(){
			$(this).attr('src', 'images/buy_active.png');
		},
		function(){
			$(this).attr('src', 'images/buy.png');
		}
	);
	$(".donateBtn").hover(
		function(){
			$(this).attr('src', 'images/donate_active.png');
		},
		function(){
			$(this).attr('src', 'images/donate.png');
		}
	);
	$(".downloadBtn").hover(
		function(){
			$(this).attr('src', 'images/download_active.png');
		},
		function(){
			$(this).attr('src', 'images/download.png');
		}
	);
	$(".ProductOtherBottom, .next").hover(
		function(){
			$(this).find('img').attr('src', 'images/down_active.png');
		},
		function(){
			$(this).find('img').attr('src', 'images/down.png');
		}
	);
	$(".fbsubmit").attr('value', '');
	$(".ProductDescription a").each(function(){
		var url = $(this).attr('href');
		var img = url.slice(-3).toLowerCase().toString();
		if(img == 'jpg') $(this).addClass("popUpImage");
	});
	$('a.popUpImage').zoomimage({
		border: 10,
		centered: true,
		hideSource: false
	});

	$(".emailinput label").hide();
	$("#md4e46email").focus(function(){
		if($(this).attr('value')=='Enter your e-mail') {$(this).attr('value','')};
	});
	$(".emailinput form").submit(function() {
		checkEmail();
		return false;
	});


	$(".menu2 ul li").quickpaginate({ perpage: 6, showcounter: true, pager : $(".menu2Pager") });
	$(".menu3 ul li").quickpaginate({ perpage: 6, showcounter: true, pager : $(".menu3Pager") });
	
});

function checkEmail(){
	var error = true;
	var email = $("#md4e46email");
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(email.val()=='Enter your e-mail' || email.val()=='' || !emailReg.test(email.val())){
		email.css('background-color', '#00e5e2');
		error = true;
	}
	else{
		email.css('background-color', '#fff');
		error = false;
	}
	if(!error) {
		$(".emailinput form").submit();
	}
}

function repl(img, title){
	$(".ProductImageMain").attr("src", img);
}


$(function(){
var listSize = $(".ProductOtherList ul li").size();
if(listSize <= 2) $(".relatedProducts").hide();
$('.ProductOtherTop').click(function() {
	$('.ProductOtherList').animate({scrollTop:'-=94'}, 500);
});
$('.ProductOtherBottom').click(function() {
		$('.ProductOtherList').animate({scrollTop:'+=94'}, 500);
});

	$(".info_names li a").click(function(e){
	var infoID = $(this).parent().attr("id");
		$(".info_names li").each(function(){
			if($(this).attr("id") == infoID) {
				if($(this).hasClass("currentpage"))
					$(this).removeClass("currentpage");
				else
					$(this).addClass("currentpage");
			} else {
				$(this).removeClass("currentpage");
			}
		});
		

		$(".infos").slideUp("slow");
		if(!$("."+infoID).is(":visible")) {
			$("."+infoID).slideDown("slow");
		}
	});
});
      
function selectChange(sel){
	var cartLink = $('.ProductAdd a');
	cartLink.attr('href', 'index.php?mact=CartMadeSimple,cntnt01,cart,0&cntnt01name=&cntnt01perfaction=add_product&cntnt01product_id='+sel.options[sel.selectedIndex].value.split("|")[0]+'&cntnt01qty=1&cntnt01attr='+sel.options[sel.selectedIndex].value.split("|")[1]+'&cntnt01returnmod=Shop&cntnt01returnid=30');
}      
function displayVals() {
      var value = $(".ProductAttributesFriend").val();
      $("#os0").val(value);
    }
