// JavaScript Document


var root = location.protocol + '//' + location.hostname;
var path = root + location.pathname;
	
/*
// Global Navigation Current
*/

function globalNavigation(){
	var dirArray = new Array("/xxx/", "/product/", "/ictag/", "/corporate/", "/recruit/");
	var current = function(event){
		return this.src.replace(/(\.gif|\.jpg|\.png)/,'_on'+"$1");
	}
	
	for(var i=0; i < dirArray.length; i++){
		if(path.match(dirArray[i])){
			$("#navi li:eq(" + i + ") img").removeClass("hover").attr("src", current);
		}
	}
	
}

/*
// Rollover Script on [ jQuery ]
// Rollover class = hover
// Rollover FileName = ***_on.jpg/gif/png
*/
function initRollovers() {
	var conf = { className : 'hover', postfix : '_on' };
	$('img.' + conf.className).each(function(){
		
		this.originalSrc = new Image;
		this.preloadSrc = new Image;

		this.originalSrc = this.src;
		this.preloadSrc = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1" + conf.postfix + "$2");
		
		$(this).hover(function(){
			this.src = this.preloadSrc;
		},function(){
			this.src = this.originalSrc;
			//this.src = this.src.replace(/^(.+)_on(\.[a-z]+)$/, "$1$2");
		});
		
	});
};

/*
// 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);
	});
}

/*
// Scroll To Anchor on [ jQuery ]
*/
function scrollToAnchors(){
	$('a[href^=#].scrollto').click(function() { 
		var href= this.hash;
		var $target = $(href == '#pageTop' ? 'body' : href);
		if($target.size()) {
			$.scrollTo($target, 800, {easing:'swing'});
		} 
		return false; 
	}); 
}

/*
// Add CSS Class to Link Type
// Link Type Class = file type
*/
function initLinkTypeIcons (){
	// PDF
	$("a[@href$=pdf]").addClass("pdf external");
	$("a[@href$=pdf] > img").parent().removeClass("pdf");
	// Excel
	$("a[@href$=xls]").addClass("xls external");
	$("a[@href$=xls] > img").parent().removeClass("xls");
	// Word
	$("a[@href$=doc]").addClass("doc external");
	$("a[@href$=doc] > img").parent().removeClass("doc");
	// ZIP
	$("a[@href$=zip]").addClass("zip external");
	$("a[@href$=zip] > img").parent().removeClass("zip");
	// External Link
	$('a[@href^="http"]').not('[@href^="http://www.guardner.co.jp/"]').not("[href^=#]").addClass("external");

}

function searchBox() {	
	$("#search .btn").each(function(){
		this.originalSrc = new Image;
		this.preloadSrc = new Image;
		this.originalSrc = this.src;
		this.preloadSrc = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
		$(this).hover(function(){
			this.src = this.preloadSrc;
		},function(){
			this.src = this.originalSrc;
		});
		
	});
	$("#search input[@type='text']").focus(function(){$(this).addClass("focus");}).blur(function(){$(this).removeClass("focus")});
}

function breadcrumbs(){
	$("#breadcrumbs .rounded").corners("3px");
}

function rightMenu(){
	$(".list ul li span").click(function(){
		$(this).next().addClass("selected");
		$(".list ul li ul:visible").not(".selected").slideUp().parent().removeClass("current");
		$(this).next().slideDown().parent().addClass("current");
		$(".list ul li ul:visible").removeClass("selected");
		return false;
	});
}

function interface() {
	$(globalNavigation);
	$(initLinkTypeIcons);
	$(initStripedTable);
	$(scrollToAnchors);
	$(initNewWindow);
	$(initRollovers);
}

function regulate() {
		
	$("table.col tr th:last-child").css("border-right","none");
	$("table.col tr td:first-child").css("border-left","none");
	
	$(".hide:visible").toggle();
	
}

function index(){
	$("#news div span").hover(function(){
		$(this).addClass("focus")},function(){$(this).removeClass("focus");
	});
	$("#pickup dl").hover(function(){
		$(this).addClass("focus")},function(){$(this).removeClass("focus");
	});
	$("#pickup dl:last").css("background-image","none");
}

$(document).ready( function(){
	$(interface);
	$(regulate);
})

