$(document).ready(function() {
	$('a.lightbox').lightBox();
	$('.sub').hide();
	$('.product-detail .detail-copy').hide();
	$('.product-detail .detail-copy:first').show();
	
	$("#navigation a").not(".sub a").mouseover(function() {
		$(this).animate({
		marginLeft: "0",
		width: "108px"
		}, 80);
	});
	$("#navigation a").not(".sub a").mouseout(function() {
		$(this).animate({
		marginLeft: "8px",
		width: "100px"
		}, 200);
	});
	
	$("#side-bar-main ul a").click(function() {
		if ($(this).next(".sub").is(":hidden"))
			{
				$(".sub").slideUp(400);
				$(this).next(".sub").slideDown(400);
			}
		else
			{
				$(this).next(".sub").slideUp(400);
			}
	});
	
	//sliding menus product detail page
	$(".product-detail h2 a").click(function() {
		if ($(this).parent().next('.detail-copy').is(":hidden"))
			{
				$(".detail-copy").hide();
				$(this).parent().next(".detail-copy").fadeIn(2000);
				$("h2 a").removeClass('active');
				$(this).addClass('active');
				$(this).blur();
				return false;
			}
		else
			{
				$(this).parent().next(".detail-copy").hide();
				$(this).removeClass('active');
				return false;
			}
	});
	
	//swap image product
	$(".product-detail-images-list a").click(function() {
		var swap = $(this).attr('href');
		$('.details-right img').stop(true, true).fadeOut(500);
		$('.details-right img').attr('src', swap);
		$('.details-right img').stop(true, true).show();
		$(this).blur();
		return false;
	});
	
	//form input handeling hidden labled	
	$("input[type='text']").focus(function() {
		if ($(this).attr("value") == $(this).attr("rel")){
			$(this).attr("value", "");
		}
	});
	
	$("input[type='text']").blur(function() {
		if ($(this).attr("value") == "")
			{
				var val = $(this).attr("rel");
				$(this).attr("value", val);
			}
	});
	
	$("input[type='text']").load(function() {
		if ($(this).attr("value") == "")
			{
				var val = $(this).attr("rel");
				$(this).attr("value", val);
			}
	});
	
	$("textarea").focus(function() {
		$(this).text("");
	});
	
	//password field handeling hidden lables
	$(".password input[type='password']").hide();
	$(".password input[type='text']").show();
	
	$(".password input[type='text']").focus(function(){
		$(this).hide();
		$(this).next("input[type='password']").show().focus();
	});
	
	$(".password input[type='password']").blur(function(){
		if ($(this).attr("value") == "")
			{
				$(this).hide();
				var pass = $(this).prev("input[type='text']").show();
				var value = pass.attr("rel");
				pass.attr("value", value)
			}
	});
	
	//basket promo code
	$(".promo-cont").show();
	$(".show-promo").click(function() {
		$(".promo-cont").hide();
		$(".hidden").fadeIn(500);
	});
	
	//different delivery address
	$(".delivery-address").hide();
	if ($("input[name='defineDelivery']:checked").attr('value') == 1) {
		$(".delivery-address").show();
	}
	$("#delivery-address").click(function() {
		var country = $(".register select[name='country']").attr("value");
		if (country == 'UK')
			{
				$(".delivery-address").toggle();
			}
		else
			{
				alert("Unfortunatly we can only ship to the cardholders address for the specified country");
				return false;
			}
	});
	
	//handle error tooltips
	$(".error").tooltip({showURL: false});
	
	//auto submit
	$(".change2").change(function() {
		this.form.submit();
	});
	
	$(".change").click(function() {
		this.form.submit();
	});
});
