// JavaScript Document

var root = location.protocol + '//' + location.hostname;
var path = root + location.pathname;

/*
	Rollover Script on [ jQuery ]
	Rollover class = over
	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;
		});
	});
};

/*
	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, a.pdf").each(function(i) {
		$(this).click(popupEvent);
		$(this).keypress(popupEvent);
	});
}

/*
// 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:not([href~="http://www.xxx.com"])').not("[href^=#]").addClass("external").attr({ target: "_blank" });
}

/*
// Regulation on [ jQuery ]
*/
function regulate(){
	// Default
	$("h2, h3, h4, h5, h6").each(function(i){
		if($(this).text()) $(this).wrapInner(document.createElement("span"));
	});
	$("table.col tr th:last-child").css("border-right", "none");
	$("table.col tr td:first-child").css("border-left", "none");
	// Add CSS [ .even .odd ]
	$('.stripe').each(function(i){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('table').each(function(i){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	$("input[type=text], textarea").focus(function(){$(this).addClass("focus");}).blur(function(){$(this).removeClass("focus")});
}

/*
// Page Loaded on [ jQuery ]
*/
$(document).ready(function(){
	$(initStripedTable);
	$(initRollovers);
	$(initNewWindow);
	$(regulate);
})


