/*
 * navigation by jquery v1.3.2
 * $Date: 2009-10-09
 * 
 */
var path = location.hostname + "/sg/asience/share/css/clobber.css";

document.writeln('<link rel="stylesheet" type="text/css" href="' + path + '" media="all">');

$(document).ready(function(){

	var conf = { nav01:'product', nav02:'research', nav03:'ad', nav04:'special' };
	var imgPostfix = '_o';

	//---------- main -----------------------------------------------------------------------
	
	init();
	//STAY
	for (var key in conf){
		//alert(conf[key]);
		if( $("body").hasClass(conf[key])){
			var imgElm = $("#"+key+" img.category").addClass("stayImg").get(0);
			var dot = imgElm.src.lastIndexOf('.');
			if(! imgElm.src.match(imgPostfix) ){
				imgElm.src = imgElm.src.substr(0, dot) + imgPostfix + imgElm.src.substr(dot, 4);
			}
		}
	}
	
	//ROLLOVER
	$("#navigationFrame a > img.over").each(function(){
		var imgElm2 = $(this).get(0);
		var dot2 = imgElm2.src.lastIndexOf('.');
		
		$(this).hover(function(){
			imgElm2.src = imgElm2.src.substr(0, dot2) + imgPostfix + imgElm2.src.substr(dot2, 4);
		},function(){
			imgElm2.src = imgElm2.src.replace(imgPostfix, '');
		});
	});
	
	
	$("#navigationFrame > ul > li").hover(function(){
		menuFunc( $(this).get(0).id, "Down");
	},function(){
		menuFunc( $(this).get(0).id, "Up");
	});
	
	//---------- function -------------------------------------------------------------------
	function init(){
		for (var key in conf){
    		$("#navigationFrame ul li ul#"+key+"List").each(function(){
    			var ul = $(this);
    			ul.data('h', ul.outerHeight());
    		}).css({ opacity: 0.7, display : 'none' }).css("height","0px");
    	}
	}
	
	function menuFunc(num,type){
		var img = $("#navigationFrame ul li#"+num+" img.category").get(0);
		//alert(img.className);
		var dot3 = img.src.lastIndexOf('.');
		var elm = $("#navigationFrame ul li#"+num+" ul#"+num+"List");
		
		if(type=="Down"){
			if(elm.is(":hidden")){elm.stop().animate({opacity: 1,height:elm.data('h')+'px'},{queue:false,duration:500} );}
			if(elm.is(":animated")){elm.stop().animate({opacity: 1,height:elm.data('h')+'px'},{queue:false,duration:500} );}	
			if($(img).hasClass("stayImg")){ return true; }
			if(!img.src.match(imgPostfix)){img.src = img.src.substr(0, dot3) + imgPostfix + img.src.substr(dot3, 4);}
		}else{
			if(!elm.is(":hidden")){elm.stop().animate({opacity: 0.7,height:"0px"},{queue:false,duration:500});}
			if(elm.is(":animated")){elm.stop().animate({opacity: 0.7,height:"0px"},{queue:false,duration:500});}
			if($(img).hasClass("stayImg")){ return true; }
			img.src = img.src.replace(imgPostfix, '');

		}
	}
	


});
