/*
	init.js
	require jQuery
*/

var $j = jQuery;
//var $j = jQuery.noConflict();

// table color stripe
$j(function(){
	$("table.list-data tr:even").addClass("even");
});

// flat-heights
$j(function(){
	$("#directory-nav > div.nav-column, div#top-nav > div.tnav-column > div").flatHeights();
})

// flat-heights 2-columns
$j(function(){
	/* divide 2 div */
	var sets = [], temp = [];
	$('div.columns-2 > div').each(function(i) {
		temp.push(this);
		if (i % 2 == 1) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);

	/* height */
	$.each(sets, function() {
		$(this).flatHeights();
	});
});
// flat-heights 3-columns
$j(function(){
	/* divide 3 div */
	var sets = [], temp = [];
	$('div.columns-3 > div').each(function(i) {
		temp.push(this);
		if (i % 3 == 2) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);

	/* height */
	$.each(sets, function() {
		$(this).flatHeights();
	});
});

//global-network map
$j(function(){
	var pdataID;
	var anchor;
	$j("#point-list > li > a").click(function(){
		//console.log(this);
		if(anchor == this) return false;
		
		var dataID = "#data" + $j(this).attr("href").slice(-1);
		$j(dataID).show();
		var pointimg = $j(this).find("img");
		$j(pointimg).attr("src",$j(pointimg).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		if(anchor) {
			var pointprevimg = $j(anchor).find("img");
			$j(pointprevimg).attr("src",$j(pointprevimg).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
		}
		if(pdataID) $j(pdataID).hide();
		pdataID = dataID;
		anchor = this;
		return false;
	});
	$j("#point1 > a").click();
});

// navigation active
$j(function(){
	var path = location.pathname.split("/")[1];
	var path2 = (location.pathname.split("/")[2] != "") ? location.pathname.split("/")[2] : "index.html";
	var filename = (location.pathname.match(".+/(.+?)$")) ? location.pathname.match(".+/(.+?)$")[1] : "/";
	//console.log("1stDir:"+path+", 2ndDir:"+path2+", filename:"+filename);
	if(path.match("index")) {
		path = "";
	}
	/*$j("div#global-nav ul li a").each(function(){
		var link1 = $j(this).attr("href").split("/");
		var directory1;
		if(link1[0] == "http:" || link1[0] == "https:") {
			directory1 = link1[3];
		}else {
			directory1 = link1[1];
		}
		if(path == directory1) {
			$j(this).find("img").attr("src",$j(this).find("img").attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		}else {
			$j(this).find("img").addClass("rollover");
		}
		
	});*/
	$j("#local-nav > ul > li > a").each(function(){
		var link2 = ($j(this).attr("href").match(".+/(.+?)$")) ? $j(this).attr("href").match(".+/(.+?)$")[1] : "/";
		if(path == "global-network") {
			path2 = "/";
		}
		//console.log("link2 = "+link2+", path2 = "+path2);
		if(path == "corporate" || path == "global-network") {
			if(link2 == path2) {
				$j(this).parent().addClass("current");
			}
		}
	});
	$j("#local-nav > ul > li > ul.local-list > li > a").each(function(){
		var link3 = ($j(this).attr("href").match(".+/(.+?)$")) ? $j(this).attr("href").match(".+/(.+?)$")[1] : "/";
		if(filename == "400ml_explanatory_note.html" || filename == "50ml_explanatory_note.html") {
			filename = "handapri.html";
		}
		//console.log("link3 = "+link3);
		if(filename == link3) {
			$j(this).parent().addClass("current");
		}
		
	});
})

// rollover
$j(function(){
	// rollover class
	$j("img.rollover").mouseover(function(){
		$j(this).attr("src",$j(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
	}).mouseout(function(){
		$j(this).attr("src",$j(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function(){
		$j("<img>").attr("src",$j(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
	});
})



