/* globalnav */

$(function () {
	var domain = location.hostname;
	var url = location.href.split(domain)[1].split('/');

	if (url[1].indexOf('index') < -1 || url[1] != '') {
		$('#header .gnav a[href*="' + url[1] + '"]').addClass('current');
	}
});



/* sidenav */

$(function () {
	var domain = location.hostname;
	var url = location.href.split(domain)[1];
	
	if (url.indexOf('index') > -1) {
		$('#sidenav a[href="' + url.split('index')[0] + '"]').parent().addClass('current');
	}
	else {
		$('#sidenav a[href="' + url + '"]').parent().addClass('current');
	}
});



/* rollover */

$(function () {
	var preLoad = new Object();
	$('img.ro,input.ro').not("[src*='_ro.']").each(function(){
		var imgSrc = this.src;
		var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
		var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
		var imgOver = imgName + '_ro' + fType;
		preLoad[this.src] = new Image();
		preLoad[this.src].src = imgOver;
		$(this).hover(
			function (){
				this.src = imgOver;
			},
			function (){
				this.src = imgSrc;
			}
		);
	});
});



/* page top */

var pagetopTimer = false;
function pagetop() {
	if(document.all){
		var currentY = document.documentElement.scrollTop;
	}else{
		var currentY = window.pageYOffset;
	}
	if (currentY > 0.5) {
		var newY = parseInt(currentY - currentY / 5);
		window.scrollTo(0, newY);
		pagetopTimer = setTimeout('pagetop()', 1);
	}
	else {
		window.scrollTo(0, 0);
		clearTimeout(pagetopTimer);
		pagetopTimer = false;
	}
}

$(function () {
	$('.pagetop a').click(function () {
		pagetop();
		return false;
	});
});



/* window open */

function openWin (url, option) {
	var options = [];
	options['width']       = 960;
	options['height']      = 600;
	options['status']      = 'no';
	options['scrollbars']  = 'yes';
	options['directories'] = 'no';
	options['menubar']     = 'no';
	options['resizable']   = 'yes';
	options['toolbar']     = 'no';
	
	if (option != null && typeof(option) === 'object') {
		for (var i in option) {
			switch (i) {
				case 'width'      : options['width']       = option[i]; break;
				case 'height'     : options['height']      = option[i]; break;
				case 'status'     : options['status']      = option[i]; break;
				case 'scrollbars' : options['scrollbars']  = option[i]; break;
				case 'directories': options['directories'] = option[i]; break;
				case 'menubar'    : options['menubar']     = option[i]; break;
				case 'resizable'  : options['resizable']   = option[i]; break;
				case 'toolbar'    : options['toolbar']     = option[i]; break;
			}
		}
	}
	
	var option_join = [];
	for (var i in options) {
		option_join.push(i + '=' + options[i]);
	}
	
	window.open(url, '', option_join.join(','));
	return false;
}



/* column margin resize */
$(function () {
	$('.cr > :last-child, .cc > :last-child, .cl > :last-child, .embox > :last-child').each(function(){
		$(this).css('margin-bottom', '0px');
	});
});



/* btn base resize */

$(function () {
	var len = $('.btm_btn li').size();
	if (len > 0 || len <= 3) {
		switch (len) {
			case 1:
				$('.btm_btn').css({marginLeft: '205px',marginRight: '205px'});
				break;
			case 2:
				$('.btm_btn').css({marginLeft: '102px',marginRight: '103px'});
				break;
		}
	}
});



/* rates tab */
$(function () {
	if (/#equipment/.test(location.href)) {
		$('#facility').hide();
		$('#equipment').show();
		$('#rates_tab .equipment').addClass('current');
		$('#rates_tab .facility').removeClass('current');
	}
	
	$('#rates_tab a').click(function(){
		if (this.className == 'facility') {
			$('#equipment').hide();
			$('#facility').show();
			$(this).addClass('current');
			$('#rates_tab .equipment').removeClass('current');
		}
		else if (this.className == 'equipment') {
			$('#facility').hide();
			$('#equipment').show();
			$(this).addClass('current');
			$('#rates_tab .facility').removeClass('current');
		}
		return false;
	});
});
