﻿
var _Common_ = {
	initRollovers:function(){
		if (!document.getElementById) return
		var aPreLoad = new Array();
		var sTempSrc;
		var aImages = document.getElementsByTagName('img');
		var img_Len = aImages.length;
		for (var i = 0; i < img_Len; i++) {		
			if (aImages[i].className == 'over') {
				var src = aImages[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);
				var hsrc = src.replace(ftype, '_over'+ftype);
	
				aImages[i].setAttribute('hsrc', hsrc);
				aPreLoad[i] = new Image();
				aPreLoad[i].src = hsrc;
				aImages[i].onmouseover = function() {
					sTempSrc = this.getAttribute('src');
					this.setAttribute('src', this.getAttribute('hsrc'));
				}	
				aImages[i].onmouseout = function() {
					if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_x'+ftype, ftype);
					this.setAttribute('src', sTempSrc);
				}
			}
		} 
		
		var aInputs = document.getElementsByTagName('input');
		var img_Len = aInputs.length;
		for (var i = 0; i < img_Len; i++) {		
			if (aInputs[i].className == 'over') {
				var src = aInputs[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);
				var hsrc = src.replace(ftype, '_over'+ftype);
	
				aInputs[i].setAttribute('hsrc', hsrc);
				aPreLoad[i] = new Image();
				aPreLoad[i].src = hsrc;
				aInputs[i].onmouseover = function() {
					sTempSrc = this.getAttribute('src');
					this.setAttribute('src', this.getAttribute('hsrc'));
				}	
				aInputs[i].onmouseout = function() {
					if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_x'+ftype, ftype);
					this.setAttribute('src', sTempSrc);
				}
			}
		}   
		return;
	},
	scrollInit:function(){
		$('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}, 1000, 'easeOutCubic',function(){
				
					location.href = href;
//					location.replace(href);				
				}); 
				return false;
			}
		})
		$('area[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}, 1000, 'easeOutCubic',function(){
				
					location.href = href;
//					location.replace(href);				
				}); 
				return false;
			}
		})
	
	}
}


$(function(){
	_Common_.scrollInit();
	_Common_.initRollovers();
	check.init();
	searchDetail.init();
});

function tab(obj,current,none,id){
	
	
		
	if($(obj).find("img").attr("src").indexOf("_current") < 0){
	
		$("#Tab"+ id).find("img").each(function(){
								  
			var src = $(this).attr("src");						  
			src = src.replace(/_current/gi,"");
			$(this).attr("src",src);	
		})
		
		
		var src = $(obj).find("img").attr("src");
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		$(obj).find("img").attr("src",src.replace(ftype, '_current'+ftype));
		
	
		$("#" + current + id).show();
		$("#" + none + id).hide();
	}
	return false;
};


var area = {};
area.current = "";
area.detail = function(obj){
	
	var id = $(obj).attr("href").replace(/#/gi,"");
	area.current = id;
	$("#" + id).find(".bg").css({opacity:0.7});
	$("#" + id).show(300);
	return false;
	
	
};

area.detailClose = function(obj){
	
	$("#" + area.current).hide(300);
	return false;
	
	
};


var check = {};
check.init = function(){
	
	
	$(".allCheck input").click(function(){
		
		if($(this).attr("checked")){
		
			$(this).parent().parent().parent().find("input").attr("checked","checked");
		
		}else{
			$(this).parent().parent().parent().find("input").removeAttr("checked");
		}
		
	});
	
};

var searchDetail = {};
searchDetail.init = function(){
	$(".areaList input").click(function(){
		if($(this).attr("checked")){
			$(".areaDetailList").hide().eq(eval($(this).attr("accesskey")-1)).show();
			
		
		}
	});
};


jQuery.extend( jQuery.easing,
{
	def: 'easeOutCubic',
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	}
});



