/* --------------------------------
file name   : global.js
last update : May 18, 2010
-------------------------------- */

$(document).ready(function(){ 
	userAgent();
	smoothScroll();
	rolloverImage();
	setTarget();
}); 

function userAgent() {
	var os, ua = navigator.userAgent;
	if (ua.match(/Mac|PPC/)) {
		os = "mac"
	} else if (ua.match(/Win(dows )?NT 6\.0/)) {
		if(!document.all){
			os = "win";
			} else {
			os = "winie";
		} 
	} else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) {
		os = "legacy";
	} else {
		os = "win";
	}
	$('body').addClass(os);
}
function smoothScroll() {
	$('a[href^=#]').click(function() { 
		var href= this.hash; 
		var $target = $(href == '#_top' ? 'body' : href); 
		if($target.size()) { 
			var top = $target.offset().top; 
			$($.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 800, 'swing'); 
		} 
		return false; 
	}); 
}
function rolloverImage() {
	var image_cache = new Object();
	$("img.rollover,.rollover a img,.global-navi img,.categories table img").not("[src*='-ovr.'],[src*='-cur.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_ovr = this.src.substr(0, dot) + '-ovr' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ovr;
		$(this).hover(
			function() { this.src = imgsrc_ovr; },
			function() { this.src = imgsrc; });
	});
}

function setTarget() {
	$("a[href*='pdf']").each(function(i) {
		$(this).attr('target','_blank');
	});
}
