// JavaScript Document

/// input text clear value
var checkValue = {
	"focus": function(elm, val, type) {
		if (type != "search") {
			elm.className = "";
		} else {
			elm.style.color = "#9d9d9d";
		}
		elm.value = (elm.value == val) ? "" : elm.value;
		if (elm.value != val && type == 'number') elm.select();
		if (type == "pw") elm.type = "password";
	},
	"blur": function(elm, val, type) {
		if (elm.value == "") {
			if (type != "search") {
				if (type != 'number') elm.className = "validation";
			} else {
				elm.style.color = "#9d9d9d";
			}
			if (type == "pw") elm.type = "text";
			elm.value = (elm.value == "") ? val : elm.value;
		} else {
			elm.value = (elm.value == "") ? val : elm.value;
		}
	}
};

/// menu setting
var menu = {
	"step":null,
	"set":function(){
		var mIndex = jQuery("#menu > li").length;
		for (var i = 1; i <= mIndex; i++) {
			var bt = "#"+"m"+i;
			jQuery(bt+" > .sub").css("display","none");
			jQuery(bt+" > a:first").attr("id",i);
			/*
			jQuery(bt+" > a:first").click(function(){
				jQuery(this).css("background-position","left bottom");
				var num = jQuery(this).attr("id");
				var bt = "#"+"m"+num;
				if (menu.step > 0) menu.hideAll(menu.step);
				jQuery(bt+" > .sub").show("blind", { direction: "vertical" }, 400);
				if (menu.step != num) {
					menu.step = num;
				} else {
					menu.step = 0;
				}
			});
			*/
		}
		jQuery("#m"+menu.step+" > .sub").show("blind", { direction: "vertical" }, 400);
		jQuery("#m"+menu.step+" > a:first").css("background-position","left bottom");	
	},
	"hideAll":function(num){
		var bt = "#"+"m"+num;
		jQuery(bt+" > a:first").css("background-position","left top");
		jQuery(bt+" > .sub").hide("blind", { direction: "vertical" }, 400);
	}
}

/// slideshow
var slideshow = {
	"time":null,
	"num":1,
	"total":null,
	"objName":null,
	"set":function(){
		if (slideshow.total <= 1) return;
		setTimeout(function(){
			jQuery("#"+ slideshow.objName + "_" + slideshow.num).fadeOut("fast", function(){
				jQuery("#" + slideshow.objName + "_" + eval((slideshow.num >= slideshow.total) ? 1 : slideshow.num + 1)).fadeIn("slow", function(){
					if (slideshow.num >= slideshow.total) {
						slideshow.num = 1;
					} else {
						slideshow.num++;
					}
					slideshow.set();
				});
			});
		}, slideshow.time);
	}
}

/// news
var news = {
	"time":null,
	"step":0,
	"total":null,
	"set":function(){
		if (news.total <= 4) return;
		if (jQuery("#news > div > ul > li").length >= 5) {
			var posY = jQuery("#news > div > ul").height()/8;
			news.step++;
			setTimeout(function(){
				jQuery("#news > div > ul").animate({top:-posY*((news.step >= news.total/2+1)?0:news.step)}, 500, function(){
					if (news.step >= news.total/2+1) news.step = 0;
					news.set();
				});
			}, news.time);
		}
	}
}

/// print ticket
function printTicket(storeId, brwName, storeCat) {
	var url = String("store_ticket_popup.asp?sid="+storeId+"&category="+storeCat);
	var w = window.open(url,"_blank","toolbar=no,status=no,scrollbars=yes,width=682,height=500");
	//w.print();
}
