// set hor. menu
(function($) {
	$.fn.hm=function() {
		var $obj=$(this).find("div:last"); var $li=$obj.find("> ul > li");
		return this.each(function() {
			$li.each(function() {
				if ($(this).find("> ul").is("ul")) {
					if ($(this).find("> ul").width()<=215) { $(this).find("> ul").width(215); }
					else { $(this).find("> ul").width($(this).find("> ul").width()); }
				}
			});
			$li.bind("mouseenter",function() {
				if ($(this).find("> ul").is("ul")) {
					$(this).addClass("activ");
					$(this).find("> ul").stop().css({display:"block",opacity:1}).fadeIn(200);
				}
			});
			$li.bind("mouseleave",function() {
				if ($(this).find("> ul").is("ul")) {
					$(this).find("> ul").stop().fadeOut(100,function() { $(this).parent().removeClass("activ"); });
				}
			});
		});
	};
})(jQuery);

// show order form
(function($) {
	$.fn.order=function() {
		var $openForm=$(this).find("> a"); var $obj=$("#order").find("form"); var num=2;
		return this.each(function() {
			$openForm.hover(
				function() { $(this).parent().addClass("hover"); },
				function() { $(this).parent().removeClass("hover"); }
			);
			// show form
			$openForm.click(function() {
				var bodyWidth=$("body").width();
				var pos=bodyWidth>1000?((bodyWidth-1000)/2)+(1000-$("#order").width()):1000-$("#order").width();
				$("#order").css({left:pos});
				if ($("#order").css("display")=="none") {
					$("#order").css({display:"block"});
					if (ie6) IEPNGFix.update();
				}
			});
			// hide form
			$("#order").find(".close > a").click(function() {
				$("#order").css({display:"none"});
			});
			// add input file
			$obj.find(".add").click(addInput);
			function addInput() {
				var $inp=$obj.find("input:file"); name=$inp.attr("name");
				var _inp=$('<input type="file" name="'+name+num+'" size="1">');
				var _close=$('<div class="close-file">&nbsp;</div>')
				$("#block-file .inp .file:last").after(_inp); _inp.filestyle(); num++;
				$("#block-file .inp .file:last").find(".file-button").after(_close);
				_close.click(function() { $(this).parent().remove(); if (ie6) IEPNGFix.update(); });
				if (ie6) IEPNGFix.update();
			}
		});
	};
})(jQuery);

// style table
(function($) {
	$.fn.tabprint=function() {
		var $obj=$(this);
		return this.each(function(i) {
			$($obj[i]).wrap('<div class="tab-print-style"></div>');
			$($obj[i]).after('<div class="tab-tit"></div><div class="ttr"></div><div class="tbr"></div><div class="tbl"></div>');
			$(".tab-print-style").find(".tbr,.tbl").css({top:$($obj[i]).height()-10});
			_txt=$($obj[i]).find(".format").html(); $($obj[i]).find(".format").html("");
			$(".tab-print-style").find(".tab-tit").html(_txt);
			_span=$(".tab-print-style").find(".tab-tit > span"); _span.addClass("tab-f").wrap("<span></span>");
			_span.before('<span class="l"></span>').after('<span class="r"></span>');
			if ($.browser.mozilla) {
				$(".tab-print-style").find(".tab-tit").css({left:-1,top:-1});
				$(".tab-print-style").find(".tbl").css({left:-1});
				$(".tab-print-style").find(".ttr").css({top:-1});
			}
		});
	};
})(jQuery);

// set height gallery
(function($) {
	$.fn.list=function() {
		var $obj=$(this).find(".w");
		return this.each(function() {
			var i=0;
			while(i<$obj.size()) {
				_o=$obj.slice(i,i+3); $(_o[1]).css({paddingLeft:125,paddingRight:125});
				h=0; for (j=0;j<_o.length;j++) { h=h<$(_o[j]).height()?$(_o[j]).height():h; }
				for (j=0;j<_o.length;j++) { $(_o[j]).height(h); }
				i+=3;
			}
	});
	};
})(jQuery);

// main page
(function($) {
	$.fn.main=function() {
		var $obj=$(this).find(".main-pic"); var $lobj=$(this).find(".main-link");
		var $aobj=$(this).find("a.activ"); var activy; var tID;

		function showActiv() {
			clearTimeout(tID);
			activ=$aobj.attr("id").replace("a",""); py=$($obj[activ-1]).attr("py");
			pos="0px "+py+"px";
			$($obj[activ-1]).css({"background-position":pos,"z-index":50});
			$($obj[activ-1]).find(".gray").hide();
		}

		return this.each(function() {
			$lobj.each(function() {
				w=$(this).width(); h=$(this).height();
				$('<img src="/i/p.gif" height="'+h+'" width="'+w+'" class="bl">').appendTo($(this));
			});
			$lobj.hover(
				function() {
					clearTimeout(tID);
					if ($aobj!=$(this)) {
						id=$aobj.attr("id").replace("a",""); px=$($obj[id-1]).width()*-1; py=$($obj[id-1]).attr("py");
						pos=px+"px "+py+"px";
						$($obj[id-1]).css({"background-position":pos,"z-index":100});
						$($obj[id-1]).find(".gray").show();
					}
					id=$(this).attr("id").replace("a",""); py=$($obj[id-1]).attr("py");
					pos="0px "+py+"px";
					$($obj[id-1]).css({"background-position":pos,"z-index":50});
					$($obj[id-1]).find(".gray").hide();
				},
				function() {
					id=$(this).attr("id").replace("a","");
					px=$($obj[id-1]).width()*-1; py=$($obj[id-1]).attr("py");
					pos=px+"px "+py+"px";
					$($obj[id-1]).css({"background-position":pos,"z-index":100});
					$($obj[id-1]).find(".gray").show();
					if ($aobj) { tID=setTimeout(showActiv,500); }
				}
			);
			$aobj.each(function() {
				activ=$(this).attr("id").replace("a",""); py=$($obj[activ-1]).attr("py");
				$($obj[activ-1]).css({"background-position":"0px "+py+"px","z-index":50});
				$($obj[activ-1]).find(".gray").hide();
			});
		});
	};
})(jQuery)

$j(function() {
	$j("#no-flash").main();
	$j("#online").order(); // show order form
	$j("input:file").filestyle(); // style input file
	$j(".tab-print").tabprint(); // style table
	$j("#list-work").list();
});
$j(window).resize(function() {
	var bodyWidth=$j("body").width();
	var pos=bodyWidth>1000?((bodyWidth-1000)/2)+(1000-$j("#order").width()):1000-$j("#order").width();
	$j("#order").animate({left:pos},500,function() { if (ie6) IEPNGFix.update(); });
});