var isLocal=document.domain=="";
	
/* ---------------------------------- */

/* animateBetween */
var rfxnum = /^([+-]=)?([¥d+-.]+)(.*)$/,rdashAlpha = /-([a-z])/ig,fcamelCase = function( all, letter ) {
		return letter.toUpperCase();
};

(function($) {  
   $.fn.animateBetween = function(prop1,prop,speed,easing,callback) { 
   var optall=jQuery.speed(speed,easing,callback);
	if(jQuery.isEmptyObject(prop)){
		return this.each(optall.complete)
	}
	return this[ optall.queue === false ? "each" : "queue" ](function() {
			var opt=jQuery.extend({},optall)
			,p
			,hidden=this.nodeType===1&&jQuery(this).is(":hidden")
			,self=this;
		
			for ( p in prop ) {
				var name = p.replace(rdashAlpha, fcamelCase);
				if ( p !== name ) {
					prop[ name ] = prop[ p ];
					delete prop[ p ];
					p = name;
				}
				if ( ( p === "height" || p === "width" ) && this.style ) {
					opt.display = jQuery.css(this, "display");
					opt.overflow = this.style.overflow;
				}
				if ( jQuery.isArray( prop[p] ) ) {
					(opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
					prop[p] = prop[p][0];
				}
			}
			if ( opt.overflow != null ) {
				this.style.overflow = "hidden";
			}
			opt.curAnim=jQuery.extend({},prop);
			jQuery.each(prop,function(name,val){
				var e=new jQuery.fx(self,opt,name);
				var endParts = rfxnum.exec(val);
				
				if(endParts){
						var end=parseFloat(endParts[2]);
						var unit = endParts[3] || "px";
					
						var startParts = rfxnum.exec(prop1[name]);
						var start=parseFloat(startParts[2]);
					
						if ( unit !== "px" ) {
							self.style[ name ] = (end || 1) + unit;
							start = ((end || 1) / e.cur(true)) * start;
							self.style[ name ] = start + unit;
						}
						
					if ( endParts[1] ) {
						end = ((endParts[1] === "-=" ? -1 : 1) * end) + start;
					}
					e.custom(start,end, unit );
				}else{
					e.custom(prop1[name],val, "" );
				}
			});
			return true;
	 });
    }
})(jQuery);



/* ---------------------------------- */

/* BTN_EF */

(function($) {  
   $.fn.BTN_EF = function(alp) { 
   var alp=(alp==undefined)?.55:alp;   
    if (pcPow!=1) return;	
		$(this).hover(
		function(){	
		if($(this).attr("current")!="this"){
				var img=$(this).find("img");			
				img.stop().animate({ opacity: alp }, 0,'easeInOutQuad');
			}
		},
		function(){
			if($(this).attr("current")!="this"){
				var img=$(this).find("img");			
				img.stop().animate({ opacity: 1 }, 500,'easeInOutQuad');
			}
		});	
    }
})(jQuery);

(function($) {  
   $.fn.BTN_EF_SELF = function(alp) {		   
	var alp=(alp==undefined)?.55:alp;	
   if (pcPow!=1) return;	
		$(this).hover(
		function(){	
			$(this).stop().animate({ opacity:alp }, 0,'easeInOutQuad');
		},
		function(){				
			$(this).stop().animate({ opacity: 1 }, 400,'easeInOutQuad');					
		});
    }
})(jQuery);


(function($) {  
   $.fn.BTN_EF_REV = function(alp) {  
   		var alp=(alp==undefined)?.5:alp;	
  		 if (pcPow!=1) return;   
		$(this).hover(
		function(){	
			$(this).stop().animate({ opacity: alp }, 0,'easeInOutQuad');
		},
		function(){			
				$(this).stop().animate({ opacity: 0}, 300,'easeInOutQuad');
		});
    }
})(jQuery);


(function($) {  
   $.fn.BTN_EF_IMG = function() {   
   		if (pcPow!=1) return;		
		this.each(function() {  
		var postfix= '_on';
		var img=$(this).find("img");
		var offsrc = img.attr("src");
		var dot = offsrc.lastIndexOf(".");
		var onsrc = offsrc.substr(0, dot) + postfix + offsrc.substr(dot, 4);
		set_cashe(onsrc);
		$(this).hover(
		function(){
			img.attr("src",onsrc);
		},
		function(){
			img.attr("src",offsrc);
		});	
	});	
    }
})(jQuery);

(function($) {  
   $.fn.BTN_EF_IMG_COVER = function() {
   		if (pcPow!=1) return;		
		this.each(function() { 
		var self=$(this);
		var img=$(this).find("img");		
		var offsrc = img.attr("src");
		var w=img.attr("width");
		var h=img.attr("height");
		var p=self.parent();	
		p.css({background:"url("+offsrc+")"});	
		var postfix= '_on';
		var dot = offsrc.lastIndexOf(".");
		var onsrc = offsrc.substr(0, dot) + postfix + offsrc.substr(dot, 4);
		img.css({ opacity: 0 });
		img.attr("src",onsrc);
		p.hover(
		function(){
			img.stop().animate({ opacity: 1 }, 100,'easeInOutQuad');
		},
		function(){
			img.stop().animate({ opacity: 0 }, 400,'easeInOutQuad');
		});
	});	
    }
})(jQuery);


/*


(function($) {  
   $.fn.BTN_SLIDE = function() {    
    if (pcPow!=1) return;	
		$(this).hover(
		function(){	
			if(isCookKill)return;
			//trace();			
			var h=$(this).height();
			$(this).stop().css("opacity",1).animate({backgroundPosition:"0px "+h+"px"},600,'easeInOutCubic');		
		},
		function(){		
			if(isCookKill){
				$(this).css({backgroundPosition:"0px 0px"});
			}else{
				$(this).stop().animate({backgroundPosition:"0px 0px"},600,'easeInOutCubic');
			}
		})			
    }
})(jQuery);

*/



	
/* ---------------------------------- */

/* SET_CASHE */
function set_cashe(url){	 
	 	var img=new Image();
		img.src = url;		
}
	
/* ---------------------------------- */

/* PageTop */
(function($) {  
   $.fn.PageTop = function() { 
			$(this).click(function() {
					scrollCallBack=function(){
					};			
					scrollToNum(0);			
					return false;
			});
			$(this).BTN_EF();
    }
})(jQuery);


/* ---------------------------------- */

/* SOUND_ON_OFF */



(function($) {  
   $.fn.SOUND_ON_OFF = function() { 
			$(this).click(function() {
					soundVolumeChange();		
					return false;
			});
			$(this).BTN_EF();
    }
})(jQuery);


//$(window).triggerHandler('COOK_OPEN',me.attr("id"));	
//$(window).bind("COOK_OPEN",openFuncID);		


function setScrollArea(num){	
	var h=num;
	var f=148;
	var h=getPageSize()[1]-(headHeight+h+f);
	h=(h<0)?0:h;	
	$("#scrollable").height(h);	
	
}


/* ---------------------------------- */
/* util */


function scrollToTarget(ta,time,delay){
	if(delay==undefined){
		delay=0;
	}
	$("html,body").queue([]).stop().delay(delay).queue(function(){
		var ny=getOffsetY(ta);
		if(time==undefined){
			var nowY=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
			time=getScrollTime(ny,nowY);	
		}
		scrollToNum(ny,time);
	});
}

function getScrollTime(a,b){	
		var c=a-b;
		var dist=(c<0)?-c:c;
		var time=(800>dist)?800:dist;	
		return time;	
}

function getOffsetY(ta){
	var addY=0;
	if(isIpad){
		addY=-(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0);
	}
	return ta.offset().top+NoHeadMaginHeight+addY;
}

function setNowOffSet(){
	if(isIpad){		
		var now=window.pageYOffset;		
		$("html,body").scrollTop(now); 
	}
}

function scrollToNum(num,time,delay){	
	var nowY=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	if(time==undefined){
		//	time=getScrollTime(num,$("html,body").scrollTop());
		time=getScrollTime(num,nowY);
	}
	//trace($("html,body").scrollTop())
	setNowOffSet();
	if(delay==undefined){
		$("html,body").queue([]).stop().animateBetween({scrollTop:nowY},{scrollTop:num},time,'easeInOutQuad',scrollCallBack);
		//$("html,body").queue([]).stop().animate({scrollTop:num},time,'easeInOutQuad',scrollCallBack);
	}else{
		$("html,body").queue([]).stop().delay(delay).animateBetween({scrollTop:nowY},{scrollTop:num},time,'easeInOutQuad',scrollCallBack);
		//$("html,body").queue([]).stop().delay(delay).animate({scrollTop:num},time,'easeInOutQuad',scrollCallBack);
	}
	
	//$("html,body").scrollTop(num);
	//scrollCallBack();
}

var scrollCallBack;

function trace(str){	
	alert(str);	
}
function updateWindow(){
	var y=$('html,body').attr('scrollTop');
	$('html,body').attr('scrollTop',y+1);
	$('html,body').attr('scrollTop',y);
}

function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(windowWidth,windowHeight,pageWidth,pageHeight);
			return arrayPageSize;
		};		
	
	function getScrollBarWidth(){		
		var div=$('<div/>',{id:'dummyDiv'});
		div.css({position:"absolute",top:"0px",left:"0px",margin:"0px",border:"0px",padding:"0px",overflowY:"scroll",width:"100px",height:"100px",visibility:"hidden"});
		div.appendTo('body');			
		var img=$('<img/>',{width:"100px",height:"100px"}).appendTo(div);
		var divhtml=document.getElementById("dummyDiv");
		var scw=divhtml.offsetWidth-divhtml.clientWidth;	
		div.remove();
		return scw;	
	}
	
	var logssss1;
	var logssss2;
	function getLog(str,str2){	
				logssss1=str;
				logssss2=str2;
				//var logID="/"+pageid+"/"+str;	
				//_gaq.push(['_trackPageview',logID]);
				//if(str!=null){
				//google
					pageTracker._trackPageview(str);
				//}			
				
				
				
				if(str2!=null){
				
				//X-ADVANCE
				//adtrafficTrack._trackFlashRequest(str2,'');
				setTimeout("getLog2()",100);
				}
	}
	
	function getLog2(){
		adtrafficTrack._trackFlashRequest(logssss2,'');
	}
	
	
	function setCurrentMainBTN(target){
		var ta=$("#"+target+" img");	
		if(ta.length!=0){
			var turl=ta.attr("src").replace(".gif","c.gif");		
			ta.attr("src",turl);
		}
	}
	
	function windowLoaded(func){
		if(isLocal){
			func();
		}else{
			$(window).bind("load", func);
		}
	}
	
	function delayed(num,func,arg){
		(function(func,arg){
			setTimeout(function(){
								if(arg instanceof Array){
								}else{
									arg=[arg];
								}
								func.apply(null,arg);
								},num);
		})(func,arg);
	}
	
	function intervalAct(num,func,arg){
		(function(func,arg){
			setInterval(function(){
								if(arg instanceof Array){
								}else{
									arg=[arg];
								}
								func.apply(null,arg);
								},num);
		})(func,arg);
	}
