jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};

$(function () {

	// GlobalNavi
	var gNavObj = '#' + $('body').attr('id') + 'Nav';
	if ($('#globalNavi li').filter(gNavObj).size() == 1) {
		$gNavObj = $(gNavObj).find('a:first img');
		var imgsrc = $gNavObj.attr('src');
		var imgsrc_on = imgsrc.replace('_of.', '_on.');
		$gNavObj.attr('src', imgsrc_on);
	}

	// Menu Img and Text
	$('h1').each(function () {

		var menuCObj = '#' + $(this).attr('class') + 'Menu';
		$(menuCObj).addClass('selected');

		var menuObj = '#' + $(this).attr('id') + 'Menu';
		if ($('#menu dt').filter(menuObj).size() == 1) {
			$menuObj = $(menuObj).find('a:first img');
			$menuObj.removeClass('over');
			var src = $menuObj.attr('src');
			var imgsrc_on = imgsrc.replace('_of.', '_on.');
			$menuObj.attr('src', imgsrc_on);
		}
	});

	// Link focus
	$('a,area,input[type=image]').focus(function () {
		$(this).blur();
	})

	// Rollover
	var image_cache = new Object();
	$('img,input[type=image]').not("[src*='_on.']").each(function () {
		var imgsrc = $(this).attr('src');
		var imgsrc_ov = imgsrc.replace('_of.', '_ov.');
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ov;
		$(this).hover(function () {
			this.src = imgsrc_ov;
		}, function () {
			this.src = imgsrc;
		});
	});

	// PageTop	
	$('a[href^=#], area[href^=#]').not('a[href=#], area[href=#]').click(function () {
		if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({
					scrollTop: targetOffset
				}, 500, 'quart');
				return false;
			}
		}
	});
	
	// scrollFollow	
	$('#pageTop').scrollFollow({
		offset: 400,
		relativeTo: 'bottom',
		delay: 300
	});

	// slideshow	
	$('.slideshow').cycle({
		fx: 'fade',
		timeout: 6000
	});
	
	//Contents Img Hover
	$("#main a img").fadeTo(0, 1.0);
	$("#main a img").hover(function () {
		$(this).fadeTo(300, 0.7);
	}, function () {
		$(this).fadeTo(300, 1.0);
	});

});


// BackgroundImage
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch (e) {}


/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/

function css_browser_selector(u) {
	var ua = u.toLowerCase(),
		is = function (t) {
			return ua.indexOf(t) > -1;
		},
		g = 'gecko',
		w = 'webkit',
		s = 'safari',
		o = 'opera',
		h = document.documentElement,
		b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js'];
	c = b.join(' ');
	h.className += ' ' + c;
	return c;
};
css_browser_selector(navigator.userAgent);
