$(function(){
	
	var len = $(".num > li").length;
	var index = 0;
	var adTimer;
	$(".num li").mouseover(function(){
		index = $(".num li").index(this);
		showImg(index);
	}).eq(0).mouseover();

	$("#ads_images").hover(function(){
		clearInterval(adTimer);
	},function(){
		adTimer = setInterval(function(){
			showImg(index);
			index++;
			if(index == len)
			{
				index = 0;
			}
			},3000);
		}).trigger("mouseleave");
	
	$(".product_contactus_page").hide();
	$(".product_recently_page").hide();
	$(".product_matching_page").hide();
	$(".product_morepictures_page").hide();
	
	$("#cart_continue img").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#cart_continue img").click(function(){
		if($("#shipping_method").val() != "" && $("#order_destination").val() != "")
		{
			$("#cart_continue_form").submit();
		}else{
			alert('You must select a country and a shipping method from the pull down menu.');
		}
	});
	
	$("#new_customers,#returning_customers,#livemessage_submit").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#complete_order img").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#popular_searches_list ul li:even").css('font-weight','700');
	$("#popular_searches_list ul li:even").css('font-size','12px');
	$("#popular_searches_list ul li:odd").css('font-weight','normal');
	$("#popular_searches_list ul li:odd").css('font-size','10px');
	
	$("#complete_order img").click(function(){
		if($("#terms_conditions input").attr('checked') == true){
			$("#complete_order_form").submit();
		}else{
			$("#terms_condition_tip").show();
		}
	});
	
	$("#product_relative_pages li").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$(".product_details_nav").click(function(){
		$(".product_details_page").show();
		$(".product_contactus_page").hide();
		$(".product_recently_page").hide();
		$(".product_matching_page").hide();
		$(".product_morepictures_page").hide();
	});
	
	$(".contact_us_nav").click(function(){
		$(".product_contactus_page").show();
		$(".product_details_page").hide();
		$(".product_recently_page").hide();
		$(".product_matching_page").hide();
		$(".product_morepictures_page").hide();
	});
	
	$(".recently_viewed_items_nav").click(function(){
		$(".product_recently_page").show();
		$(".product_details_page").hide();
		$(".product_contactus_page").hide();
		$(".product_matching_page").hide();
		$(".product_morepictures_page").hide();
	});
	
	$(".matching_product_nav").click(function(){
		$(".product_matching_page").show();
		$(".product_details_page").hide();
		$(".product_contactus_page").hide();
		$(".product_recently_page").hide();
		$(".product_morepictures_page").hide();
	});
	
	$(".more_products_nav").click(function(){
		$(".product_morepictures_page").show();
		$(".product_details_page").hide();
		$(".product_contactus_page").hide();
		$(".product_recently_page").hide();
		$(".product_matching_page").hide();
	});
	
	
	$(".payment_method_tip").hide();
	$("#credit_card_tip").hide();

	
	$("#fname").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#fname_tip").html("<font color=red>Your FName must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#fname_tip").html("");
	}
	});

	$("#lname").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#lname_tip").html("<font color=red>Your LName must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#lname_tip").html("");
	}
	});

	$("#email").bind('blur',function(){
	var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
    var email_val = $("#email").val();
	if(!search_str.test(email_val))
	{
		$("#email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
	}else
	{
		$("#email_tip").html("");
	}
	});
	
	
	$("#email1").bind('blur',function(){
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#email1").val();
		if(!search_str.test(email_val))
		{
			$("#email1_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
		}else
		{
			$("#email1_tip").html("");
		}
	});
	
	$("#l_email").bind('blur',function(){
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#l_email").val();
		if(!search_str.test(email_val))
		{
			$("#l_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
		}else
		{
			$("#l_email_tip").html("");
		}
	});
	
	$("#r_email").bind('blur',function(){
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#r_email").val();
		if(!search_str.test(email_val))
		{
			$("#r_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
		}else
		{
			$("#r_email_tip").html("");
		}
	});
	
	$("#password1").bind('blur',function(){
	if($(this).val().length < 5)
	{
		$("#password1_tip").html("<font color=red>Password must contain a minimum of 5 characters.</font>");
	}else if($(this).val().length >= 5)
	{
		$("#password1_tip").html("");
	}
	});
	
	$("#l_password").bind('blur',function(){
	if($(this).val().length < 5)
	{
		$("#l_password_tip").html("<font color=red>Password must contain a minimum of 5 characters.</font>");
	}else if($(this).val().length >= 5)
	{
		$("#l_password_tip").html("");
	}
	});
	
	$("#password").bind('blur',function(){
	if($(this).val().length < 5)
	{
		$("#password_tip").html("<font color=red>Password must contain a minimum of 5 characters.</font>");
	}else if($(this).val().length >= 5)
	{
		$("#password_tip").html("");
	}
	});
	
	$("#confirmpassword").bind('blur',function(){
	if($(this).val() != $("#password").val())
	{
		$("#confirmpassword_tip").html("<font color=red>The Password Confirmation must match your Password.</font>");
	}else if($(this).val().length >= 5)
	{
		$("#confirmpassword_tip").html("");
	}
	});
	
	

	$("#telephone").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#telephone_tip").html("<font color=red>Telephone must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#telephone_tip").html("");
	}
	});

	$("#address").bind('blur',function(){
	if($(this).val().length < 5)
	{
		$("#address_tip").html("<font color=red>You Address must contain a minimum of 5 characters.</font>");
	}else if($(this).val().length >= 5)
	{
		$("#address_tip").html("");
	}
	});

	$("#postcode").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#postcode_tip").html("<font color=red>Postcode must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#postcode_tip").html("");
	}
	});
	
	// contact us
	$("#c_email").bind('blur',function(){
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#c_email").val();
		if(!search_str.test(email_val))
		{
			$("#c_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
		}else
		{
			$("#c_email_tip").html("");
		}
	});
	
	$("#fullname").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#fullname_tip").html("<font color=red>FullName must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#fullname_tip").html("");
	}
	});
	
	$("#subject").bind('blur',function(){
	if($(this).val().length < 2)
	{
		$("#subject_tip").html("<font color=red>Subject must contain a minimum of 2 characters.</font>");
	}else if($(this).val().length >= 2)
	{
		$("#subject_tip").html("");
	}
	});
	
	$("#question").bind('blur',function(){
	if($(this).val().length < 10)
	{
		$("#question_tip").html("<font color=red>Question must contain a minimum of 10 characters.</font>");
	}else if($(this).val().length >= 10)
	{
		$("#question_tip").html("");
	}
	});
	
	$("#contactus_submit").click(function(){
		result = true;
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#c_email").val();
		if(!search_str.test(email_val))
		{
			$("#c_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#c_email_tip").html("");
		}
		
		if($("#fullname").val().length < 2)
		{
			$("#fullname_tip").html("<font color=red>FullName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#fullname_tip").html("");
		}
		
		if($("#subject").val().length < 2)
		{
			$("#subject_tip").html("<font color=red>Subject must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#subject_tip").html("");
		}
		
		if($("#question").val().length < 10)
		{
			$("#question_tip").html("<font color=red>Question must contain a minimum of 10 characters.</font>");
			result = false;
		}else if($(this).val().length >= 10)
		{
			$("#question_tip").html("");
		}
		
		if(result == true)
		{
			$("#contactus_form").submit();
		}
	});
	
	$("#livemessage_submit").click(function(){
		result = true;
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#c_email").val();
		if(!search_str.test(email_val))
		{
			$("#c_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#c_email_tip").html("");
		}
		
		if($("#fullname").val().length < 2)
		{
			$("#fullname_tip").html("<font color=red>FullName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#fullname_tip").html("");
		}
		
		if($("#country").val() == "")
		{
			$("#subject_tip").html("<font color=red>Please Select a Country.</font>");
			result = false;
		}else
		{
			$("#subject_tip").html("");
		}
		
		if($("#question").val().length < 10)
		{
			$("#question_tip").html("<font color=red>Question must contain a minimum of 10 characters.</font>");
			result = false;
		}else if($(this).val().length >= 10)
		{
			$("#question_tip").html("");
		}
		
		if(result == true)
		{
			$("#testimonial_form").submit();
		}
	});
	
	// contact us end

	$("#country").bind('blur',function(){
	if($(this).val() == "")
	{
		$("#country_tip").html("<font color=red>You must select a country from the pull down menu.</font>");
	}else
	{
		$("#country_tip").html("");
	}
	});

	$("#payment_method").click(function(){
		var payment_method = $("#payment_method :selected").val();
		if(payment_method == "Credit Card"){
			$(".payment_method_tip").show();
			$(".input_credit_card_info").show();
			$(".payment_method_tip").html("<font color=red>8% Credit Card Commission is must.</font>");
		}
		else if(payment_method == "Westernunion or Moneygram"){
			$("#credit_card_tip").html("");
			$("#credit_card_tip").hide();
			$(".payment_method_tip").show();
			$(".input_credit_card_info").hide();
			$(".payment_method_tip").html("<font color=red> Westernunion payer can get 5 % discount directly every payment.</font>");
		}else if(payment_method == "Paypal"){
			$("#credit_card_tip").hide();
			$(".payment_method_tip").hide();
		}else if(payment_method == ""){
			$("#credit_card_tip").html("");
			$("#credit_card_tip").hide();
			$(".payment_method_tip").show();
			$(".payment_method_tip").html("<font color=red> You must select a payment method from the pull down menu.</font>");
			$(".input_credit_card_info").hide();
		}
	});

	$("#continue_checkout").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#contactus_submit").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#continue_register").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#login_btn").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#login_btn2").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#retrieve_btn").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#product_contactus").hover(function(){
		$(this).css('cursor','pointer');
	},function(){
		$(this).css('cursor','normal');
	});
	
	$("#product_contactus").click(function(){
		result = true;
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#p_email").val();
		if(!search_str.test(email_val))
		{
			result = false;
		}
		
		if($("#p_fullname").val().length < 2)
		{
			result = false;
		}
		
		if($("#suggestions").val().length < 2)
		{
			result = false;
		}
		
		if(result == true)
		{
			$("#product_contactus_form").submit();
		}
	});
	
	$("#retrieve_btn").click(function(){
		result = true;
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#r_email").val();
		if(!search_str.test(email_val))
		{
			$("#r_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#r_email_tip").html("");
		}
		
		if(result == true)
		{
			$("#retrievepwd_form").submit();
		}
	});
	
	$("#login_btn2").click(function(){
		$("#side_login").submit();
	});
	
	$("#login_btn").click(function(){
		var result = true;
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#l_email").val();
		if(!search_str.test(email_val))
		{
			$("#l_email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#l_email_tip").html("");
		}
		
		if($("#l_password").val().length < 1)
		{
			$("#l_password_tip").html("<font color=red>Please enter your password.</font>");
			result = false;
		}else if($(this).val().length >= 1)
		{
			$("#l_password_tip").html("");
		}
		
		if(result == true)
		{
			$("#login_form").submit();
		}
		
	});
	
	$("#continue_register").click(function(){
		var result = true;
		if($("#fname").val().length < 2)
		{
			$("#fname_tip").html("<font color=red>Your FName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#fname_tip").html("");
		}
		
		if($("#password").val().length < 5)
		{
			$("#password_tip").html("<font color=red>Password must contain a minimum of 5 characters.</font>");
			result = false;
		}else if($(this).val().length >= 5)
		{
			$("#password_tip").html("");
		}
	
		if($("#confirmpassword").val() != $("#password").val())
		{
			$("#confirmpassword_tip").html("<font color=red>The Password Confirmation must match your Password.</font>");
			result = false;
		}else if($("#confirmpassword").val().length < 5){
			$("#confirmpassword_tip").html("<font color=red>Password must contain a minimum of 5 characters.</font>");
			result = false;
		}else if($("#confirmpassword").val().length >= 5)
		{
			$("#confirmpassword_tip").html("");
		}

		if($("#lname").val().length < 2)
		{
			$("#lname_tip").html("<font color=red>Your LName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#lname_tip").html("");
		}

		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#email").val();
		if(!search_str.test(email_val))
		{
			$("#email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#email_tip").html("");
		}


		if($("#telephone").val().length < 2)
		{
			$("#telephone_tip").html("<font color=red>Telephone must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#telephone_tip").html("");
		}


		if($("#address").val().length < 5)
		{
			$("#address_tip").html("<font color=red>You Address must contain a minimum of 5 characters.</font>");
			result = false;
		}else if($(this).val().length >= 5)
		{
			$("#address_tip").html("");
		}

		if($("#postcode").val().length < 2)
		{
			$("#postcode_tip").html("<font color=red>Postcode must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#postcode_tip").html("");
		}

		if($("#country").val() == "")
		{
			$("#country_tip").html("<font color=red>You must select a country from the pull down menu.</font>");
			result = false;
		}else
		{
			$("#country_tip").html("");
		}
		
		if(result == true)
		{
			$("#register_form").submit();
		}
	});

	$("#continue_checkout").click(function(){
		var result = true;
		if($("#fname").val().length < 2)
		{
			$("#fname_tip").html("<font color=red>Your FName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#fname_tip").html("");
		}

		if($("#lname").val().length < 2)
		{
			$("#lname_tip").html("<font color=red>Your LName must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#lname_tip").html("");
		}

		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	    var email_val = $("#email").val();
		if(!search_str.test(email_val))
		{
			$("#email_tip").html("<font color=red>Your E-mail Address is not formatted correctly.</font>");
			result = false;
		}else
		{
			$("#email_tip").html("");
		}


		if($("#telephone").val().length < 2)
		{
			$("#telephone_tip").html("<font color=red>Telephone must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#telephone_tip").html("");
		}


		if($("#address").val().length < 5)
		{
			$("#address_tip").html("<font color=red>You Address must contain a minimum of 5 characters.</font>");
			result = false;
		}else if($(this).val().length >= 5)
		{
			$("#address_tip").html("");
		}

		if($("#postcode").val().length < 2)
		{
			$("#postcode_tip").html("<font color=red>Postcode must contain a minimum of 2 characters.</font>");
			result = false;
		}else if($(this).val().length >= 2)
		{
			$("#postcode_tip").html("");
		}

		if($("#payment_method").val() == "")
		{
			$(".payment_method_tip").show();
			$(".payment_method_tip").html("<font color=red>You must select a payment method from the pull down menu.</font>");
			result = false;
		}else
		{
			$(".payment_method_tip").html("");
		}

		if($("#payment_method :selected").val() == "Credit Card"){
			if($("#cardNO").val() == "" || $("#cvv2").val() == "" || $("#cardExpireMonth").val() == 0 || $("#cardExpireYear").val() == 0 || $("#issuingBank").val() == ""){

				$(".payment_method_tip").show();
				$(".input_credit_card_info").show();
				$(".payment_method_tip").html("<font color=red>8% Credit Card Commission is must.</font>");
				$("#credit_card_tip").show();
				
				$("#credit_card_tip").html("<font color=red>Your credit card information incomplete</font>");
				result = false;
			}else{
				$("#credit_card_tip").html("");
				$("#credit_card_tip").hide();
			}
		}else if($("#payment_method :selected").val() == "Westernunion or Moneygram"){
			$("#credit_card_tip").html("");
			$("#credit_card_tip").hide();
			$(".payment_method_tip").show();
			$(".input_credit_card_info").hide();
			$(".payment_method_tip").html("<font color=red> Westernunion payer can get 5 % discount directly every payment.</font>");
		}else if($("#payment_method :selected").val() == "Paypal"){
			$(".payment_method_tip").hide();
		}else{
			$("#credit_card_tip").html("");
			$("#credit_card_tip").hide();
			$(".payment_method_tip").show();
			$(".payment_method_tip").html("<font color=red> You must select a payment method from the pull down menu.</font>");
		}

		if(result == true)
		{
			$("#shipping_address_form").submit();
		}
	});
})

function showImg(index){
	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    if (Sys.ie != "8.0"){
    	$(".slider").stop(true,false).animate({top : -236*index},1000);
    }
    else{
    	$(".slider").stop(true,false).animate({top : -232*index},1000);
    }
	$(".num li").css('background','#A1C2D1');
	$(".num li").eq(index).css('background','#FF0000');
}
