$(document).ready( function() {

	var gup = function( name, url ) {
		var results = (new RegExp("[\\?&]"+name+"=([^&#]*)")).exec(url);
		if ( results == null ) {return ""}
		else {return results[1]}
	};

	var getlangcode = function() {
		var url = window.location.href;
		url = url.replace("http://", "");
		url = url.replace("https://", "");
		var arr = url.split( "/");		 
		return arr[1];
	}

	if( $("div.footer-social-media").length > 0 ) {
		$(".footer-social-media-panel").hide();
		var offset = $("div.footer-social-media").offset();
		var height = $(".footer-social-media-panel").height();
		var width = $(".footer-social-media-panel").width();

		$("div.footer-social-media-panel").css('left', (offset.left - (width/2) ) + "px");
		$("div.footer-social-media-panel").css('top', (0 - height ) + "px");
				
		$("div.footer-social-media").hover( function() {
			if( $("div.footer-social-media-panel").css("display") == "none") 
				$("div.footer-social-media-panel").fadeIn(500);	
		}, 
		function() {
			$("div.footer-social-media-panel").fadeOut(500);
		});
	}

	if( $("a#productsearchbutton").length > 0 ){ 
 
		$("a#productsearchbutton").click( function() {
			 
			var def = $("form#productsearchform #s").attr("title");
			var val = $("form#productsearchform #s").val();
			if( def == val ) {
				$("#popup-search-empty").trigger( 'click' );
			} else {
				$("form#productsearchform").submit();
			}
			delete def, val;
			return false;
		});
	}
	
	if( $("#change-country").length > 0 ) {
		
		//$("#change-country-dollar").html(that.val() +" dollars");
		//$("#change-country-site").html(that.attr("rel") +"US web site");			
		$("#change-country").change( function() {
			var val = $(this).val();
			var that = $("#"+val);
			
			if( val != "" ) { 
				$("#change-country-dollar").html( that.attr("rel") + " ");
				//$("#change-country-site").html( that.val() + " web site");
				$("#change-country-site2").html( that.val() + " web site");
			}
			delete val, that;
		});
	}

	if( $("input#btn-confirm-change").length > 0 ) {
		$("input#btn-confirm-change").click( function() {
			if( $("#change-country").val() == 0 ){
				return false;
			} 
		});
	}

	if( $("a.change-language").length > 0 ) {
		$("a.change-language").click( function() {
			var name = $(this).attr("rel");
 			$("form#headerformLang #language").val( name );
			$("form#headerformLang").submit();
			delete name;
			return false;
		});
	} 
	

	if( $(".popupCountry").length > 0) { 
		$(".popupCountry").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 420,
			'height'			: 170,
			'padding'			: 1,
			'type'				: 'iframe'
		}).trigger('click');
	}
	
	/** header **/
	if( $("#country").length > 0 ) {
		$(".country-panel").hide();
 
		$("#country").hover( function() {
			if( $(".country-panel").css("display") == "none" ) {
				$("a.country-link").parent().children(".country-panel").slideDown(1000, function() {
					$("#country").addClass("country-panel-active");
				});
			}
		}, function() {
			$("a.country-link").parent().children(".country-panel").slideUp(1000, function() {			
				$("#country").removeClass("country-panel-active");	
			});
		});		
	}

	if( $("#social-media").length > 0 ) {
		
		$(".social-media-panel").hide();
	
		
		
		$("#social-media").hover( function() {
			if( $(".social-media-panel").css("display") == "none" ) {
				$(".social-media-panel").slideDown(1000, function() {
					$("#social-media").css("z-index", 999);
					$("#social-media").addClass("social-media-panel-active");
				});
			}
		}, function() {
			$(".social-media-panel").slideUp(1000, function() {
				$("#social-media").removeClass("social-media-panel-active");	
			});
		});	
			
			
				   
		
		
		
	}

	if( $("#my-shopping-session").length > 0 ) {
		$("#my-shopping-session").hover( function() {

			if( $(".my-shopping-session-panel").css("display") == "none" ) { 
				$("a.my-shopping-session-link").parent().children(".my-shopping-session-panel").slideDown(1000, function() {
					$("#my-shopping-session").css("z-index", 999);
					$("#my-shopping-session").addClass("session-panel-active");
				});
			} 
		}, function() {		 
				$("a.my-shopping-session-link").parent().children(".my-shopping-session-panel").slideUp(1000, function() {			
				$("#my-shopping-session").removeClass("session-panel-active");	
			});
		})
	}

	var initShopBagMenu = function() {
		var sb_obj = $(".shopping-bag");
		var scb_obj = $(".shoppingCartBox");
 			
		if( sb_obj.length > 0 ) { 
			sb_obj.hover( function() {					
					if( scb_obj.css("display") == "none" ) { 
						sb_obj.children(".shoppingCartBox").slideDown(1000, function() {
							sb_obj.addClass("shopping-bag-active");
						});
					}
			}, function() {
				sb_obj.children(".shoppingCartBox").slideUp(1000, function() {			
					sb_obj.removeClass("shopping-bag-active");	
				});
			});
		} 

		delete sb_obj, scb_obj;
	}

	var reloadTopShoppingbag = function () {
		var url = $("#topshoppingbags").attr( "rel" );
		
		var extra;
		extra = '';

		if( $(".changeshippingcountry").length > 0 ) {
			extra = "&country=" + $(".changeshippingcountry").val() + "&temp=1";	
		}

		var timestamp = Number(new Date());
		if( document.location.protocol == "https:" ) {
			url = "https://" + document.location.host + url;
		} else {
			url = "http://" + document.location.host + url;
		}
		
		var jqXHR = $.ajax({
			url: url + "?t="+timestamp+extra,
			crossDomain: false,
			success: function( data ) {
				$("#topshoppingbags").html( data );
				initShopBagMenu();
			},
			error: function(jqXHR2, textStatus, errorThrown) {
			}
		});
		delete url;
	};
	
	var reloadPersonalDataSubmenu = function() {		
 		if( $(".catmenu-personal-data").length > 0 ) {
			 
			var url = $("#topshoppingbags").attr( "rel" );
			$(".catmenu-personal-data").load(url + "?right=3", function() {
 			});
			delete url;	
		}
	}

	var reloadMyShoppingSession = function() {
		
		reloadPersonalDataSubmenu();

		var url = $("#topshoppingbags").attr( "rel" );
		$("#my-shopping-session").load(url + "?right=2", function() {
			//initShopBagMenu();
		});
		delete url;	
	};

	if( $("#topshoppingbags").length > 0 ) {
		reloadTopShoppingbag();
		/*
		var url = $("#topshoppingbags").attr( "rel" );
		$("#topshoppingbags").load(url, function() {
			initShopBagMenu();
		});
		delete url;
		*/
	}


	/** END - header **/
	
	if( $(".featured-product").length > 0 ) {
		$(".featured-product").each( function() {
			$(this).hover( function() {
				$(this).addClass("border");
				
				if( $(this).children("span").css("position") != "relative") {
					var h = $(this).children("span").height();				
					$(this).children("span").css("position", "relative");
					$(this).children("span").css("top", (0-h-2) + "px");
					delete h;
				}
				
				$(this).children("span").fadeIn(1000);
				var rel = $(this).attr("rel");
				$("#"+rel).fadeIn(1000); 
				delete rel;
			}, function() {			
				$(this).removeClass("border");
				$(this).children("span").fadeOut(1000);
				var rel = $(this).attr("rel");
				$("#"+rel).fadeOut(500);
				delete rel;
			});
			
			//$(this).click( function() { });
		});
	}

	if( $(".product-feature-popup").length > 0 ) {
		$(".product-feature-popup").fancybox({
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding'			: 0,
			'width'				: 890,
			'height'			: 661,
			'type'              : 'iframe'
		});
	}
	
	if( $(".shopping-bag").length > 0 ) {
		$(".shopping-bag").hover( function() {
				$(".shopping-bag").children(".shoppingCartBox").slideDown(1000, function() {
				$(".shopping-bag").addClass("shopping-bag-active");
			});
		}, function() {
				$(".shopping-bag").children(".shoppingCartBox").slideUp(1000, function() {			
				$(".shopping-bag").removeClass("shopping-bag-active");	
			});
		});
	}
	
	if( $(".wishThb a.quickColor").length > 0 ) {
		$(".wishThb").each( function( index, ele ) {
			$(this).hover (
				function() {
					var src = $(this).children("a").children("img").attr("rel");
					var mask = $(this).children("a").children("img").attr("src");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", mask);
					$(child).attr("src", src);
					$("a.quickColor:eq("+index+")").removeClass( "inactive" );
					$("a.quickColor:eq("+index+")").addClass( "active" );
				},
				function() {
					var src = $(this).children("a").children("img").attr("src");
					var mask = $(this).children("a").children("img").attr("rel");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", src);
					$(child).attr("src", mask);
					$("a.quickColor:eq("+index+")").removeClass( "active" );
					$("a.quickColor:eq("+index+")").addClass( "inactive" );
				}
			);
		});
	}
	
	if( $(".prodThb a.quickColor").length > 0 ) {
		$(".prodThb").each( function( index, ele ) {
			$(this).hover (
				function() {
					var src = $(this).children("a").children("img").attr("rel");
					var mask = $(this).children("a").children("img").attr("src");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", mask);
					$(child).attr("src", src);
					$("a.quickColor:eq("+index+")").removeClass( "inactive" );
					$("a.quickColor:eq("+index+")").addClass( "active" );
				},
				function() {
					var src = $(this).children("a").children("img").attr("src");
					var mask = $(this).children("a").children("img").attr("rel");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", src);
					$(child).attr("src", mask);
					$("a.quickColor:eq("+index+")").removeClass( "active" );
					$("a.quickColor:eq("+index+")").addClass( "inactive" );
				}
			);
		});
	}
	

	
	if( $("a[rel=photo_gallery]").length > 0 ) { 
		$("a[rel=photo_gallery]").fancybox({ 
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: '100%',
			'height' 			: '100%', 
			'padding'			: 0,
			'type'				: 'image',
			'changeFade' 		: 0
		});
	}
	
	if( $("a.popup-iframe-1024").length > 0 ) { 
		$("a.popup-iframe-1024").fancybox({ 
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: '100%',
			'height' 			: '100%', 
			'padding'			: 0,
			'type'				: 'image',
			'changeFade' 		: 0
		});
	}
	
	
	if( $("a.popup").length > 0 ) { 
		$("a.popup").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'image',
			'padding'			: 0
		});
	}

	if( $("a.popup-image").length > 0 ) { 
		$("a.popup-image").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'image',
			'padding'			: 0
		});
	}
	
	
	if( $("a.popup-iframe-tell-friend").length > 0 ) { 
		$("a.popup-iframe-tell-friend").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'width'				: 620,
			'height'			: 460,
			'padding'			: 0
		});
	}
	 
	if( $("a.popup-iframe").length > 0 ) { 
		$("a.popup-iframe").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'padding'			: 0
		});
	}
	
	if( $("a.popup-inline").length > 0 ) {
		$("a.popup-inline").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'inline',
			'centerOnScroll'	: true,							
			'padding'			: 0
		});
	}

	if( $("a.popup-iframe-480-600").length > 0 ) {
		$("a.popup-iframe-480-600").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: 520,
			'height' 			: 400, 
			'type'				: 'iframe',
			'padding'			: 0		
		});
	}

	if( $("a.popup-iframe-full-window").length > 0 ) { 
		$("a.popup-iframe-full-window").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: '100%',
			'height' 			: '100%', 
			'type'				: 'iframe',
			'padding'			: 0
		});
	}
	
	if( $("a.popup-iframe-full").length > 0 ) { 
		$("a.popup-iframe-full").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: '90%',
			'height' 			: '90%', 
			'type'				: 'iframe',
			'padding'			: 0
		});
	}
	
	if( $(".wishThb a.quickColor").length > 0 ) {
		$(".wishThb").each( function( index, ele ) {
			$(this).hover (
				function() {
					var src = $(this).children("a").children("img").attr("rel");
					var mask = $(this).children("a").children("img").attr("src");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", mask);
					$(child).attr("src", src);
					$("a.quickColor:eq("+index+")").removeClass( "inactive" );
					$("a.quickColor:eq("+index+")").addClass( "active" );
				},
				function() {
					var src = $(this).children("a").children("img").attr("src");
					var mask = $(this).children("a").children("img").attr("rel");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", src);
					$(child).attr("src", mask);
					$("a.quickColor:eq("+index+")").removeClass( "active" );
					$("a.quickColor:eq("+index+")").addClass( "inactive" );
				}
			);
		});
	}
	
	if( $(".prodThb a.quickColor").length > 0 ) {
		$(".prodThb").each( function( index, ele ) {
			$(this).hover (
				function() {
					var src = $(this).children("a").children("img").attr("rel");
					var mask = $(this).children("a").children("img").attr("src");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", mask);
					$(child).attr("src", src);
					$("a.quickColor:eq("+index+")").removeClass( "inactive" );
					$("a.quickColor:eq("+index+")").addClass( "active" );
				},
				function() {
					var src = $(this).children("a").children("img").attr("src");
					var mask = $(this).children("a").children("img").attr("rel");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", src);
					$(child).attr("src", mask);
					$("a.quickColor:eq("+index+")").removeClass( "active" );
					$("a.quickColor:eq("+index+")").addClass( "inactive" );
				}
			);
		});
	}
	
	if ($(".trunk-show-lightbox").length > 0) {
		$(".trunk-show-lightbox").fancybox({
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 780,
			'height'			: 661,
			'padding'			: 1,
			'type'              : 'iframe'
		});
	}
	
	if ($(".quickColor").length > 0) {
		$(".quickColor").fancybox({
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 890,
			'height'			: 661,
			'padding'			: 0,
			'type'              : 'iframe', 
			'onStart'			: function() { },
			'onClosed'			: function() {
 				initShopBagMenu();
				
				$(".popup-msg").fancybox({
					'width'				: 480,
					'height'			: 80,
					'padding'			: 0,
					'autoScale'     	: false,
					'autoDimensions'	: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'inline',
					'scrolling'			: 'no',
					'onComplete'		: function() {
						if( $(this).attr("href") == "#search-no-result-block" ) {
							$("#fancybox-content").height(111);
							$("#fancybox-content").css("overflow", "hidden");
							$("#fancybox-content div").css("overflow", "hidden");
						} else if( $(this).attr("href") == "#viewed-block" ) {
							$("#fancybox-content").height(90);
						} else if( $(this).attr("href") == "#love-block" ) {
							$("#fancybox-content").height(120);
						}
					}
				});

			}
		}); 
	}
	 

	/*
	if ($(".quickColor").length > 0) {
		$(".quickColor").fancybox({
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 890,
			'height'			: 661,
			'padding'			: 0,
			'type'              : 'iframe',
			'onStart'			: function() {
				alert("start");
			},
			'onClosed'			: function() {
				alert("CLOSED!!");
				initShopBagMenu();
			}
		});
	}
	*/
	// this function should be rewrite!!! just demo use only!!!
	var collapse = function( selector, active ) {
		if( $(selector).length > 0 ) {
			$(selector).each( function(index, ele) {
				$(this).click( function() {
					if( $(this).parent().hasClass("active") ) {
						$(this).parent().removeClass("active");
					} else {
						$(active).removeClass("active");
						$(this).parent().addClass("active");
					}
				});
			}); 
		}
	}
	
	collapse( ".contactListBar li h2", ".contactListBar li.active" );
	collapse( ".contentListBar li h2", ".contentListBar li.active" );
	
	delete collapse;
	
	/** product details **/
	if ($("a[rel=lightbox_gallery]").length > 0) {
		$("a[rel=lightbox_gallery]").fancybox({
			//'width'				: 480,
			//'height'			: 640,
			'width'				: 841,
			'height'			: 640,
			'padding'			: 0,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'onStart'			: function() {									
									$("#fancybox-wrap").addClass("fixproductpopup"); 
								},
			'onClosed'			: function() {
									$("#fancybox-wrap").removeClass("fixproductpopup"); 
								},
			'type'				: 'iframe'
		}); 
	}

	if( $(".prodThb").length > 0 ) {
		$(".prodThb").each( function( index, ele ) {
			$(this).hover (
				function() {
					var src = $(this).children("a").children("img").attr("rel");
					var mask = $(this).children("a").children("img").attr("src");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", mask);
					$(child).attr("src", src);
					$("a.quickView:eq("+index+")").removeClass( "inactive" );
					$("a.quickView:eq("+index+")").addClass( "active" );
					
				},
				function() {
					var src = $(this).children("a").children("img").attr("src");
					var mask = $(this).children("a").children("img").attr("rel");
					var child = $(this).children("a").children("img");
					$(child).attr("rel", src);
					$(child).attr("src", mask);
					$("a.quickView:eq("+index+")").removeClass( "active" );
					$("a.quickView:eq("+index+")").addClass( "inactive" );
				}
			);
		});
	}
 
	//$(".quickView").click(function() { 
		//$('#fancybox-outer').append("<a id='fancybox-like' class='btn1'>"+$(this).parent().attr("rel")+"</a>");		
	//});
	$(".popup-msg").fancybox({
		'width'				: 480,
		'height'			: 80,
		'padding'			: 0,
		'autoScale'     	: false,
		'autoDimensions'	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'inline',
		'scrolling'			: 'no',
		'onComplete'		: function() {
				if( $(this).attr("href") == "#search-no-result-block" ) {
					$("#fancybox-content").height(111);
					$("#fancybox-content").css("overflow", "hidden");
					$("#fancybox-content div").css("overflow", "hidden");
				} else if( $(this).attr("href") == "#viewed-block" ) {
					$("#fancybox-content").height(90);
				} else if( $(this).attr("href") == "#love-block" ) {
					$("#fancybox-content").height(120);
				}
			}
		});	

	$(".popup-iframe-footer").fancybox({
			'width'				: 480,
			'height'			: 175,
			'padding'			: 0,
			'autoScale'     	: false,
			'autoDimensions'	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	
	/*
	$(".popup-search-empty").fancybox({
			'width'				: 480,
			'height'			: 125,
			'padding'			: 1,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'inline'
	});

	$(".popup-search-noresult").fancybox({
			'width'				: 480,
			'height'			: 300,
			'padding'			: 1,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'inline'
	});
	*/

	$("a#addtocarterror").fancybox({
			'width'				: 480,
			'height'			: 80,
			'padding'			: 0,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});

	$(".quickView").fancybox({
			'width'				: 480,
			'height'			: 640,
			'padding'			: 0,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'onClosed'			: function() {
				$(".popup-msg").fancybox({
					'width'				: 480,
					'height'			: 80,
					'padding'			: 0,
					'autoScale'     	: false,
					'autoDimensions'	: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'inline',
					'scrolling'			: 'no',
					'onComplete'		: function() {
							if( $(this).attr("href") == "#search-no-result-block" ) {
								$("#fancybox-content").height(111);
								$("#fancybox-content").css("overflow", "hidden");
								$("#fancybox-content div").css("overflow", "hidden");
							} else if( $(this).attr("href") == "#viewed-block" ) {
								$("#fancybox-content").height(90);
							} else if( $(this).attr("href") == "#love-block" ) {
								$("#fancybox-content").height(120);
							}
						}
					});
			}

	});
	
 
	
	if( $("a[rel=sizeGuide]").length > 0 )
	{ 
		$("a[rel=sizeGuide]").fancybox({
			'padding'			: 1,
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'image'
		});
	}
	
	if( $(".no-search-result").length > 0 ) {
		$("#popup-search-no-result").trigger( "click" );
	}

 	if( $(".proSizeValue").length > 0 ) { 
		$(".proSizeValue-panel").hide();
		$('.proSizeValue').click(function() {
			$(this).parent().children('div.proSizeValue-panel').toggle('slow', function() {
			});
		});
	}
	if( $(".proItemValue").length > 0 ) { 
		$(".proItemValue-panel").hide();
		$('.proItemValue').click(function() {
			$(this).parent().children('div.proItemValue-panel').toggle('slow', function() {
			});
		});
	}
	
	if( $(".proSizeReduce").length > 0 ) { 
		$('.proSizeReduce').click(function() {
			var itr, total, obj, i;
			itr = 0;
			total = $(this).parent().parent().children(".sizelist").children("div").length;
		 
			$(this).parent().parent().children(".sizelist").children("div").each( function( index, ele ) {	
				if( $(this).hasClass("active") ) {
					$(this).removeClass("active");
					itr = index;
					return false;
				}
			});

			if( itr <= 0)
				itr = (total-1);
			else
				itr--; 

			obj = $(this).parent().parent().children(".sizelist").children("div").eq( itr );

			// update
			obj.addClass("active");
			i = $(this).attr("rel");
			$("input#size"+i).val( obj.attr("rel") );
			$(this).parent().parent().children(".proSizeValue").children("span").text(obj.html());
			
			updatecart(i);

			delete itr, total, obj, i;
		}); 
	}
	
	if( $(".proSizeIncrease").length > 0 ) { 
		$('.proSizeIncrease').click(function() {
			var itr, total, obj, i;
			itr = 0;
			total = $(this).parent().parent().children(".sizelist").children("div").length;
		 
			$(this).parent().parent().children(".sizelist").children("div").each( function( index, ele ) {	
				if( $(this).hasClass("active") ) {
					$(this).removeClass("active");
					itr = index;
					return false;
				}
			});

			if( (itr+1) >= total)
				itr = 0;
			else
				itr++; 

			obj = $(this).parent().parent().children(".sizelist").children("div").eq( itr );

			// update
			obj.addClass("active");
			i = $(this).attr("rel");
			$("input#size"+i).val( obj.attr("rel") );
			$(this).parent().parent().children(".proSizeValue").children("span").text(obj.html());
			
			
			updatecart(i);

			delete itr, total, obj, i;

		});
	}
	
	if( $(".proItemReduce").length > 0 ) { 
		$('.proItemReduce').click(function() {
			var itemNu, i;
			itemNu = $(this).parent().parent().children(".proItemValue").text();
			itemNu = parseInt(itemNu) - 1;
			if (itemNu <= 0)
				return false;
			
			i = $(this).attr("rel"); 
			$("input#qty"+i).val( itemNu );

			if (itemNu == 1)
				itemNu = itemNu +' item';
			else
				itemNu = itemNu +' items';

			$(this).parent().parent().children(".proItemValue").text(itemNu);
			
			updatecart(i);
			
			delete itemNu, i;
		});
	}
	
	if( $(".proItemIncrease").length > 0 ) { 
		$('.proItemIncrease').click(function() {
			var itemNu, i;
			itemNu = $(this).parent().parent().children(".proItemValue").text();
			
			i = $(this).attr("rel");
			$("input#qty"+i).val( parseInt(itemNu) + 1 );

			itemNu = parseInt(itemNu) + 1 +' items';
			
			if (itemNu >= 99)
				return false;
			else
				$(this).parent().parent().children(".proItemValue").text(itemNu);
			
			updatecart(i);
			
			delete itemNu, i;
		});
	}

	if( $("span.plusqty").length > 0 ) {
		$("span.plusqty").click( function() {
			var intqty = 0;
			var qty;
			 
			try {
				qty = parseInt($("input#input-qty").val());
				//alert(qty);
				if( !isNaN(qty) ) {
					intqty = qty; 
				//	alert( qty );
				}
			} catch(err) {
				
			}
			
			intqty++;

			$("input#input-qty").val( intqty );
			
			delete qty, intqty;

		});		
	} 

	if( $("span.minusqty").length > 0 ) {
		$("span.minusqty").click( function() {
			var intqty = 0;
			var qty;
			 
			try {
				qty = parseInt($("input#input-qty").val());
				if( !isNaN(qty) )
					intqty = qty; 
			} catch(err) { }

			intqty--;
			
			if( intqty <= 0 )
				intqty = 1;

			$("input#input-qty").val( intqty );
			
			delete intqty;
		});	
	}
	
	
	if( $("a.deletecartitem").length > 0 ) {
		$("a.deletecartitem").click( function() {	
			var that = $(this);
			var parent = $(this).parent().parent().parent().children("li");
			deletecart( $(this).attr("rel"), function() {
				var row = that.parent().parent().attr("rel");
				// remove item 
				that.parent().parent().remove();

				// check no item
				if( parent.length == 1 ) {
					$(".shoppingBag").eq( row ).remove();
				}
				delete row;
			});
			delete that;
		});
	}
	
	var updateCheckoutRightItem = function() {

		if( $("#checkoutrightItems").length > 0 ) {
			var url = $("#checkoutrightItems").attr("rel");
			var timestamp = Number(new Date());
			if( document.location.protocol == "https:" ) {
				url = "https://" + document.location.host + "/" + url;
			} else {
				url = "http://" + document.location.host + "/" + url;
			}
			
			assignState( $("#txtcountry"), $("input#txtprovince"), "sstate" );
							
			var _country, _state;
			_country = $(".changeshippingcountry").val();
			_state = $("#txtprovince").val();
			
			
			$.post(url, { 'right':'1', 'country' : _country, 'state':_state }, function(data) {
				$("#checkoutrightItems").fadeOut();
				$("#checkoutrightItems").html( data );
				$("#checkoutrightItems").fadeIn(1000);
			});
			delete url, _country, _state;
		}
	}

	var canupdatecart = true;
	var updatecart = function( i ) {
		if( canupdatecart ) { 
			//canupdatecart = false;

			// post to update cart 
			var color, size, qty, subcat, skut, original, url;
			url = $(".shopBar").attr("rel");
			color = $("input#color"+i).val();
			size = $("input#size"+i).val();
			qty = $("input#qty"+i).val();
			subcat = $("input#subcat"+i).val();
			skut = $("input#skut"+i).val();
			original = $("input#original"+i).val();
			$.post(url, { 'mode':'updatecartitem', 'color': color, 'size': size, 'qty':qty, 'subcat':subcat, 'skut':skut, 'original': original }, function(data) {
				//canupdatecart = false;
				
				updateCheckoutRightItem();
				reloadTopShoppingbag();
				// set back the original // $id_subcat, $skut, $color, $size, $iqty
				original = subcat+","+ skut+","+color+","+size+","+qty;
				$("input#original"+i).val(original);
			});
			delete color, size, qty, subcat, skut, url;
		}
	};

	var deletecart = function( i, completefunc ) {
		var color, size, qty, subcat, skut, url;
		url = $(".shopBar").attr("rel");
		color = $("input#color"+i).val();
		size = $("input#size"+i).val();
		qty = $("input#qty"+i).val();
		subcat = $("input#subcat"+i).val();
		skut = $("input#skut"+i).val();
		$.post(url, { 'mode':'deletecartitem', 'color': color, 'size': size, 'qty':qty, 'subcat':subcat, 'skut':skut }, function(data) {
			completefunc();
			updateCheckoutRightItem();
			reloadTopShoppingbag();
		});
		delete color, size, qty, subcat, skut, url;
	};

	if( $(".helpListBar li h2").length > 0 ) {
		$(".helpListBar li h2").each( function(index, ele) {
			$(this).click( function() {
				$(".helpListBar li.active").removeClass("active");
				$(this).parent().addClass("active");
			});
		}); 
	}
	
	if( $("#s2").length > 0 ) {
		$('#s2').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 0, 
			next:   '#fancybox-right', 
			prev:   '#fancybox-left' 
		});
	}

	if( $("a.zoom").length > 0 ) { 
		$("a.zoom").each( function(index, ele) {
			if( $(this).css("display") != "none" )  {
				$(this).jqzoom({
					title: false,
					xOffset:0,
					zoomWidth: 348,
					zoomHeight: 500
				});
				var attr = $(this).attr("rel");
				$('li[rel="'+attr+'"]').hide();
				delete attr;
			}
		});
	}

	/*
	if( $("a.productsizeopt").length > 0 ) {
		alert( $("a.productsizeopt").length );
		$("a.productsizeopt").each( function( index, ele ) {
			$(this).click(function() {
				alert( index );
			});
		});
		
		$("a.productsizeopt").click( function(e) {
			alert("ABCDE");
			//if( !$(this).hasClass("active") ) {
			//	$(this).addClass("active");
			//}
			//return false;
		});	
		
	}
*/
	if( $("a.wishlistdeletebutton").length > 0 ) {
		$("a.wishlistdeletebutton").click( function() {

			var _wid = $(this).attr("rel");
			var that = $(this);
			
			var total = that.parent().parent().parent().children("li").length;
			var catpanel = that.parent().parent().parent().parent("div.wishlistdategroup");
			var item = that.parent().parent();
			
			$.post($(this).attr("href"),  { 'mode':'delete', 'wid': _wid }, function(data) {
				// remaining 
				if( total == 1 ) {
					catpanel.remove();	
				} else {
					item.remove();
				}
			});
			 
			delete _wid, that, total, catpanel, item;

			return false;
		});
	}

	if( $("a.wishAddbutton").length > 0 ) {
		$("a.wishAddbutton").click( function() {
			
			if( !$(this).hasClass("button-added") ) { 
				var param = $(this).attr( "rel" );
				var params = param.split( "," );
				var url, _skut, _color, _subcat;
				var that = $(this);
				url = _skut = _color = _subcat = '';
				_skut = params[0];
				_subcat = params[1];
				_color = params[2];
				url = $(this).attr( "href" );
			
				$.post(url, { 'mode':'add', 'color': _color, 'skut': _skut, 'subcat': _subcat }, function(data) {
					that.addClass("button-added");
					var t = $("#myshoppingsession-wishlist");
					try
					{						
						var i = parseInt(t.html());								
						t.html(++i);
					}
					catch (err)
					{
						alert(err);
					}
					$("#my-shopping-session").trigger( "hover");
					delete t, i;
				});

				delete param, params, url, _skut, _color, _subcat, that;
			}
			
			return false;
		});
	}
	
	var parentShoppingBagSlideDown = function () {
 		var sb_obj = $(".shopping-bag", window.parent.document);
		var timer = null;
		 if ( $.browser.msie ) {
			//alert("IE debug: " );
			//alert(sb_obj.html());
		 }

		//alert( sb_obj.length );
		//sb_obj.children(".shoppingCartBox").show();

		sb_obj.children(".shoppingCartBox").slideDown(500, function() {
			sb_obj.addClass("shopping-bag-active");
			if( timer != null ) {
				clearTimeout(timer);
				timer = null;
			}

			timer = setTimeout( function() { 
					var sb_obj = $(".shopping-bag", window.parent.document);
		
					sb_obj.children(".shoppingCartBox").slideUp(500, function() {			
					sb_obj.removeClass("shopping-bag-active");	
					delete sb_obj;
				});
			}, 500);

		});
		delete sb_obj, timer;
	}

	if( $("a.addtocart").length > 0 ) {
		$("a.addtocart").click( function() {
			var url = $(this).attr("href");
			var hasitem = false;

			var timer = null;
			$("a.productsizeopt").each( function(index, ele) {
				if( $(this).hasClass("active") ) {
					hasitem = true;
					var color = $(this).parent().parent().attr("rel");
					var size = $(this).attr("rel");
					var qty = $("#input-qty").val();
					var subcat = $("#subcat").val();
					var skut = $("#skut").val();
					
					$.post(url, { 'mode':'addtobag', 'color': color, 'size': size, 'qty':qty, 'subcat':subcat, 'skut':skut }, function(data) {						
						var tsb_obj = $("#topshoppingbags");
						var scb_obj = $(".shoppingCartBox");
						var sb_obj = $(".shopping-bag");

						if( $("body.lightbox").length > 0 ) {
							tsb_obj = $("#topshoppingbags", window.parent.document);
							scb_obj = $(".shoppingCartBox", window.parent.document);
							sb_obj = $(".shopping-bag", window.parent.document);
						} 				
												
						var loadurl = tsb_obj.attr( "rel" );
						var timestamp = Number(new Date());
 
						$.get( loadurl + "?t=" + timestamp, function(data) {
							//alert( "IE debug: " + data );
							
							tsb_obj.html( data );

							 if ( $.browser.msie ) {
								//tsb_obj.html( data );
								//alert( data ); 
								//alert("IE debug: sb_obj " );
								//alert( tsb_obj.html());
							 }

							//tsb_obj.load(loadurl, function() {  
  							initShopBagMenu();

							$("#product-detail-checkout-button").show();	
							
 							
							if( $("body.lightbox").length > 0 ) {
								parentShoppingBagSlideDown();
								tsb_obj = $("#topshoppingbags", window.parent.document);
								scb_obj = $(".shoppingCartBox", window.parent.document);
								sb_obj = $(".shopping-bag", window.parent.document);
							} else if( $(".shoppingCartBox").css("display") == "none" ) { 
								$(".shopping-bag").children(".shoppingCartBox").slideDown(1000, function() {
									$(".shopping-bag").addClass("shopping-bag-active");
									if( timer != null ) {
										clearTimeout(timer);
										timer = null;
									}

									timer = setTimeout( function() { 
										$(".shopping-bag").children(".shoppingCartBox").slideUp(1000, function() {			
											$(".shopping-bag").removeClass("shopping-bag-active");	
										});
									}, 1000);

								});
							}
						
						});
						delete loadurl;
						//$('.result').html(data);
					});

					delete color, size, qty, subcat, skut;
				}
			});

			if( !hasitem ) {
				 $("a#addtocarterror").trigger('click');
				//alert('Please choose color and size.');
			}

			delete url, hasitem;
			
			return false;

		});
	}

	if( $("a.colorimg").length > 0 ) {
		$("a.colorimg").click( function(e) {
			// hide current one 
			$("a.zoom").hide();
			
			// show click one
			var attr = $(this).attr("rel");
			$("a#zoomimg"+attr).show();
			
			$("a#zoomimg"+attr).jqzoom({
				title: false,
				xOffset:0,
				zoomWidth: 348,
				zoomHeight: 500
			});
			
			$("a.colorimg").each( function( index, ele ) {
				if( $(this).hasClass("active") ) {
					$(this).removeClass("active");
				} 
			});
			$('a.colorimg[rel="'+attr+'"]').addClass("active");
				
			delete attr;
			return false;
		});	
	}

	if( $("a.productviews").length > 0 ) {
		
		$("a.productviews").click( function(e) {
			// hide current one 
			$("a.zoom").hide();
			
			// show click one
			var attr = $(this).attr("rel");
			$("a#zoomimg"+attr).show();
			
			$("a#zoomimg"+attr).jqzoom({
				title: false,
				xOffset:0,
				zoomWidth: 348,
				zoomHeight: 500
			});
			$("li.productviewitem").each( function( index, ele ) {
				if( $(this).css("display") == "none" ) {
					$(this).show();
				}
			});
			$('li[rel="'+attr+'"]').hide();
				
			delete attr;
			return false;
		});
	}
	
	if( $("a#packagesubmitbutton").length > 0 ) {
		$("a#packagesubmitbutton").click( function() {
			// do validation 

			//jQuery.validator.addMethod("validdate", function(value, element) { 
			//	return Date.parseExact(value, "yyyy-M-d"); 
			//});
			var validation = true;
			if( document.getElementById("giftpack2").checked ) { 
				validation = $("form#packageform").validate({
					rules: { 
						giftsurname: "required",
						//gifttitle: "required",
						giftmsg: "required"
					},
					messages: {
						giftsurname: "",
						//gifttitle: "",
						giftmsg: ""
					} 
				}).form(); 
			} else {
				 
			
				//alert( 'checking:' + $("#giftmsg").val() ); 

				document.getElementById("packageform").submit();
				/*
				$("form#packageform").validate().resetForm();
				validation = $("form#packageform").validate({
					rules: { 
						giftpack: "required" 
					},
					messages: {
						giftpack: "" 
					}
				}).form(); 
				//validation = true;
 				*/
			}
			
			if( validation && ($("input[name='package']:checked").val() != "undefined") && ($("input[name='giftpack']:checked").val() != "undefined")) {
				if( $("#giftmsg").val() == $("#giftmsg").attr("label") )
					$("#giftmsg").val('');
				
				$("#errmsgbox").hide();
				$("form#packageform").submit();
			} else {
				$("#errmsgbox").show();
			}
			return false;
		}); 
	}

	if( $("a#btnBillingButton").length > 0 ) {
		$("a#btnBillingButton").click( function() {
			//alert("ABCDE");
			// do validation 

			//jQuery.validator.addMethod("validdate", function(value, element) { 
			//	return Date.parseExact(value, "yyyy-M-d"); 
			//});
			var validation = $("form#billingform").validate({
				rules: { 
					title: "required",
					firstname: "required",
					surname: "required",
					country: "required",
					city: "required", 
					addr1: "required", 
					zip: "required",
					phoneday: "required"
				},
				messages: {
					title: "",
					firstname: "",
					surname: "",
					country: "",
					city: "",
					addr1: "", 
					zip: "",
					phoneday: ""
				}
			}).form(); 
			
			if( validation ) {
				$("#errmsgbox").hide();
				$("form#billingform").submit();
			} else {
				$("#errmsgbox").show();
			}
			return false;

		});
	}
	
	function assignState( countryid, txtstate, state ) {
		var val = countryid.val();
		var res = '';
		if( $("#"+state+val).length > 0 ) {			
			res = $("#"+state+val).val();
 			//txtstate.show();
			txtstate.val( res );
 		}
		delete val, res;
	}

	
	if( $("a#btnShippingButton").length > 0 ) {
		$("a#btnShippingButton").click( function() {
			// do validation 
			var validation = $("form#shippingform").validate({
				rules: { 
					title: "required",
					firstname: "required",
					surname: "required",
					country: "required",
					city: "required", 
					addr1: "required", 
					//zip: "required",
					phoneday: "required",
					btitle: {required: "#chkdiff:checked"},
					bfirstname: {required: "#chkdiff:checked"},
					bsurname: {required: "#chkdiff:checked"},
					bcountry: {required: "#chkdiff:checked"},
					bcity: {required: "#chkdiff:checked"}, 
					baddr1: {required: "#chkdiff:checked"}, 
					//zip: "required",
					bphoneday: {required: "#chkdiff:checked"}
				},
				messages: {
					title: "",
					firstname: "",
					surname: "",
					country: "",
					city: "",
					addr1: "", 
					//zip: "",
					phoneday: "",
					btitle: "",
					bfirstname: "",
					bsurname: "",
					bcountry: "",
					bcity: "",
					baddr1: "", 
					//zip: "",
					bphoneday: ""
				}
			}).form(); 
			
			var type = '';
			if (jQuery("form#shippingform").attr("id") != undefined) { 
				type = $("form#shippingform").parent().attr("id");
			}
			
			// check ship state
			var sc = $("#txtcountry").val();
			if( $("#sstate"+sc).length > 0 ) {
				var t = ($("#sstate"+sc).val() != '');
				if (!t)
				{
					$("#sstate"+sc).addClass("error");
				} 
				else 
				{
					$("#sstate"+sc).removeClass("error");
				}
				validation = (validation) && t;
			}

			var bc = $("#txtbcountry").val();
			if( $('input#chkdiff').is(':checked') ) 
			{
				var t = ($("#bstate"+bc).val() != '');
				if (!t)
				{
					$("#bstate"+bc).addClass("error");
				} 
				else 
				{
					$("#bstate"+bc).removeClass("error");
				}
				validation = (validation) && t;
			}

			if( validation ) {
				// assign sstate, bstate to province
				assignState( $("#txtcountry"), $("input#txtprovince"), "sstate" );
				assignState( $("#txtbcountry"), $("input#txtbprovince"), "bstate" );
				//alert( $("input#txtprovince").val() );
				$("#errmsgbox").hide();
				$("form#shippingform").submit();
			} else {
				$("#errmsgbox").show();
			}
			return false;

		});
	}
	
	
	
	
	if( $("a#btnPersonalDataButton").length > 0 ) {
		$("a#btnPersonalDataButton").click( function() {
			// do validation 
			var validation = $("form#personaldataupdateform").validate({
				rules: { 
					title: "required",
					firstname: "required",
					surname: "required",
					country: "required",
					city: "required", 
					addr1: "required", 
					//zip: "required",
					phoneday: "required",
					btitle: {required: "#chkdiff:checked"},
					bfirstname: {required: "#chkdiff:checked"},
					bsurname: {required: "#chkdiff:checked"},
					bcountry: {required: "#chkdiff:checked"},
					bcity: {required: "#chkdiff:checked"}, 
					baddr1: {required: "#chkdiff:checked"}, 
					//zip: "required",
					bphoneday: {required: "#chkdiff:checked"}
				},
				messages: {
					title: "",
					firstname: "",
					surname: "",
					country: "",
					city: "",
					addr1: "", 
					//zip: "",
					phoneday: "",
					btitle: "",
					bfirstname: "",
					bsurname: "",
					bcountry: "",
					bcity: "",
					baddr1: "", 
					//zip: "",
					bphoneday: ""
				}
			}).form(); 
			
			/*
			var type = '';
			if (jQuery("form#shippingform").attr("id") != undefined) { 
				type = $("form#shippingform").parent().attr("id");
			}
			*/
			
			if( validation ) {
				// assign sstate, bstate to province
				assignState( $("#txtcountry"), $("input#txtprovince"), "sstate" );
				assignState( $("#txtbcountry"), $("input#txtbprovince"), "bstate" );
 				$("#errmsgbox").hide();
				
				$.post( window.location.href, $("#personaldataupdateform").serialize(), function(data) {
					 
					$("a#personal-data-popup").trigger("click");
				});
				
				//$("form#personaldataupdateform").submit();
			
			
			} else {
				$("#errmsgbox").show();
			}
			return false;

		});
	}
	
	
	
	
	
	
	

	if( $("a#confirmpaymentbutton").length > 0 ) {
		$("a#confirmpaymentbutton").click( function() { 			 
			var validation = false;
			$("#op1").hide();
			$("#op2").hide();
			$("#op3").hide();
			try
			{
				//var ccTypeObjs = $(".cctype"); //document.getElementById("ccType");
				
				if( $("#password").length > 0 ) { 
					validation = $("#checkoutconfirmform").validate({
						rules: {
							ccCode: {
								creditcard2: function(){ return $("input.cctype:checked").val(); }
							},
							ccType: "required",
							ccHolder: "required",
							ccSecNo: "required",
							ccMonth: "required",
							ccYear: "required",
							/*
							ccIssueNo: { required: function() {
								var flag = false;
								$(".cctype").each( function( index, ele ) {									
									if( $(this).is(':checked') && index == 1 )
										flag = true;
								});
								return flag;
							}}, */
							//chktc: { required: true },
							guest_password: { required: true },
							confirm_password: { required: true, equalTo: "#guest_password" }
						},
						messages: {
							ccCode: {
								creditcard2: ""
							},
							ccType: "",
							ccHolder: "",
							ccSecNo: "",
							ccMonth: "",
							ccYear: "",
							//ccIssueNo: "",
							//chktc: "",
							guest_password: { required: ""},
							confirm_password: { required: "", equalTo: "" }
						}
					}).form();
				} else {
					validation = $("#checkoutconfirmform").validate({
						rules: {
							ccCode: {
								creditcard2: function(){ return $("input.cctype:checked").val(); }
							},
							ccType: "required",
							ccHolder: "required",
							ccSecNo: "required",
							ccMonth: "required",
							ccYear: "required"
							/*,ccIssueNo: { required: function() {
								var flag = false;
								$(".cctype").each( function( index, ele ) {									
									if( $(this).is(':checked') && index == 1 )
										flag = true;

								});
								return flag;
							}}*/
							//,chktc: "required"
						},
						messages: {
							ccCode: {
								creditcard2: ""
							},
							ccType: "",
							ccHolder: "",
							ccSecNo: "",
							ccMonth: "",
							ccYear: ""
							//,ccIssueNo: ""
							//,chktc: ""
						}
					}).form();
				}

//$("input#acceptTC:checked").length 
				if( $("input#chktc:checked").length > 0 ) {
					$("input#chktc").parent().removeClass("error");
					$("#op3").hide();				
				} else {
					$("input#chktc").parent().addClass("error");
					$("#op3").show();
				}
				$("#op1").show();
			}
			catch (err )
			{
				//alert( err );
				$("#op2").show();
			}
			
			 
			if( validation && $("input#chktc:checked").length > 0 ) {
				$("#errmsgbox").hide();
				$("form#checkoutconfirmform").submit();
			} else {
				$("#errmsgbox").show();
			}
			return false;
		});
	}
	
	if( $("a.footer-newsletter-link").length > 0 ) { 
		$("a.footer-newsletter-link").fancybox({ 
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width' 			: 360,
			//'height' 			: 250,
			'padding'			: 0,
			'type'				: 'iframe',
			'changeFade' 		: 0,
			'centerOnScroll'	: true,
			'onComplete'		: function() {
				//alert('complete!');
			}
		});
	}
	if( $(".footer-newsletter-button").length > 0 ) {		
		$(".footer-newsletter-button").click( function() {
			if( $("input#newsletterform-email").val() != $("input#newsletterform-email").attr("rel") ) {				
				var url = $("a.footer-newsletter-link").parent().attr("rel") + "?email=" + $("input#newsletterform-email").val();
				$("a.footer-newsletter-link").attr("href", url );
				$("a.footer-newsletter-link").trigger('click');
			
				delete url;
			} else {
			
			}
			return false;
		});
	}

	if( $("a.loginbutton").length > 0 ) {
		$("a.loginbutton").click( function() {
			var validation = $("#loginform").validate({
				rules: {
					email: { 
						required: true,
						email: true
					},
					password: "required"
				},
				messages: {
					email: "",
					password: ""
				}
			}).form();

			if( validation ) {
				$("#loginform").submit();
			} else {
				// show error box
				$("#errmsgbox").show();
			}
			return false;
		});
	}

	if( $("#giftmsg").length > 0 ) {
		$("#giftmsg").focus( function() {
			if( $("#giftmsg").val() == $("#giftmsg").attr("label") )
				$("#giftmsg").val('');
		}).blur( function() {
			if( $("#giftmsg").val() == '' )
				$("#giftmsg").val( $("#giftmsg").attr("label") );		
		});

		if( $("#giftmsg").val() == '' )
			$("#giftmsg").val( $("#giftmsg").attr("label") );

		//$("#giftmsg").labelify({text: 'label'});
	}

	if( $("#productsearchform #s").length > 0 ) {
		//alert("productsearchform #s");
		$("input#s").labelify();
	}

	if( $("#newsletterform-email").length > 0 ) {
		$("#newsletterform-email").labelify();
	}

	if( $("#promotionbutton").length > 0 ) {
		$("#promotionbutton").click( function() {
			
			var text = $("#txtpromotion").val();
			text = jQuery.trim( text );

			if( text.length == 0 ) {
				$("#promoerror").show();
				$("#txtpromotion").addClass("error");
			} else {
				$("#promoerror").hide();
				$("#txtpromotion").removeClass("error");
				$("form#checkoutconfirmform input#mode").val( "updatepromotion" );
				$("form#checkoutconfirmform").submit();
			}
			

			return false;
		});
	}
	
	if( $("#chkdiff").length > 0 ) {
		if( document.getElementById("chkdiff").checked ) {
			$("#billingaddrpart").show();
		}

		$("#chkdiff").click( function() {
			$("#billingaddrpart").show();
		});
		
		$("#chksame").click( function() {
			$("#billingaddrpart").hide();
		});

	}

	if( $("#forgotpwdbutton").length > 0 ) {
		$("#forgotpwdbutton").click( function() {
			var validation = $("#forgotpwdform").validate({
				rules: {
					email: { 
						required: true,
						email: true
					} 
				},
				messages: {
					email: "" 
				}
			}).form();

			//alert(" debug: " + validation);

			if( validation ) {
				$("#errmsgbox").hide();
				
				$.post($("#forgotpwdbutton").attr("href"), { 'mode':'forgotpwd', 'email': $("#forgotpwdform input#email").val() }, function(data) {
					var url = $("#forgotpwdbutton").attr("href") + "?error=" + data;
					$("a#forgotpwdpopup").attr("href", url );					
					//alert( "debug: " + url );
					$("a#forgotpwdpopup").trigger('click');	
					delete url;
				});
			} else {
				// show error box
				$("#errmsgbox").show();
			} 
			
			//errmsgbox 

			return false;
		});
	}
	
	if( $("a#forgotpwdpopup").length > 0 ) {
		$("a#forgotpwdpopup").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 360,
			'height'			: 130,
			'padding'			: 0,
			'centerOnScroll'	: true,
			'type'				: 'iframe',
			'scrolling'			: 'no',
			'onClosed'			: function() {
				var error = gup("error", $(this).attr("href") );
				if( jQuery.trim(error) == "" ) {
					// redirect to login page
					//alert( $("a#loginpage").attr("href") ); 
					window.location.href = "/" + $("a#loginpage").attr("href");
					//window.location.href = '/' + getlangcode() + '/eshop';
				}
			}
		});
	}


			 

	if( $("a#registerbutton").length > 0 ) { 
		
		$("a#registerbutton").click( function(e) {
			//e.preventDefault();
			e.preventDefault();

			var validation = $("#registerform").validate({
				rules: {
					title: { required: true },
					firstname: { required: true },
					lastname: { required: true },
					email: { 
						required: true,
						email: true
					},
					confirmemail: { 
						required: true,
						email: true,
						equalTo: "#registeremail"
					},
					password: { 
						required: true
					},
					confirmpassword: { 
						required: true,
						equalTo: "#registerpwd"
					},
					acceptTC: { required: true }
				},
				messages: {
					title: { required: "" },
					firstname: { required: "" },
					lastname: { required: "" },
					email: { 
						required: "",
						email: ""
					},
					confirmemail: { 
						required: "",
						email: "",
						equalTo: ""
					},
					password: { 
						required: ""
					},
					confirmpassword: { 
						required: "",
						equalTo: ""
					},
					acceptTC: { required: "" }
				}
			}).form();
			
			 
			( $("#acceptTC:checked").length <= 0 ) ? $("#acceptTCtext").addClass("error"): $("#acceptTCtext").removeClass("error");					
			

			if( validation ) {
				// show title error 
				$(".radioTxt").removeClass("error");

				$("#errmsgbox").hide();
				var that = $(this);
				
				$.post($(this).attr("href"), $("form#registerform").serialize(), function(data) {
		 
					var url = that.attr("href") + "?error=" + jQuery.trim(data);
					$("a.signuppopup").attr("href", url );
 					$("a.signuppopup").trigger('click'); 					 
 					delete url;
				});
				delete that;
			} else {
				if( $("input#acceptTC:checked").length > 0 ) {
					$("#acceptTCerr").hide();
				} else {
					$("#acceptTCerr").show();
				}

				if( $("input#registerpwd").val() != $("input#confirmpwd").val() ) {
					$("#pwderr").show();
				} else {
					$("#pwderr").hide();
				}


				// show error box
				$("#errmsgbox").show();

				// show title error 
				$(".radioTxt").addClass("error");
				//$("input.error[type='radio']").parent().addClass("error");
			} 

			return false;
		});
	}

	if( $("a.signuppopup").length > 0 ) { 
		$("a.signuppopup").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: 360,
			'height'			: 500,
			'padding'			: 1,
			'type'				: 'iframe',
			'onClosed'			: function() {
				
				//if( $(".mainpanel").attr("rel") != "" ) {
				var error = gup("error", $(this).attr("href") );
				if( error == "" || error == "0" || error == 0 ) { 
					window.parent.location.href = $("a#loginpage").attr("href");
				}
				//window.location.href = '/' + getlangcode() + '/eshop';
				
				/*
				var error = gup("error", $(this).attr("href") );
				if( jQuery.trim(error) == "" ) {
				}
				*/
			}
		});
	}

	if( $("a.register-terms").length > 0 ) {
		
	}
	
	if( $("a.deleterecentlyviewed").length > 0 ) {
		$("a.deleterecentlyviewed").click( function() {
			var param = $(this).attr("rel");
			var that = $(this);
			var _skut, _color;
			var params = param.split( "," );
			_skut = _color = "";
			_skut = params[0];
			_color = params[1];
			
			var total = that.parent().parent().parent().children("li").length;
			var catpanel = that.parent().parent().parent().parent("div");
			var item = that.parent().parent(); 
			$.post($(this).attr("href"),  { 'mode':'delete', 'skut': _skut, 'color': _color }, function(data) {
				// remaining 
				if( total == 1 ) {
					catpanel.remove();	
				} else {
					item.remove();
				}
				$("#myshoppingsession-recently").html( total-- );
			});
			delete _skut;
			return false;
		});
	}

	if( $("a.like-delete").length > 0 ) {
		$("a.like-delete").click( function() {
			var param = $(this).attr("rel");
			var that = $(this);
			var _skut, _color;
			_skut = _color = "";
			var params = param.split( "," );
			_skut = params[0];
			_color = params[1];

			var total = that.parent().parent().parent().children("li").length;
			var catpanel = that.parent().parent().parent();
			var item = that.parent().parent();
			$.post($(this).attr("href"),  { 'mode':'delete', 'skut': _skut, "color": _color }, function(data) {
				// remaining 
				if( total == 1 ) {
					catpanel.remove();	
				} else {
					item.remove();
				}

				reloadMyShoppingSession();

				///$("#myshoppingsession-like").html( total-- );
			});
			
			 
			delete _skut, _color, params;
			return false;
		});
	}

	if( $(".store-col1 ul li a").length > 0 ) {
		$(".store-col1 ul li a").hover( function() {
			
			$(".store-col1 ul li a").removeClass("active");
			$(this).addClass("active");
			$(".store-col2 ul li a").parent().addClass("hide");
			$("li.country"+$(this).attr("rel")).removeClass("hide");
			
			// clear country active
			$(".store-col2 ul li a").removeClass("active");
 
			// clear city col
			$(".store-col3 ul li a").removeClass("active");
			$(".store-col3 ul li a").parent().addClass("hide");

			// clear city and store
			$(".store-col3 ul li a").removeClass("active");			
			$(".store-row").addClass("hide");
			
			return false;
		});
	}

	if( $(".store-col2 ul li a").length > 0 ) {
		$(".store-col2 ul li a").hover( function() {			
			
			$(".store-col2 ul li a").removeClass("active");
			$(this).addClass("active");
			$(".store-col3 ul li a").parent().addClass("hide");		
			$("li.city"+$(this).attr("rel")).removeClass("hide");
			
			// clear city and store
			$(".store-col3 ul li a").removeClass("active");			
			$(".store-row").addClass("hide");
			
			return false;
		});
	}

	if( $(".store-col3 ul li a").length > 0 ) {
		$(".store-col3 ul li a").hover( function() {			
			
			$(".store-col3 ul li a").removeClass("active");
			$(this).addClass("active");
			
			$(".store-row").addClass("hide");
			$(".city" + $(this).attr("rel")).removeClass("hide");
			//$(".store-col3 ul li a").parent().addClass("hide");		
			//$("li.city"+$(this).attr("rel")).removeClass("hide");
		
			return false;
		});
	}
	
	var country_state = function( country, txtstate, state ) {
		if( country.length > 0 ) {
			var val = country.val();
			if( $( "#" + state + val).length > 0 ) {
				$( "#" + state + val).show();
				txtstate.hide();
			} else {
				$( "." + state).hide();
				txtstate.show();			
			}
		}
	}

	if( $("#txtcountry").length > 0 ) {
		$("#txtcountry").change( function() {
			country_state( $("#txtcountry"), $("#txtprovince"), "sstate");
		});
	}

	if( $("#txtbcountry").length > 0 ) {
		$("#txtbcountry").change( function() {
			country_state( $("#txtbcountry"), $("#txtbprovince"), "bstate");
		});
	}

	country_state( $("#txtcountry"), $("#txtprovince"), "sstate");
	country_state( $("#txtbcountry"), $("#txtbprovince"), "bstate");


	if( $("a.shareiT").length > 0 ) {
		$("a.shareiT").click( function() {
			return false;
		});
	}

	if( $(".sharemenu").length > 0 ) {
		$("div.sharearea").hover( function() {
			if( $(".sharemenu").css( "display") == "none" ) { 
				$('.sharemenu').slideToggle(1000);
			}
		}, 
		function() {
			if( $(".sharemenu").css( "display") == "block" ) { 
				$('.sharemenu').slideToggle(1000);
			}
		});

		$("a.shareiT").click( function() { return false; } );
	}

	if( $(".sharemenubottom").length > 0 ) {
		$("div.sharearea").hover( function() {
 			if( $(".sharemenubottom").css("display") == "none" ) { 
				$('.sharemenubottom').slideDown(1000);//slideToggle(1000);
			} 
		}, 
		function() {
			if( $(".sharemenubottom").css( "display") == "block" ) { 
				$('.sharemenubottom').slideUp(1000); //slideToggle(1000);
			}
		});

		$("a.share").click( function() { return false; } );
	}
	
	
	if( $("a.print").length > 0 ) {
		$("a.print").click( function() {
			window.print();
			return false;
		})
	}

	if( $("a.win_open").length > 0 ) {
		$("a.win_open").click( function() {
			window.open( $(this).attr("href"),"popup","status=1,width=550,height=350");
			return false;
		});
	}
	
	if( $("a#setpwdbutton").length > 0 ) {
		 
		 $("a#setpwdbutton").click( function(e) { 
			var validation = $("form#setpwdform").validate({
				rules: { 
					password: "required",
					confirmpassword: { 
						required: true,
						equalTo: "#password"
					}										
				},
				messages: {
					password: "",
					confirmpassword: { 
						required: "",
						equalTo: ""
					}							
				}
			}).form();
			//alert( validation );
			if( validation ) {
				$("form#setpwdform").submit();
			} else {
				if( $("input#password").val() != $("input#confirmpassword").val() ) {
					$("#error1").hide();
					$("#error2").show();
				} else {
					$("#error1").show();
					$("#error2").hide();
				}
				$("#errmsgbox").show();
			}
			delete validation;
		});
	}

	if( $("a#emailtofrdsubmit").length > 0 ) {
		$("a#emailtofrdsubmit").click( function() { 
			var validation = $("form#emailfrdform").validate({
								rules: { 
									yourname: "required",
									youremail: { 
										required: true,
										email: true
									},						 
									frdname: "required",
									frdemail: { 
										required: true,
										email: true
									}
								},
								messages: {
									yourname: "",
									youremail: { 
										required: "",
										email: ""
									},						 
									frdname: "",
									frdemail: { 
										required: "",
										email: ""
									}
								}
							}).form(); 
			if( validation ) {
				$("form#emailfrdform").submit();
			} else {
				$("#errmsgbox").show();
			}
		});

		return false;

	}
	
	if( $(".sstate").length > 0 ) {		
		$(".sstate").change( function() {
			if( $(this).val() != "" ) {
				updateCheckoutRightItem();
				reloadTopShoppingbag();
			}
		});
	}
	
	if( $("#myaccount-shipping #btnShippingButton").length > 0 ) {
		
	}

	if( $(".changeshippingcountry").length > 0 ) {
		$(".changeshippingcountry").change( function() {
			if( $(this).val() != "" ) {
				var data = $("form#shippingform").serialize();
				var timestamp = Number(new Date());
			 
				updateCheckoutRightItem();
				reloadTopShoppingbag();
				/*
				data += "&exit=1";
				$.post( document.location.href, data, function() {
					updateCheckoutRightItem();
					reloadTopShoppingbag();
				});
				*/
			}
		});
	}

	if( $("a#resetbutton").length > 0 ) {
		$("form#emailfrdform").reset();
		return false;
	}


	if( $(".rollingArea").length > 0 ) {
		$(".rollingArea").jCarouselLite({
			auto:	true,
			speed:	5000
		});
	}
	  
});



var addsizeopt = function(e, active) {
	if( active == '' ) {
		var str = e.className;
		var css = '';
		var arr = str.split(" ");
		var bool = false;
		for( var i = 0; i < arr.length; i++ ){		
			if( arr[i] == "active" )
				bool = true;
			else 
				css += arr[i] + ' ';
		}
		if( bool ) 
			e.className = css;
		else 
			e.className += " active";
	}
};
