$(function(){

//	$("#nav ul li img").scgrph_swapper({regexp:"name_NUM_o"});
	$("#nav ul li img,a.ro img").scgrph_swapper();
	
	if(jQuery.fn.pngfix)
	$("img[@src$=png]").pngfix();
	
	$("ul.service").find("li:last").css({paddingBottom:0}).end().
		filter(".tiny:last").css({borderBottom:"solid 2px white"}).end().
		filter(":not(.tiny):last").css({borderBottom:"solid 2px white"}).end().
		find("img").each(function(){new Image().src=this.src.replace(/(.+_)([0-9]+.+)$/,"$1o_$2");}).end().
		find("a").hover(function(){
			var img = $(this).addClass("cur").find("img").get(0);
			if(img) img.src=img.src.replace(/(.+_)([0-9]+.+)$/,"$1o_$2");
			},
			function(){
				var img = $(this).removeClass("cur").find("img").get(0);
				if(img) img.src=img.src.replace(/(.+_)o_([0-9]+.+)$/,"$1$2");
		});
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		$("ul.service").find("li:first a").css({paddingBottom:1});
		$("ul.service:first").find("li:eq(1) a").css({paddingBottom:2});
//		$("#commercial-event ul.photos a img").css("margin",0).css({marginBottom:"8px"}).
//			parent().parent().css({marginRight:"15px",marginTop:"-4px"});
		$("#commercial-event ul.photos a img").width(166).height(124).css("margin-top","0");
		
	}
	else{
		if(!jQuery.browser.safari) $("#commercial-event ul.photos a img").width(166).height(124).css("margin-top","0");
	}
		
	
	
	//var img_sel = "#spirits img,#spirits_index img";
	var img_sel = "#spirits img";
	/*
	$("#spirits_index li a").each(function(){
		if(jQuery.scgrph_absolute_path(this.href) == location.href){
			$(this).css({fontWeight:"bold",color:"#A11000"});
			$(this).attr("href").match(/([0-9]+)\.html/);
			var n = RegExp.$1/1;
			var img = $(img_sel).get(0);
			$(img).attr({src:img.src.replace(/[0-9]+\./,n+".")});
		}
	});
*/
	if($(img_sel).length>0){
		var org_src = $(img_sel).attr("src");
//		$("#spirits a,#spirits_index a").hover(function(){
		$("#spirits a").hover(function(){
				$(this).attr("href").match(/([0-9]+)\.html/);
				var n = RegExp.$1/1;
				var img = $(img_sel).get(0);
				$(img).attr({src:img.src.replace(/[0-9]+\./,n+".")});
			},
			function(){$(img_sel).attr({src:org_src});}).
		each(function(){$(this).attr("href").match(/([0-9]+)\.html/);var n = RegExp.$1/1;new Image().src=org_src.replace(/[0-9]+\./,n+".");});
	}
	if(location.href.indexOf("cgi-bin")>-1) $("#nav ul li img:eq(7)").scgrph_swapper({force:"active"});
	if(location.href.indexOf("mt-comments")>-1){
		$("body").css("background","none");
	}
	
	
	if(location.href.indexOf("/result/commercial-tool.html")>-1 || location.href.indexOf("/result/publicity-tool.html")>-1){
		$.scgrph_import("/js/ui.shadow.js","/js/ui.dimensions.js",function(){$(".shadow img").shadow({ color: "#666"});});
		
		/*
		var h = document.getElementsByTagName("head")[0];
		var s = document.createElement("script");
		var s2 = document.createElement("script");
		s.src = "/js/ui.shadow.js";
		h.appendChild(s);
		s2.src = "/js/ui.dimensions.js";
		h.appendChild(s2);
		
		var tid = setInterval(function(){
			if(jQuery.fn.shadow && jQuery.dimensions){
				clearInterval(tid);
				$("div>img").shadow({ color: "#666"})//.shadowEnable();
			}
		},100);
		*/
	}
	
	if(location.href.indexOf("/result/commercial-event.html")>-1){
		//$.scgrph_import("/js/ui.shadow.js","/js/ui.dimensions.js",function(){alert($.fn.shadow)});
	};


	if(!jQuery.browser.safari){
		$("#news").load("/_news.html");
//		$.get("/_news.html",null,function(data){setTimeout(function(){$("#news").html(data);},100);});
		}
	else{
		$.get("/_news.html",null,function(data){var esc=escape(data);if(esc.indexOf("%u")<0&&esc.indexOf("%")>-1){data = decodeURIComponent(esc);}$("#news").html(data);});
		$("#commercial-event ul.photos a img").width(166).height(124).css("margin-top","2px");

	}

	if($("a.popup").length>0)
	$("a.popup").each(function(){if(!$(this).attr("rel")) $(this).attr("rel","h:460");}).openWin();
	
	$("#popup a").click(function(){
		try{
			var a = window.opener.location.href;
			
			window.close();
			return false;
		}
		catch(e){
			
		}

	});
	
	if(location.href.indexOf("contact") > -1 || location.href.indexOf("cgi-bin") > -1){
		$("input[name=tel],input[name=address],input[name=email],input[name=office],input[name=officename],textarea").css("width","340px");
		$("input[name=name]").css("width","200px");
		$("input[name=zip]").css("width","150px");
		
	}
	
	$("#spirits_index a").each(function(){
		if(this.href == location.href){
			var html = $(this).html();
			$(this).parent().html('<span style="color:gray;text-decoration:underline;">'+html+'</span>');
			
		}
	});
	
	

});

