// JavaScript Document
// 

var root = location.protocol + '//' + location.hostname + '/honda';
	
/*
// Global Navigation Current
*/

function globalNavigation(){
	
	var dirArray = new Array("/product/", "/corporate_e/", "/eco_e/");
	var current = function(event){
		return this.src.replace(/(\.gif|\.jpg|\.png)/,'_on'+"$1");
	}
	
	for(var i=0; i < dirArray.length; i++){
		if(location.pathname.match(dirArray[i])){
			$("#globalNavi li:eq(" + i + ") img").removeClass("hover").attr("src", current);
		}
	}
	
}


/*
	Rollover Script on [ jQuery ]
	Rollover class = over
	Rollover FileName = ***_on.jpg/gif/png
*/
function initRollovers() {
	var conf = {
		className : 'hover',
		postfix : '_on'
	};
	$('img.'+conf.className).hover(function(){
		this.originalSrc = this.src;
		this.src = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, conf.postfix + "$1");
	},function(){
		this.src = this.originalSrc;
	});
};



/*
	Striped Table on [ jQuery ]
	Rollover class = odd,even
*/
function initStripedTable() {
	var conf = {	
		className : "stripedTable",
		childElement : "tr",
		oddClassName : "odd",
		evenClassName : "even"
	};
	$('.'+conf.className+' '+conf.childElement+':odd').addClass(conf.evenClassName);
	$('.'+conf.className+' '+conf.childElement+':even').addClass(conf.oddClassName);
};



/*
	Open New Window on [ jQuery ]
	Rollover class = popup
*/
function initNewWindow() {
	
	var popupEvent = function(event) {
		if( this.rel ) {
			window.open(this.href, 'popup', this.rel).focus();
		} else {
			window.open(this.href, '_blank').focus();
		}
		event.preventDefault();
		event.stopPropagation();
	}
	
	$("a.popup, a.external").each(function(i) {
		$(this).click(popupEvent);
		$(this).keypress(popupEvent);
	});
	
}

/*
	Add CSS Class to Link Type
	Link Type Class = file type
*/
function initLinkTypeIcons (){

	$("a[@href$=pdf]").addClass("pdf external");
	$("a[@href$=pdf] > img").parent().removeClass("pdf");

	$("a[@href$=xls]").addClass("xls external");
	$("a[@href$=xls] > img").parent().removeClass("xls");

	$("a[@href$=zip]").addClass("zip external");
	$("a[@href$=zip] > img").parent().removeClass("zip");
	
	//$("a:not([@href*=http://www.honda-connectors.co.jp])").not("[href^=#]").addClass("external").attr({ target: "_blank" });
	$('a[@href^="http"]').not('[@href^="http://www.honda-connectors.co.jp"]').not("[href^=#]").addClass("external");

}

/*
	Styleswitch : stylesheet switcher built on [ jQuery ]
	http://ideas.nty3.com/jquery-styleswitcher.html
	Rollover class = styleSwitch
*/

$(document).ready(function() {
	$('.styleSwitch').click(function(){
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);
});

function switchStylestyle(styleName){
	$('link[@rel*=style][@title]').each(function(i){
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style', styleName, 365);
}
/* cookie functions http://www.quirksmode.org/js/cookies.html */
function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}
/* cookie functions */




$(document).ready( function(){
	$(globalNavigation);
	$(initLinkTypeIcons);
	$(initStripedTable);
	$(initNewWindow);
	$(initRollovers);
})



