var lang_txt = new Array();
lang_txt['checkemail'] = 'Please check your email address.\nYour email addresses should look like "myname@gmail.com"';
lang_txt['bookm'] = 'AddThis Social Bookmarking Widget';
lang_txt['notice_12_22'] = '<strong>IMPORTANT NOTICE:</strong> Dear Customers, after <strong>Sunday 21 Dec 17:00 (PST)</strong> we can no longer guarantee items ordered from LightInTheBox.com will arrive before Christmas Day. We are still working hard over the Holidays to source, pack and ship the best quality products, so you are invited to browse now for 2009. <br />Merry Christmas and a Happy New Year from everyone at LightInTheBox!';
lang_txt['notice_1_22'] = '<strong>5%</strong> Off Promotion for the Chinese New Year. Order between <strong>Jan 22</strong> and <strong>Feb 1 (PST)</strong> to receive a <strong>5% discount on all items</strong> at LightInTheBox.com. For more details on this exclusive offer, <a href="http://www.lightinthebox.com/html/notice.html" class="u">click here</a>.'
lang_txt['pageText']='Displaying';
lang_txt['ADDART']='Add to Cart';
lang_txt['ATTRIBUTESELECT']='Please Select';
lang_txt['WIN_OPEN_TITLE']='Help LightInTheBox to serve you better. ';
lang_txt['WIN_OPEN_CON']='Please take 2 mins to answer a few short questions about our website. Thank you! ';
lang_txt['WIN_OPEN_BUTTON_NEVER']='Never';
lang_txt['WIN_OPEN_BUTTON_LATER']='Later';
lang_txt['WIN_OPEN_BUTTON_NOW']='Now';
lang_txt['FRM_CHECK_TEXT']=[
	"The two passwords you entered don't match. Please try again.",
	"Are you sure your ",
	" is correct? E-mail addresses must contain an \"at\" sign (@) and a period (.) somewhere to the right of the @, with no spaces or commas. (Example: yourname@lightinthebox.com)",
	"Is your ",
	" correct? Sorry, my system does not understand your telephone format.",
	"Your ",
	" must contain a minimum of ",
	" characters.",
	" correct? Our system requires a maximum of ",
	"a valid email address",
	"a password",
	"you need to confirm your",
	"Sorry, you need to ",
	"Sorry, ",
	" is required.",
	"a \"Title\"",
	"Please choose ",
	"Are you sure you want to delete reviews?",
	"Full name information is required.",
	"E-mail address information is required.",
	"Are you sure your email address is correct? An email address should contain the \"@\" and \".\" characters.",
	"Phone information is required.",
	"phone must be number",
	"QTY information is required.",
	"Quantity (Qty.) must be a number.",
	"Minimum Quantity (Qty.) is 3 units.",
	"Any questions about delivery, products or any special instructions about your order, write it down here.",
	"Inquiry information is required.",
	"Your inquiry is too long. The maximum length is 500 characters.",
	"Name is too long. The maximum length is 50 characters.",
	"Phone number cannot contain letters and must be less than 20 characters long.",
	"Please enter the validation code in the box provided.",
	"The validation number you entered is incorrect.",
    "Please Choose Your Country.",
    "Please Choose Your Describes.",
	"Please enter the ",
	" in this format: 0911020100375457.",
        "The two email address you entered don't match. Please try again.",
	"Phone number is invalid.",
	"Your phone number must be at least 9 digits."
];
lang_txt['TEXT_PLEASE_SELECT']='Please Select';
////
lang_txt['save'] = 'Save';
lang_txt['freeshipping'] = 'Free Shipping';
lang_txt['retailprice'] = 'Retail Price';
lang_txt['view_orders_paypal_first'] = 'The order status shall be updated from pending to apropos status in 48 hours after you placed and paid your order. If you pay again for this order via the button below, it will be updated to a new order. are you continue?';
lang_txt['view_orders_paypal'] = 'Thank you, we have received the payment for your order, and it is now processing. Please do not try to resend your payment again.';
lang_txt['searchTicketId'] = 'Please submit valid ticket number!';
var lang = new Array();
lang['save'] = 'Save';
lang['freeshipping'] = 'Free Shipping';
lang['retailprice'] = 'Retail Price';
lang_txt['Required'] = '*Required';
function MouseEvent(e) {this.x = e.pageX;this.y = e.pageY;this.l=e.clientX;this.t=e.clientY;}
//list
(function($){
	$.fn.jqList = function(options){
		var sets = {size:8,number:0,total:0,cid:0,no:0}, isSub=false;;
		if(options) {$.extend(sets, options);};
		sets.current=Math.floor(sets.number/sets.size);
		sets.pages=Math.ceil(sets.total/sets.size);
		page(Math.floor(sets.no/sets.size));
		function page(t){
			var current=sets.current;
			switch (t) {
				case -1:	
					current=current<1?(sets.pages-1):(current-1);
					break;
				case 1:				
					current=current<(sets.pages-1)?(current+1):0;
					break;
				default:
					current=t;
					break;
			}
			sets.current=current;	
			$(sets.id+"Page").html("page "+(sets.current+1)+" of "+(sets.pages));//kule
			get();
		}
		function get(){
			var mx=0,cn="#cell_name",ci="#cell_img";
			for(var i = sets.current*sets.size;i<(sets.current+1)*sets.size;i++){
				var p = [],s = productArr[i];	
				if(s){
					// i=id,n=name,m=img,s=salePrice,p=price,c=count,o=soldOut,a=almost
					p.push(s.i,s.n,s.m,s.s,s.p,s.c,s.o,s.a);
					$(sets.id+" li").eq(mx).replaceWith($(".proList").html().replace(/{%salePrice%}/ig,p[3]).replace(/{%price%}/ig,symbol_left+p[4]).replace(/{%pAlt%}/ig,p[1]?p[1]:'').replace(/{%pName%}/ig,p[1]?p[1].substring(0,35)+"...":'').replace(/{%i%}/ig,i).replace(/{%pOff%}/ig,p[5]));
					$(cn+i).attr("href",rewrite_url(p[1],p[0]));
					$("#cell_link"+i).attr("href",rewrite_url(p[1],p[0]));
					loadImage(imgURL+p[2],chUrl,ci+i);
					if(p[0]==productid) {$(ci+i).addClass("border-red");}
					function showHide(a){for(var k=0;k<a.length;k++){a[k].a=="0"||a[k].a==null?$(a[k].b+i).hide():$(a[k].b+i).show();}}
					showHide([{a:p[6],b:"#a_arr_"},{a:p[5],b:"#b_arr_"},{a:p[7],b:"#c_arr_"}]);
				}else{
					$(sets.id+" li").eq(mx).html("");
				}
				mx++;
			}
		}
		if(sets.pages>1){$(".recent_flash_prev").click(function(){if(isSub) return;subOk();page(-1);});$(".recent_flash_next").click(function(){if(isSub) return;subOk();page(1);});}
		function subOk(){isSub=true;window.setTimeout(function(){isSub=false;},500);};
	}
})(jQuery);
// Marquee
(function($){
	var methods = {
        marquee: function marquee(user_settings) {
            var self = $(this);            
			var sch = self.attr('scrollHeight');
			self.append(self.html());
            var settings = {
                timeout: null,                
                events: {
                    play: function(evt) {
                        var self = $(this);						
						var sct = self.scrollTop();
						if(sct>=sch)self.scrollTop(sct=sct-sch);
						self.animate({scrollTop:sct+settings.step-sct%settings.step},2000,function(){
							if(settings.timeout) clearTimeout(settings.timeout);
							settings.timeout = setTimeout(function(){self.marqueePlay()},settings.time);
						});
                    },
                    stop: function(evt) {
                        var self = $(this);
                        clearTimeout(settings.timeout);self.stop();
                    }
                }
            };
            if(self.data("marquee.settings")) {
                settings = self.data("marquee.settings");
            }
            settings = $.extend(user_settings, settings);            
            for(var event in settings.events) {
                var evt = "marquee." + event;
                self.unbind(evt);
                self.bind(evt, settings.events[event]);
            }            
            self.data("marquee.settings", settings);
			self.marqueePlay();
            return self;
        },
        marqueePlay: function() {
            $(this).trigger("marquee.play");         
        },
        marqueeStop: function() {
            $(this).trigger("marquee.stop");
        }
    };
    $.each(methods, function(i) {
        $.fn[i] = this;
    });
})(jQuery);
/**********************************/
function show(a){$("#"+a).show();}function hide(a){$("#"+a).hide();}
function back(num){history.go(num);return false;}
function findPos(obj){return[$(obj).offset().left,$(obj).offset().top];}
function loadImage(url, callback,id) {var img = new Image();img.src = url;if (img.complete) { callback.call(img,id);}else{$(img).bind("load", function(){callback.call(img,id);});}}
function rewrite_url(pname,pid){if(pid==null||pid=="undefined"){return""};var re=/[,.?!`~@#$%^&*()_\-=+{\[}\]|\\;:'"<>\/]/ig;var url="";if(FRIENDLY_URLS!=null&&FRIENDLY_URLS=='true'){url=baseURL+pname.replace(re,"").replace(/^\s+|\s+$/g,"").replace(/\s+/ig,"-").toLowerCase()+"_p"+pid+".html";}else{url=linkURL+pid;}return url;}
function chUrl(id){$(id).attr({src:this.src});};
function isNone(str){return str==null||$.trim(str)==""?true:false;};
String.prototype.trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g,"");};String.prototype.inc=function(k1,k2){if(k2==null){k2=","};return(k2+this+k2).indexOf(k2+k1+k2)>-1?true:false;};String.prototype.sub=function(k1,k2){if(k2==null){k2=","};var tmp=k2+this+k2;var size=tmp.indexOf(k1);if(size==-1){return 0;}var i=0;while(tmp.charAt(size+3+i)!='/'){i++;}return tmp.substring(size+3,size+3+i);};
function efocu(obj){try{$(obj).focus();}catch(e){}};
function insHtm(obj,code,pos){obj=$(obj)[0];if($.browser.msie){obj.parentNode.insertAdjacentHTML(pos==null?"beforeend":"afterbegin",code);}else{var r=obj.ownerDocument.createRange();r.setStartBefore(obj);eval("obj.parentNode."+(pos==null?"appendChild":"insertBefore")+"(r.createContextualFragment(code),obj.parentNode.firstChild)");}}
function checkEmail(id){var email=$("#"+id)[0]==null?'':$("#"+id).val();if(!/(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/.test(email.replace(/-|\//g,""))){$(id).focus();alert(lang['checkemail']);return false;}else{return true;}}
var openShow=false;
function show_chat_div(obj){
	if(openShow){close_chat_div();return;}
	openShow=true;
	$('#nav_chat_sales').marqueeStop()
	var msn=$(obj).attr("msn"),skype=$(obj).attr("skype"),email=$(obj).attr("email"),yahoo=$(obj).attr("yahoo");
	var str="",s1="<li><span class='big black b'>",s2="</span><BR/> <span class='pad_1em'>",s3="</span></li>";
	str+="<ul class='gray_trangle_list'>";
	function setStr(a){for(var i=0;i<a.length;i++){if(a[i].a!=null&&a[i].a!=""){str+=s1+a[i].b+s2+a[i].a+s3;}}};
	setStr([{a:email,b:"Email"},{a:msn,b:"MSN"},{a:skype,b:"SKYPE"},{a:yahoo,b:"YAHOO"}]);
	str+="</ul>";
	$('#chat_div_name').html(str);
	$('#chat_div').show();
	hide_select(0,"rel","dropdown");
}
function close_chat_div(){$('#chat_div').hide();$('#nav_chat_sales').marqueePlay();openShow=false;}
function hide_select(a,b,c){
	$("select").each(function(i){
		var t=a==0?"hidden":"visible";
		var r=b==0?"":"["+b+"*='"+c+"']";
		if($.browser.version==6.0) $("select"+r).css({visibility:t});
	});
}
function toggle(el){if($("#"+el).css("display")=="none"){$("#"+el).show();}else{$("#"+el).hide();}}

function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++)
{var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function trackingChat(){
	var img=new Image();
	img.src = 'http://www.lightinthebox.com/click_to_live_chat';
}


var li1="li_img01",li2="li_img02";
// imgbox
function ls(a,b){
	var me=this;
	var wgif="includes/templates/lightinthebox/images/tran.gif";
	var class_ul="product_list_li_ul",class_text="product_list_text",pop="pop_window",isImg=$(a)[0]?true:false,isList=b?true:false;
	var tListHtml="<ul><li class=\"wWin_li\"><div class=\"wWin_li_l\" next=\"l\" title=\"Back\"></div><div class=\"wWin_li_c\"><ul class=\""+class_ul+"\"></ul></div><div class=\"wWin_li_r\" next=\"r\" title=\"Next\"></div><li/><span class=\"g_t_c pr210\">"+lang_txt['pageText']+" <span class=\""+class_text+"\"></span></span></ul>";
	this.starl=this.start=this.starw=this.starh=this.state=this.starc=this.imgsrclist=this.imgin=this.winin=this.srcArr=[];
	var $win,$pho,$bp,$bg,$wlist,$close;
	function createElem(tagName,intObject){
		intObject=intObject||{};
		var newTag = document.createElement(tagName);
		for (var i in intObject) {
			newTag[i] = intObject[i];
		}
		return newTag;
	}
	function getScrollTop(){function ieTrueBody(){return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;}return $.browser.msie ? ieTrueBody().scrollTop : window.pageYOffset;}
	function getPos(e){
		var $e=$(e);
		return {t:$e.offset().top,l:$e.offset().left,w:$e.width(),h:$e.height()};
	}
	function getTag(name,obj){var oo=obj||document.body;return oo.getElementsByTagName(name);}
	window.onresize=function(){
		$("div").each(function(){
			if($(this).hasClass("wBg2")){
				getClientSize();
				setBgStyle($(this));
			}
		});
	}
	function setBgStyle(obj){
		getClientSize();
		obj.css({height:Math.max(cH,bH,sH),width:Math.max(cW,bW,sW)});
	}
	function imgInit(a,b,c,d,e,w){
		var newarr=initList(a,b,c,d,e,w);
		newarr[7].innerHTML=(parseInt(newarr[2])+1)+"/"+(parseInt(newarr[1])+1);
		var b_l=b.length;
		for(var i=0;i<b_l;i++){
			(function(i){
				b[i].onclick=function(){
					b[newarr[8]].className=li2;
					b[i].className=li1;
					me.number=i;
					newarr[8]=i;
					a[0].src=wgif;
					var z=b[i].getAttribute("imgb");
					var y=me.srcArr;
					var s=w?(y[2]+z):(me.state[0]==0?(y[2]+y[1]+z.split(y[0])[1]):(y[2]+y[3]+z.split(y[3])[1]));
					a[0].setAttribute("title",b[i].getAttribute("title"));
					a[0].setAttribute("alt",b[i].getAttribute("alt"));
						loadImage(s,chUrl,a[0]);
					if(me.state[0]==1&&!isList){
						me.img=me.a[me.number];
						var pos=getPos($(me.img)[0]);
						me.starl[0]=pos.l;
						me.start[0]=pos.t;
						me.starw[0]=pos.w;
						me.starh[0]=pos.h;
					}
					return false;
				};
				$(b[i]).hover(function(){b[i].className=li1;},function(){if(i!=newarr[8]) b[i].className=li2;});
			})(i);
		}
		var c_l=c.length;
		for(var n=0;n<c_l;n++){
			(function(n){
				var tt = newarr;
				if(parseInt(tt[1])<1) return;
				if(c[n].getAttribute("next")=="l") c[n].onclick=function(){showList(1,tt);}
				if(c[n].getAttribute("next")=="r") c[n].onclick=function(){showList(0,tt);}
			})(n);
		}
	}
	function initList(a,b,c,d,e,w){
		var rlist,rtext,e_l=e.length,d_l=d.length;
		for(var u=0;u<e_l;u++){
			if(e[u].className==class_ul) rlist=e[u];
		}
		for(var i=0;i<d_l;i++){
			if(d[i].className==class_text) rtext=d[i];
		}
		if(w){
			me.imgin=[0,Math.floor((me.imgsrclist.length-1)/5),0,270,0,0,rlist,rtext,0,5,10];
			return me.imgin;
		}else{
			me.winin=[0,Math.floor((me.imgsrclist.length-1)/7),0,420,0,0,rlist,rtext,0,7,20];
			return me.winin;
		}
	}
	function setImglist(){
		var _list=isList?me.b:me.a;
		var liHtml="";
		$(_list).each(function(){
			var sc=$(this).attr("src").split(me.srcArr[0])[1];
			liHtml+="<li><img title=\""+$(this).attr("title")+"\" imgb=\""+me.srcArr[3]+$(this).attr("imgb").split(me.srcArr[1])[1]+"\" src=\""+me.srcArr[2]+me.srcArr[0]+sc+"\" class=\""+li2+"\"/></li>";
			me.imgsrclist.push(sc);
		});
		var eul=getTag("ul",me.wlist);
		$wlist.find("ul").each(function(){if($(this).hasClass(class_ul)) $(this).html(liHtml);});
		me.f=getTag("div",me.wlist);
		me.g=getTag("span",me.wlist);
		me.i=getTag("ul",me.wlist);
		me.j=getTag("img",me.wlist);
		me.k=getTag("img",me.win);
		imgInit(me.k,me.j,me.f,me.g,me.i,false);
	}
	function create(){
		me.win=createElem("DIV",{className:"wWin"});
		me.close=createElem("DIV",{className:"winclose hide"});
		me.win.onclick=me.close.onclick=function(){
			if(me.startt==1) return;
			winOnclick();
			return false;
		};
		me.close.onclick = function(){$close.show();};
		me.pho=createElem("IMG");
		me.pho.setAttribute("src",wgif);
		me.wlist=createElem("DIV",{className:"wList hide"});	
		me.wlist.innerHTML=tListHtml;
		me.bg=createElem("DIV",{className:"wBg2"});
		me.bp=createElem("DIV",{className:"wBp hide"});
		for(var i=1;i<8;i++){var bpb=createElem("B",{className:"o"+i,id:"bpb"+i});me.bp.appendChild(bpb);}
		document.write('<span id="wPop_'+$(a)[0].id+'" class="wPop"></span>');
		me.win.appendChild(me.pho);
		$win=$(me.win),$pho=$(me.pho),$bp=$(me.bp),$bg=$(me.bg),$wlist=$(me.wlist),$close=$(me.close);
		$("#wPop_"+$(a)[0].id).append(me.bg);
		$("#wPop_"+$(a)[0].id).append(me.win);
		$("#wPop_"+$(a)[0].id).append(me.wlist);
		$("#wPop_"+$(a)[0].id).append(me.bp);
		$("#wPop_"+$(a)[0].id).append(me.close);
	}
	function winOnclick(){
		$bp.stop();
		$wlist.stop().hide().css({height:0});
		$close.hide();
		$win.removeClass("lbg");
		$bp.find("b").stop().each(function(i){if(i>1&&i<5){$(this).css({height:me.maxh-20});}}).end().hide().css({height:me.maxh+20});	
		show();
	}
	function imgLoad(){
		var _a=me.a,_a_l=_a.length;
		for(var i=0;i<_a_l;i++){
			(function(i){
				_a[i].onclick=function(){
					if(me.state[0]==1) return false;
					if(me.startt==1) return false;
					me.img=_a[i];
					if(me.state[0]==0&&!isList) me.number=i;
					getClientSize;
					setContent();
					me.pho.src=wgif;
					show();
					return false;
				}
			})(i);
		}
	}
	function setContent(){
		var pos=getPos($(me.img)[0]);
		$win.css({height:pos.h,width:pos.w,left:pos.l,top:pos.t});
		setBgStyle($bg);
		var mt=(getScrollTop()+(cH-me.maxh-70)/2);
		me.maxt=mt>0?mt:10;
		me.maxl=(cW-me.maxw)/2;
		me.starl=[me.maxl,pos.l];
		me.start=[me.maxt,pos.t];
		me.starw=[me.maxw,pos.w];
		me.starh=[me.maxh,pos.h];
		me.starc=[0.1,1];
	}
	function show(){
		me.state[0]==0?$bg.show():$bg.hide();
		hide_select(0,0);
		me.startt=1;
		$win.show().css({opacity: me.starc[0]}).animate({opacity: me.starc[1],top:me.start[0],left:me.starl[0],width:me.starw[0],height:me.starh[0]}, 500,function(){actShow();});
		$pho.show().css({opacity: me.starc[0]}).animate({opacity: me.starc[1],width:me.starw[0],height:me.starh[0]}, 500);
		function actShow(){
			var z=me.img.getAttribute("imgb");
			var y=me.srcArr;
			var imgrc=isList?(y[2]+y[3]+me.img.src.split("/l/")[1]):(y[2]+y[1]+z.split(y[0])[1]);
			me.pho.setAttribute("title",me.img.getAttribute("title"));
			loadImage(imgrc,chUrl,me.pho);
			me.startt=0;
			var al=[me.starl,me.start,me.starw,me.starh,me.starc,me.state],al_l=al.length;
			for(var i=0;i<al_l;i++){al[i].reverse();}
			if(me.state[0]==0){
				$win.hide();
				$bg.hide();
				hide_select(1,0);
			}else{
				var l=me.starl[1],t=me.start[1];
				$win.addClass("lbg").hover(function(){if(me.startt==1) return;showClose();},function(){if(me.startt==1) return;$close.hide();});
				$bp.css({left:l-10,top:t-10}).show().animate({height:"590"}, 600);
				$wlist.css({left:l,top:t+me.maxw}).show().animate({height:"70"}, 600,function(){setBgStyle($bg);showClose();});
				$bp.find("b").each(function(i){if(i>1&&i<5){$(this).animate({height:"550"},300);}});
				function showClose(){$close.css({left:($win.offset().left+me.maxw-20),top:($win.offset().top+5)}).show();}
			}
			setContact();
		}
	}
	function setContact(){
		if(me.state[0]==1){
			contacts(me.winin,me.j);
		}else{
			if(isList){
				contacts(me.imgin,me.b);
				me.a[0].src=wgif;
				var s=me.srcArr[2]+me.srcArr[1]+me.b[me.number].src.split(me.srcArr[0])[1];
				me.a[0].setAttribute("title",me.b[me.number].getAttribute("title"));
				loadImage(s,chUrl,me.a[0]);
			}
		}
		function contacts(m,z){
			m[2]= Math.floor(me.number/m[9]);
			m[6].style.left=-m[3]*m[2]+"px";
			m[0]=-m[3]*m[2];
			m[8]=me.number;
			var z_l=z.length;
			for(var i=0;i<z_l;i++){z[i].className=li2;}
			z[me.number].className=li1;
			m[7].innerHTML=(parseInt(m[2])+1)+"/"+(parseInt(m[1])+1);
		}
	}
	this.init=function(){
		if(!isImg) return;
		me.a=getTag("img",$(a)[0]);
		if(!isList&&me.a.length==0) return;
		if(isList){
			me.b=getTag("img",$(b)[0]);
			me.c=getTag("div",$(b)[0]);
			me.d=getTag("span",$(b)[0]);
			me.e=getTag("ul",$(b)[0]);
		}
		create();
		me.maxw=500,me.maxh=500,me.number=0,me.startt=0,me.state=[0,1];
		getClientSize();
		getSrc();
		imgLoad();
		setImglist();
		if(isList) imgInit(me.a,me.b,me.c,me.d,me.e,true);
	}
	function getSrc(){
		var i="/images/";
		var a=isList?(i+"s/"):i;
		var b=isList?(i+"l/"):i;
		var c=isList?me.b[0].src.split(a)[0]:me.a[0].src.split(a)[0];
		var d=isList?(i+"v/"):i;
		me.srcArr=[a,b,c,d];
	}
}
function getClientSize(){
	var dd=document.documentElement,db=document.body;
	cW=dd.clientWidth;
	cH=dd.clientHeight;
	bW=db.offsetWidth;
	bH=db.offsetHeight;
	sH=dd.scrollHeight;
	sW=dd.scrollWidth;
}
function showList(t,m){
	if(m[4]==1) return;
	var x=t==0?-m[3]:m[3];
	if(t==0&&m[2]==m[1]){ rolling(1);cycleShow(1);}else if(t==1&&m[2]==0) {rolling(2);cycleShow(0);}else{ rolling();}
	function rolling(e){
		m[4]=1;
		$(m[6]).animate({left:parseInt($(m[6]).css("left"))+x},300,function(){pageSet(e);m[4]=0;});
	}
	function cycleShow(y){
		$(m[6]).after($(m[6]).clone(true).css({left:(y==1?(m[3]):(-m[3]*(m[1]+1)))}));
		$(m[6]).next("ul").animate({left:parseInt($(m[6]).next("ul").css('left'))+x},300,function(){
			m[0]=y==1?0:-m[3]*m[1];
			$(m[6]).addClass("hide").css({left:m[0]}).next("ul").css({left:m[0]}).end().removeClass("hide").next("ul").remove();
		}); 
	}
	function pageSet(h){if(h){m[2]=h==1?0:m[1];}else{t==0?m[2]++:m[2]--;}$(m[7]).html((parseInt(m[2])+1)+"/"+(parseInt(m[1])+1));}
}
///////////////zoom image
 // constants
var viewportWidth = 380,viewportHeight = 500,tileSize = 250;
var imageBaseName,imageDatePath;
// START:globalstate
var zoom = 0;
var zoomPath = ["s","m","l"];
var zoomSizes = [ [ "500px", "500px" ],[ "1000px", "1000px" ], [ "1500px", "1500px" ] ];
// END:globalstate
var scaleMode = "out";
// used to control moving the map div
var dragging = false;
var pDragging = false;
var is1500=true;
var offTop = 0,offLeft = 0;
var oT,oL,dragStartTop,dragStartLeft,dragST,dragSL;
function init() {
	imageDatePath = getRegExp($("#zoomBg")[0].src,0);
	imageBaseName = getRegExp($("#zoomBg")[0].src,1);
    // make inner div big enough to display the map
    // START:innerDivSize
    setInnerDivSize(zoomSizes[zoom][0], zoomSizes[zoom][1]);
    // END:innerDivSize
    // wire up the mouse listeners to do dragging                
	$("#outerDiv").bind("mousedown",startMove);
	$("#outerDiv").bind("mousemove",processMove);
	$("#outerDiv").bind("mouseup",stopMove);
	$("#outerDiv").bind("dblclick",scaleMove);				
	$("#pointer").bind("mousedown",pStartMove);
	$("#pointer").bind("mousemove",pProcessMove);	
	$("#pointer").fadeTo("slow", 0.6);
    // necessary to enable dragging on IE
	document.getElementById("outerDiv").ondragstart = function() { return false; }				
    document.getElementById("pointer").ondragstart = function() { return false; }
    checkTiles();
	initList();
	if(initBigImg==0){
		var isrc=$("#thumbnail_zoom img")[0].src;
		$("#zoomBg").attr({src:imagePath+"v/"+getRegExp(isrc,0)+"/"+getRegExp(isrc,1)+".jpg?35103"}).siblings().hide();
		is1500=false;
	}
}
function getRegExp(str,exp){
	var regExps=exp==1?/\/s\/[0-9]*\/([A-Za-z0-9]*)/:/\/s\/([0-9]*)/;
	regExps.exec(str);
	return RegExp.$1;
}
function initList(){
	var zl=".zoom_list_";
	var $list={a:$(zl+"ul").get(0),b:$(zl+"text").get(0),c:$(zl+"ul img"),e:$(zl+"ul img"),f:$(zl+"l"),g:$(zl+"r")};
	var newarr=[0,Math.floor(($list.c.length-1)/6),0,325,0,0,$list.a,$list.b,$list.c.hasClass(li1),6,25];
	$(newarr[7]).html((parseInt(newarr[2])+1)+"/"+(parseInt(newarr[1])+1));
	$list.c.each(function(){
		$(this).click(function(){
			$(this).removeClass(li2).addClass(li1);
			$(newarr[8]).removeClass(li1).addClass(li2);
			newarr[8]=$(this);
			sr=$(this).attr("src");
			$("#thumbnail_zoom img").attr({src:sr});
			if($(this).attr("bimg")==0){
				$("#zoomBg").attr({src:imagePath+"v/"+getRegExp(sr,0)+"/"+getRegExp(sr,1)+".jpg?35103"}).siblings().hide();
				is1500=false;
			}else{			
				$("#zoomBg").attr({src:sr});
				imageDatePath = getRegExp($("#zoomBg")[0].src,0);
				imageBaseName = getRegExp($("#zoomBg")[0].src,1);
				is1500=true;
			}
			goZoom('reset');
			return false;
		})
		if($(this).hasClass(li1) ) newarr[8]=$(this);
		$(this).hover(function(){ $(this).removeClass(li2).addClass(li1); }, function(){ if($(this).get(0)!=$(newarr[8]).get(0)) $(this).removeClass(li1).addClass(li2); });
	});
	if(newarr[1]>0){
		$list.f.click( function () { showList(1,newarr); }); 
		$list.g.click( function () { showList(0,newarr);});
	}
}
//keep the drag area
function limitArea(x,y){
	if(y>0)	y=0;
	if(y<-(zoom*viewportHeight)) y=-(zoom*viewportHeight);					
	if(x>-((zoom+1)*60)) x = -((zoom+1)*60);					
	if(x<(viewportWidth - (zoom+1)*440)) x = (viewportWidth - (zoom+1)*440);				
	return {x:x,y:y};		
}
//listener_BOF
function scaleMove(e) {
	if(zoom==2)	return;	
	if(e.target.tagName=="A") return;	
	var cursorOffX = e.clientX - $("#outerDiv").offsetLeft - stripPx($("#innerDiv").css("left"));
	var cursorOffY = e.clientY - $("#outerDiv").offsetTop - stripPx($("#innerDiv").css("top"));
	toggleZoom(cursorOffX,cursorOffY,"out");
}
function startMove(e) {
	if(zoom==0)	return;
	if(e.target.tagName=="DIV")	return;
    dragStartLeft = e.clientX;
    dragStartTop = e.clientY;				
    offTop = stripPx($("#innerDiv").css("top"));
    offLeft = stripPx($("#innerDiv").css("left"));
    dragging = true;
    return false;
}
function processMove(e) {
	if(zoom==0)	return;
	if(e.target.tagName=="DIV")	return;	
    var innerDiv = $("#innerDiv");
    if (dragging) {
		var moveX = offLeft + (e.clientX - dragStartLeft)
		var moveY = offTop + (e.clientY - dragStartTop)
		var offset = limitArea(moveX,moveY); 
		innerDiv.css({ left: offset.x, top: offset.y});		
    }
    //checkTiles();
	updatePointer();
}
// START:checktiles
function checkTiles() {
    // check which tiles should be visible in the inner div
    var visibleTiles = getVisibleTiles();
    // add each tile to the inner div, checking first to see
    // if it has already been added
    var innerDiv = document.getElementById("innerDiv");
    var visibleTilesMap = {};  
	if(!is1500) return; 
    for (i = 0; i < visibleTiles.length; i++) {
        var tileArray = visibleTiles[i];
        // START:imgZoomLevel
		var tileName = imageBaseName + "_" + tileArray[0] + "_" + tileArray[1];
        // END:imgZoomLevel
        visibleTilesMap[tileName] = true;
        var img = document.getElementById(tileName+"_"+zoom);
        if (!img) {
            img = document.createElement("img");
            img.src = imageBasePath + zoomPath[zoom]+"/"+imageDatePath + "/" + tileName + ".jpg?35103";
			img.style.position = "absolute";
			img.style.left = tileArray[0] + "px";
			img.style.top = tileArray[1] + "px";
			img.style.width = tileSize + 0.5 + "px";
            img.style.zIndex = 1;
            img.setAttribute("id", tileName+"_"+zoom);
			innerDiv.appendChild(img);
        }
    }
}
// END:checktiles
function getVisibleTiles() {
    var innerDiv = document.getElementById("innerDiv");
    var mapX = stripPx(innerDiv.style.left);
    var mapY = stripPx(innerDiv.style.top);
    var startX = Math.abs(Math.floor(mapX / tileSize)) - 1;
    var startY = Math.abs(Math.floor(mapY / tileSize)) - 1;
    var tilesX = Math.ceil(viewportWidth / tileSize) + 1;
    var tilesY = Math.ceil(viewportHeight / tileSize) + 1;
    var visibleTileArray = [];
    var counter = 0;
    for (x = startX; x < (tilesX + startX); x++) {
        for (y = startY; y < (tilesY + startY); y++) {						
			var x1 = x*tileSize;
			var y1 = y*tileSize;
			if(x1<0||y1<0)
				continue;
			switch(zoom){
			case 0:
			  if(x1>250||y1>250)
			  	continue;
			  break;    
			case 1:
			  if(x1>750||y1>750)
			  	continue;
			  break;
			case 2:
			  if(x1>1250||y1>1250)
			  	continue;
			  break;
			}
            visibleTileArray[counter++] = [x1, y1];
        }
    }
    return visibleTileArray;
}
function stopMove(e) {
	if(zoom==0)	return;						
    dragging = false;
	pDragging = false;
	checkTiles();
}
//==============move the pointer
function pStartMove(e) {
	if(zoom==0)	return;
    dragSL = e.clientX;
    dragST = e.clientY;
    var pointer = $("#pointer");
    oT = stripPx(pointer.css("top"));
    oL = stripPx(pointer.css("left"));
    pDragging = true;
    return false;
}
function pProcessMove(e) {
	if(zoom==0)	return;
    var pointer = $("#pointer");
    if (pDragging) {
		var moveX = oL + (e.clientX - dragSL);
		var moveY = oT + (e.clientY - dragST);	
	    if(moveX < 6) moveX = 6;
		if(moveY < 0) moveY = 0;
		if(moveY > 50 - pointer.height()) moveY = 50 - pointer.height();
		if(moveX > 44 - pointer.width()) moveX = 44 - pointer.width();
		pointer.css({ left: moveX, top: moveY});	
		//move the image
		var ox = -stripPx(pointer.css("left"))*(zoom+1)*10;				
		var oy = -stripPx(pointer.css("top"))*(zoom+1)*10;
		//fix the deviate
		var offset = limitArea(ox,oy);  
		ox = offset.x;
		oy = offset.y;			
		$("#innerDiv").css({width:500*(zoom+1),height:500*(zoom+1),left:ox,top:oy});		
    }
}
//============== end of move pointer of
function stripPx(value) {
    if (value == "") return 0;
    return parseFloat(value.substring(0, value.length - 2));
}
function setInnerDivSize(width, height, x, y) {
    var innerDiv = $("#innerDiv");
	innerDiv.css({ width: width, height: height});
	var moveX;
	var moveY;
	if(x&&y&&scaleMode == "out"){
			//fix the flow bug
			moveX = offLeft - x/zoom;
			if(zoom==1){
				moveX = offLeft - x/zoom - 60*(zoom+1);
			}
			moveY = offTop - y/zoom;						
	}
	
	if(scaleMode == "in"){
		offLeft = (zoom==0)?0:stripPx(innerDiv.css("left"));
		offTop = (zoom==0)?0:stripPx(innerDiv.css("top"));
		moveX = offLeft/(zoom+1);
		moveY = offTop/(zoom+1);	
	}
	
	if(scaleMode == "reset"){
		moveX = -60;
		moveY = 0;
		offLeft = offTop = 0;
	}
	
	var offset = limitArea(moveX,moveY);					  
	innerDiv.css({ left: offset.x, top: offset.y});	
	updatePointer();
}
function updatePointer(){
	var el = $("#pointer");
	var innerDiv = $("#innerDiv");
	var ox = -stripPx(innerDiv.css("left"))/[(zoom+1)*10];
	var oy = -stripPx(innerDiv.css("top"))/[(zoom+1)*10];
	(zoom==0)?el.css("cursor",""):el.css("cursor","move");
	el.css({width:38/(zoom+1),height:50/(zoom+1),left:ox,top:oy});	
}
function goZoom(type){
	toggleZoom("","",type);
}
// START:toggleZoom
function toggleZoom(clickX,clickY,type) {
	scaleMode = type;
	switch(type){
		case "out":
		zoom++;
		if(zoom>2){
			zoom = 2;
			return;
		}
		break;
		case "in":
		zoom--;
		if(zoom<0){
			zoom = 0;
			return;
		}
		break;
		case "reset":
		zoom = 0;
		break;
	}
	var innerDiv = document.getElementById("innerDiv");
	var posX;
	var posY;
	posX = (clickX)?clickX:(viewportWidth/2 - offLeft);
	posY = (clickY)?clickY:(viewportHeight/2 - offTop);
   //clear images
    var imgs = innerDiv.getElementsByTagName("img");   
	$("#zoomBg").width(zoomSizes[zoom][0]);
	$("#zoomBg").height(zoomSizes[zoom][1]);			
    setInnerDivSize(zoomSizes[zoom][0], zoomSizes[zoom][1], posX, posY);			
	//save the bg
	while (imgs.length > 1) innerDiv.removeChild(imgs[1]);
	//fix the image shake;
	(clickX)?checkTiles():setTimeout(checkTiles,500);			
}
// END:toggleZoom
function characterCount(field, count, maxchars) {
  var realchars = field.value.replace(/\t|\r|\n|\r\n/g,'');
  var excesschars = realchars.length - maxchars;
  if (excesschars > 0) {
		field.value = field.value.substring(0, excesschars);
		alert("Error:\n\n- You are only allowed to enter up to"+maxchars+" characters.");
	} else {
		count.value = maxchars - realchars.length;
	}
}
var BvGlobalCounter = function() {};
BvGlobalCounter.value = 0;
function bvGetMouseX(e) {
	var tempX;
	if (document.all) {
	tempX = e.clientX + document.body.scrollLeft;
	} else {
	tempX = e.pageX;
	}
	
	if (tempX < 0){
	tempX = 0;
	}
	return tempX;
}
function BvRatingBar(ratedItem){
	
	var _prepend = ratedItem;	
	var _BGWidth = 15;	
	var _BGHeight = 14;	
	var _specificity = 1;	
	var _maxRating = 5;	
	var _minRating = 1;	
	
	var _ratingType = "Stars";
	var _ratingTypeSingular = "Star";
	var _sparkleImage = baseURL+"includes/templates/lightinthebox/images/icon/sparkle.gif";
	var _rating;
	
	var _displayItemOverride = "score_title";
	var _inputItemOverride = "product_score";
	
	var _isMouseDown = false;
	
	var _hasValueSet = false;
	
	
	this.initializeValue = function (givenValue) {
		_hasValueSet = true;
		var ratingValue = (Math.ceil(givenValue/_specificity)* 100 *_specificity)/100;
		if(ratingValue > _maxRating){
		ratingValue = _maxRating;
		} else if(ratingValue < _minRating){
		ratingValue = _minRating;
		}
		_rating = ratingValue;
		var tableWidth = ratingValue * _BGWidth;
		idObj(ratedItem + "Filled").style.width = tableWidth + "px";
		//change the input value
		if(_inputItemOverride){
			var inputItemOverrideElement = idObj(_inputItemOverride);
			if( inputItemOverrideElement) {
			inputItemOverrideElement.value = _rating;
			}
		}
		//display the value of show text
		if(_displayItemOverride){
		if(idObj(_displayItemOverride)){
			if (_rating == 1){
			idObj(_displayItemOverride).innerHTML = _rating + " " + _ratingTypeSingular;
			} else {
			idObj(_displayItemOverride).innerHTML = _rating + " " + _ratingType;
			}
		}
		}
	};
	this.resizeTable = function (event, table) {
		var ratingBarElement = idObj(_prepend + 'RatingBar');
		var tableWidth = ratingBarElement.style.width;
		
		var scaleAmt = bvGetMouseX(event) - bvFindPosX(ratingBarElement);		
		var ratingValue = (Math.ceil(scaleAmt/_BGWidth/_specificity) * 100 * _specificity)/100;
		
		if(ratingValue > _maxRating){
		ratingValue = _maxRating;
		} else if(ratingValue < _minRating){
		ratingValue = _minRating;
		}
		
		tableWidth = ratingValue * _BGWidth;
		
		if(tableWidth < 1){
		tableWidth = 1;
		}
		
		idObj(table).style.width = tableWidth + "px";
	
		
		_rating = ratingValue;
	};
	
	
	this.setRating = function (event) {
		this.updateRating(event, _prepend + 'Filled');
		_hasValueSet = true;
	};
	
	this.updateRating = function (event, table, ignoreInput) {
		this.resizeTable(event, table);
		if(!ignoreInput){
		if(_inputItemOverride){
			var inputItemOverrideElement = idObj(_inputItemOverride);
			if(inputItemOverrideElement){
			inputItemOverrideElement.value = _rating;
			}
		}
		}
	
		if(_displayItemOverride){
		var displayItemOverrideElement = idObj(_displayItemOverride);
		if( displayItemOverrideElement){
		if (_rating == 1){
		displayItemOverrideElement.innerHTML = _rating + " " + _ratingTypeSingular;
		} else {
		displayItemOverrideElement.innerHTML = _rating + " " + _ratingType;
		}
		}
		}
	};
	
	
	this.startSlide = function () {
	
		_isMouseDown = true;
	};
	
	
	this.stopSlide = function () {
		if(_isMouseDown){
			var backgroundPath = _sparkleImage + '?i=' + BvGlobalCounter.value++;
			idObj(_prepend + 'Filled').style.background = "url(" + backgroundPath +")";
			_isMouseDown = false;
		}
	};
	
	
	this.doSlide = function (event) {
		if(_isMouseDown){
		this.updateRating(event, _prepend + "Filled");
		
		_hasValueSet = true;
		
		} else if(!_hasValueSet){
		this.updateRating(event, _prepend + "Hover", true);
		}
	};
	
	
	this.resetHover = function () {
		
		idObj(_prepend + "Hover").style.width = '1px';
	
		if(!_hasValueSet){
		if(_displayItemOverride){
		var displayItemOverrideElement = idObj(_displayItemOverride);
		if(displayItemOverrideElement){
		displayItemOverrideElement.innerHTML = "";
		}
		} 
		}
	}
}
function bvFindPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
	while (obj){
		curleft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function update_reload_check(){
	var rand = Math.random();
	document.getElementById('update_reload_check').innerHTML='<img src="vcode.php?rand='+rand+'" onclick="update_reload_check();" style="cursor:pointer;" align="middle">';
}



var scrolltotop={
	setting: {startline:100, scrollto:0, offsetx:50, offsety:50, scrollduration:500, fadeduration:[500, 500]},

	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto);
		if (typeof dest=="string" && $('#'+dest).length==1)
			dest=$('#'+dest).offset().top;
		else
			dest=this.setting.scrollto;
		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=$(window);
		var controly = $window.scrollTop() + $window.height() - this.$control.height() - this.setting.offsety;
		this.$control.css({left:this.setting.offsetx+'px', top:controly+'px'});
	},

	fixpos:function(){
		this.$control.css({left:this.setting.offsetx+'px', bottom:this.setting.offsety});
	},

	togglecontrol:function(e){
		var scrolltop=$(window).scrollTop();
		if (e!=null && e.type=='resize')
			if (this.resized)
				this.setting.offsetx = this.resized();
		if (!this.cssfixedsupport)
			this.keepfixed();
		if (this.cssfixedsupport && e!=null && e.type=='resize')
			this.fixpos();
		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false;
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().css('opacity', 1).fadeIn(this.setting.fadeduration[0]);
			this.state.isvisible=true;
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().fadeOut(this.setting.fadeduration[1]);
			this.state.isvisible=false;
		}
	},
	
	init:function(sets){
		this.setting = $.extend(this.setting, sets);
		$(document).ready(function($){
			var mainobj=scrolltotop;
			var iebrws=document.all;
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest; //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body');
			mainobj.$control=$('<div id="topcontrol"><img src="'+mainobj.setting.img_path+'" /></div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', left:mainobj.setting.offsetx, bottom:mainobj.setting.offsety, cursor:'pointer'})
				.hide()
				.attr({title:mainobj.setting.control_title})
				.click(function(){mainobj.scrollup(); return false;})
				.appendTo('body');
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}); //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol(null);
			mainobj.$control.click(function(){
				mainobj.scrollup();
				return false;
			});
			$(window).bind('scroll resize', function(e){
				mainobj.togglecontrol(e);
			});
		});
	}
};


