/* DEV: sakesan@v6hp.in.th */
var uniqid=function(){var newDate = new Date;return "uid"+newDate.getTime();};
jQuery.equalHeight = function(selector){jQuery(document).ready(function(){var MaxHeight=0;jQuery(selector).each(function(){if(jQuery(this).height()>MaxHeight) MaxHeight=jQuery(this).height();});jQuery(selector).css({"height":MaxHeight});});};
var jQuertpopup=function(){jQuery("a[rel^=popup]").click(function(e){e.preventDefault();var option = jQuery(this).attr("rel");var features="";var op;if((op=option.match(/^(popup) ([0-9]*) ([0-9]*)$/i))){features =  "height="+op[3]+",width="+op[2]+",resizable=0,scrollbars=0,location=0,status=0,menubar=0";newwindow=window.open(this.href, 'newwin'+(Math.floor(Math.random()*100)), features);}else if((op=option.match(/^(popupimg) ([0-9]*) ([0-9]*)$/i))){features =  "height="+op[3]+",width="+op[2]+",resizable=0,scrollbars=0,location=0,status=0,menubar=0";newwindow=window.open('', 'newwin'+(Math.floor(Math.random()*100)), features);var title=jQuery(this).attr("title");var imgsrc=jQuery(this).attr("href");var content="<img src='"+imgsrc+"' alt='"+title+"'>";newwindow.document.writeln('<html><head><title>'+title+'</title></head>'+'<body bgcolor="black" style="margin: 0px;padding: 0px;text-align: center;" onLoad="self.focus();">'+content+'</body></html>');}else if((op=option.match(/^(popup)/i))){newwindow=window.open(this.href, 'newwin'+(Math.floor(Math.random()*100)));}else{}return false;});};

jQuery("#topnav a").hover(function(){
	jQuery(this).parent().addClass("hover");
}, function(){
	jQuery(this).parent().removeClass("hover");
});

var activeLookbook=function(){
	var w=jQuery(window).width();
	var h=jQuery(window).height();
	var mid=h/2;
	if(w>1200){
		jQuery("#content,#popupview").addClass("w1280");
	}else if(w>1100){
		jQuery("#content,#popupview").addClass("w1024p");
	}else{
		jQuery("#content,#popupview").addClass("w1024");
	}
};



/* bottom most */
var screenWidth = jQuery(window).width();
if(screenWidth > 1600){jQuery("body").addClass("w1600");}else if(screenWidth > 1200){jQuery("body").addClass("w1200");}else{jQuery("body").addClass("w1000");}
// jQuery(document).bind("contextmenu",function(e){return false;});
var currentSlider = 0;
var slideTotal = 0;
var slideNow = function(selector, to){
	currentSlider=currentSlider+to;
	if(currentSlider < 1){currentSlider=0;jQuery(selector).find(".leftarrow").css("visibility", "hidden");}else{jQuery(selector).find(".leftarrow").css("visibility", "visible");}
	if(currentSlider > slideTotal-4){currentSlider=slideTotal-3;jQuery(selector).find(".rightarrow").css("visibility", "hidden");}else{jQuery(selector).find(".rightarrow").css("visibility", "visible");}
	jQuery(selector).find("ul").animate({"left":-230*currentSlider}, 300);
};
var sliderInit = function(selector){
	slideTotal=parseInt(jQuery(selector).find("li").length);
	if(slideTotal>1){
		jQuery(selector).find(".leftarrow").click(function(e){
			e.preventDefault();
			slideNow(selector, -1);
		});
		jQuery(selector).find(".rightarrow").click(function(e){
			e.preventDefault();
			slideNow(selector, 1);
		});
	}else{
		jQuery(selector).find(".leftarrow").hide();
		jQuery(selector).find(".rightarrow").hide();
	}
	if(slideTotal==3){jQuery(selector).find(".rightarrow").hide();}
	jQuery(selector).find("li").hover(function(){
		jQuery(this).stop().animate({"opacity":1}, 500);
	},function(){
		jQuery(this).stop().animate({"opacity":0.6}, 500);
	});
	jQuery(selector).find("li").css("opacity", 0.6);
};
var scrollHeight=0;
var scrollwrapHeight=0;
var currentScroll = 0;
var scrollNow = function(selector, to){
	var scroll = true;
	var tmp=currentScroll+to;
	if(to<0 && tmp < 0){tmp=0;scroll=false;}
	if(to>0 && tmp > scrollHeight-scrollwrapHeight){scroll=false}
	if(scroll){
		currentScroll=tmp
		jQuery(selector).find(".contentDetail").attr("rel", currentScroll);
		jQuery(selector).find(".contentDetail").animate({"top": -1*currentScroll}, 550);
	}
};
var scrollInit = function(selector){
	scrollwrapHeight = jQuery(selector).height();
	scrollHeight=jQuery(selector).find(".contentDetail").height();
	jQuery(selector).find(".uparrow").click(function(e){
		e.preventDefault();
		scrollNow(selector, -1*scrollwrapHeight);
	});
	jQuery(selector).find(".downarrow").click(function(e){
		e.preventDefault();
		scrollNow(selector, scrollwrapHeight);
	});	
};
var menuConnection = false;
var scrollMenuCurrent = 0;
var scrollMenuTotal=0;
var menuConnectionFlag = false;
jQuery("#topnav td.submenu a").click(function(e){
	e.preventDefault();
	if(menuConnectionFlag){
		menuConnection.abort();
	}
	menuConnectionFlag=true;
	var loadurl=jQuery(this).attr("href");
	menuConnection=jQuery.ajax({
		url: loadurl+"/menu",
		success: function(data){
			jQuery("#subcontent").fadeOut("fast").fadeIn("slow").find("#displayarea").html(data);
			jQuery("#closemenu").click(function(){
				jQuery("#subcontent").fadeOut("fast");
			});
			
			scrollMenuTotal=jQuery("#subcontent ul").length;
			scrollMenuCurrent = 0;
			if(scrollMenuTotal < 2){jQuery("#subcontent #scrollRight").css("visibility", "hidden");}
			jQuery("#subcontent .scrollWrap").animate({"scrollLeft": 0}, 300);
			jQuery("#subcontent #scrollLeft").click(function(e){
				e.preventDefault();
				scrollMenuNow(-1);
			});
			jQuery("#subcontent #scrollRight").click(function(e){
				e.preventDefault();
				scrollMenuNow(1);
			});
		}
	});

});

jQuery("#contact-usNav a").click(function(e){
	e.preventDefault();
	if(menuConnectionFlag){
		menuConnection.abort();
	}
	menuConnectionFlag=true;
	var loadurl=jQuery(this).attr("href");
	menuConnection=jQuery.ajax({
		url: loadurl+"/ajax",
		success: function(data){
			jQuery("#subcontent").fadeOut("fast").fadeIn("slow").find("#displayarea").html(data);
			jQuery("#closecontact").click(function(){
				jQuery("#subcontent").fadeOut("fast");
			});
			jQuery("#contactusform input[name=email]").attr("id", "iemail");
			jQuery("#contactusform input[name=from]").attr("id", "ifrom");
			jQuery("#contactusform textarea[name=message]").attr("id", "imessage");
			jQuery("#contactusform #iemail").click(function(){
				if(jQuery(this).val()=="email"){jQuery(this).val("");}
			});
			jQuery("#contactusform #ifrom").click(function(){
				if(jQuery(this).val()=="from"){jQuery(this).val("");}
			});
			jQuery("#contactusform #imessage").click(function(){
				if(jQuery(this).val()=="message"){jQuery(this).val("");}
			});
			jQuery("#contactusform").submit(function(){
				var pass=true;
				if(jQuery("#contactusform #iemail").val()=="" || jQuery("#contactusform #iemail").val()=="email"){
					pass=false;
				}
				if(jQuery("#contactusform #ifrom").val()=="" || jQuery("#contactusform #ifrom").val()=="from"){
					pass=false;
				}
				if(jQuery("#contactusform #imessage").val()=="" || jQuery("#contactusform #imessage").val()=="message"){
					pass=false;
				}
				if(pass){
					var data=jQuery(this).serialize();
					jQuery.post(jQuery('#contactusform').attr("action")+"/ajax/send",data,function(returned){
						if(returned=='OK'){
							alert("Thank You For Your Interest In Our Products.\n"+"We will contact you as soon as possible");
							jQuery("#subcontent").fadeOut();
						}else{
							alert('Please check name, email or message');
						}
					});
				}
				return false;
			});
		}
	});
});




var scrollMenuNow = function(to){
	scrollMenuCurrent=scrollMenuCurrent+to;
	if(scrollMenuCurrent < 1){scrollMenuCurrent=0;jQuery("#subcontent #scrollLeft").css("visibility", "hidden");}else{jQuery("#subcontent #scrollLeft").css("visibility", "visible");}
	if(scrollMenuCurrent >= scrollMenuTotal-1){scrollMenuCurrent=scrollMenuTotal-1;jQuery("#subcontent #scrollRight").css("visibility", "hidden");}else{jQuery("#subcontent #scrollRight").css("visibility", "visible");}
	jQuery("#subcontent .scrollWrap").animate({"scrollLeft": 664*scrollMenuCurrent}, 300);
};

/* batch script from inline script -- must be bottom most : ) */
if(SCRIPTS.length > 0){for(var i=0;i<SCRIPTS.length;i++){SCRIPTS[i]();}}
