/*
 * Js by Sofresh version 1.0
 */
 
var isHome = false;
var pageSection = "home";
$(document).ready(function(){
						   
	// Lazyload
	$("img").lazyload({ 
		placeholder : "images/b.gif",
		effect : "fadeIn" 
	});

						   
	if (bigBannerAuto) clearTimeout(bigBannerAuto);
	if (smallBannerAuto) clearTimeout(smallBannerAuto);
	if (ctentBannerAuto) clearTimeout(ctentBannerAuto);
						   
	var urlReader = document.URL;
	
	if (urlReader.lastIndexOf("?p=")>0){
		pageSection = urlReader.substring(urlReader.lastIndexOf("?p=")+3, urlReader.length);
	}
	else{
		if (urlReader.match("calendar")=="calendar") pageSection="calendar";
		if (urlReader.match("gallery")=="gallery") pageSection="gallery";
		if (urlReader.match("menu")=="menu") pageSection="menu";
		if (urlReader.match("reservation")=="reservation") pageSection="reservation";
	}
		
	$('#musicPlayer').html('<object width="360" height="120"><param name="movie" value="main.swf"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent"><param name="allowscriptaccess" value="always"></param><param value="para='+pageSection+'" name="flashvars"></param><embed flashvars="para='+pageSection+'" src="main.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="120" wmode="transparent"></embed></object>');

						   
	if ($('.bigBanner_home').html() == null) isHome = false;
	else isHome = true;
						   
	if ($('.rotateBanner').html() != null){		
		bigBanner();
		bigBannerPaging();
		bigBannerBtns();
	}	
	smallBanner();
	ctentBanner();	
});


var bigBannerDelay = 5000;
var bigBannerSpeed = 500;
var bigBannerTempI = 0;
var bigBannerTempY = 0;
var bigBannerCount;
var bigBannerAuto;

var smallBannerDelay = 5000;
var smallBannerSpeed = 1000;
var smallBannerTempI = 0;
var smallBannerCount;
var smallBannerAuto;

var ctentBannerDelay = 3000;
var ctentBannerSpeed = 1000;
var ctentBannerTempI = 0;
var ctentBannerCount;
var ctentBannerAuto;

var pasBannerDelay = 5000;
var pasBannerSpeed = 500;
var pasBannerAuto;
var pasBannerTempI = 0;
var pasBannerTempY = 0;
var pasBannerCount;
var pasBannerTempI_b = 0;
var pasBannerTempY_b = 0;
var pasBannerCount_b;
var pasBannerTempI_c = 0;
var pasBannerTempY_c = 0;
var pasBannerCount_c;
var pasBannerTempI_d = 0;
var pasBannerTempY_d = 0;
var pasBannerCount_d;
var pasBannerTempI_e = 0;
var pasBannerTempY_e = 0;
var pasBannerCount_e;


function bigBanner(){
	$('.disableLayer').show();
	bigBannerCount = $('.rotateCopy').length;
		
	//reset pagination
	$('.banners_nav a').removeClass('active');
	$('.banners_nav a:eq('+bigBannerTempI+')').addClass('active');
	
	if (isHome == true){
		$('.rotateCopy').fadeOut(bigBannerSpeed);
		$('.rotateCopy:eq('+bigBannerTempI+')').fadeIn(bigBannerSpeed, function(){
			bigBannerA();
		});
	}
	else{
		$('.rotateCopy').fadeOut(bigBannerSpeed);
		$('.rotateCopy:eq('+bigBannerTempI+')').fadeIn(bigBannerSpeed, function(){ $('.disableLayer').hide(); });
		if (bigBannerCount>1) bigBannerAuto=setTimeout("bigBanner()", 5000)
		bigBannerTempI = bigBannerTempI+1;
		bigBannerTempY = bigBannerTempI-1;
		if (bigBannerTempI == bigBannerCount) bigBannerTempI=0;
	}
};

	function bigBannerA(){
		$('.rotateCopy_a').fadeOut(bigBannerSpeed);
		$('.rotateCopy_a:eq('+bigBannerTempI+')').fadeIn(bigBannerSpeed, function(){
			bigBannerB();
		});
	};
	
	function bigBannerB(){
		$('.rotateCopy_b').fadeOut(bigBannerSpeed);
		$('.rotateCopy_b:eq('+bigBannerTempI+')').fadeIn(bigBannerSpeed, function(){
			
			if ( bigBannerCount>1 ) bigBannerAuto=setTimeout("bigBanner()",bigBannerDelay)
			bigBannerTempI = bigBannerTempI+1;
			bigBannerTempY = bigBannerTempI-1;
			if ( bigBannerTempI == bigBannerCount) bigBannerTempI=0;
			
			$('.disableLayer').hide();
		});	
	};
	
	
	
// Calendar | past events
function init_pasBanner(){
	$('.disableLayer').show();
	pasBannerCount = $('.pasCopy_a').length;
	pasBannerCount_b = $('.pasCopy_b').length;
	pasBannerCount_c = $('.pasCopy_c').length;
	pasBannerCount_d = $('.pasCopy_d').length;
	pasBannerCount_e = $('.pasCopy_e').length;
	pasBanner();
};

function pasBanner(){
	$('.pasCopy_a').fadeOut(pasBannerSpeed);
	$('.pasCopy_a:eq('+pasBannerTempI+')').fadeIn(pasBannerSpeed, function(){
		pasBannerTempI = pasBannerTempI+1;
		pasBannerTempY = pasBannerTempI-1;
		if ( pasBannerTempI == pasBannerCount) pasBannerTempI=0;
		pasBannerB();		
	});	
};

	function pasBannerB(){
		$('.pasCopy_b').fadeOut(pasBannerSpeed);
		$('.pasCopy_b:eq('+pasBannerTempI_b+')').fadeIn(pasBannerSpeed, function(){
			pasBannerTempI_b = pasBannerTempI_b+1;
			pasBannerTempY_b = pasBannerTempI_b-1;
			if ( pasBannerTempI_b == pasBannerCount_b) pasBannerTempI_b=0;
			pasBannerC();
		});
	};
	
	function pasBannerC(){
		$('.pasCopy_c').fadeOut(pasBannerSpeed);
		$('.pasCopy_c:eq('+pasBannerTempI_c+')').fadeIn(pasBannerSpeed, function(){
			pasBannerTempI_c = pasBannerTempI_c+1;
			pasBannerTempY_c = pasBannerTempI_c-1;
			if ( pasBannerTempI_c == pasBannerCount_c) pasBannerTempI_c=0;
			pasBannerD();
		});
	};
	
	function pasBannerD(){
		$('.pasCopy_d').fadeOut(pasBannerSpeed);
		$('.pasCopy_d:eq('+pasBannerTempI_d+')').fadeIn(pasBannerSpeed, function(){
			pasBannerTempI_d = pasBannerTempI_d+1;
			pasBannerTempY_d = pasBannerTempI_d-1;
			if ( pasBannerTempI_d == pasBannerCount_d) pasBannerTempI_d=0;
			pasBannerE();
		});
	};
	
	function pasBannerE(){
		$('.pasCopy_e').fadeOut(pasBannerSpeed);
		$('.pasCopy_e:eq('+pasBannerTempI_e+')').fadeIn(pasBannerSpeed, function(){
			
			if ( pasBannerCount>1 ) pasBannerAuto=setTimeout("pasBanner()",pasBannerDelay)
			pasBannerTempI_e = pasBannerTempI_e+1;
			pasBannerTempY_e = pasBannerTempI_e-1;
			if ( pasBannerTempI_e == pasBannerCount_e) pasBannerTempI_e=0;
		});	
	};
	
	

/************************/
/* Bigbanner pagination */

function bigBannerPaging(){	/* generate pagination */
	if (bigBannerCount>1){

		for (var tempPaging=1; tempPaging < bigBannerCount+1; tempPaging++){
			$('.banners_nav').append('<a href="#"><p>'+tempPaging+'</p></a>');
		}
		$('.banners_nav a:first').addClass('active');
	}
	
	$('.banners_nav a').click(function(){ return false; $('.disableLayer').show();});
	$('.banners_nav p').click(function(){
		$('.banners_nav a').removeClass('active');
		$(this).parent().addClass('active');
									  
		if (bigBannerAuto) clearTimeout(bigBannerAuto);
		buttonClick = false;
		bigBannerTempI = parseInt($(this).html())-1;
		bigBannerTempY = bigBannerTempI-1;
		if (bigBannerTempY<0) bigBannerTempY = bigBannerCount - 1;		
				
		bigBanner();
	});
};

/************************/
/*   Bigbanner buttons  */

function bigBannerBtns(){
	$('.btn_rotateImg_prev').click(function(){
		bigBannerTempI = bigBannerTempY-1;
		bigBannerTempY = bigBannerTempI-1;
		
		if (bigBannerTempI<0){		
			bigBannerTempI = bigBannerCount-1;
			bigBannerTempY = 0;
		}
		if (bigBannerAuto) clearTimeout(bigBannerAuto);
		bigBanner();
	});
	
	$('.btn_rotateImg_next').click(function(){
		if (bigBannerAuto) clearTimeout(bigBannerAuto);
		bigBanner();
	});
};

/*****************************************************************/



/***********************/
/*     SubBanner       */

function smallBanner(){
	smallBannerCount = $('.rotateCopy_sub2').length;
	$('.rotateCopy_sub2').fadeOut(smallBannerSpeed);
	$('.rotateCopy_sub2:eq('+smallBannerTempI+')').fadeIn(smallBannerSpeed);
	
	if ( smallBannerCount>1 ) smallBannerAuto = setTimeout("smallBanner()",smallBannerDelay)
	smallBannerTempI = smallBannerTempI+1;
	if ( smallBannerTempI == smallBannerCount) smallBannerTempI=0;	
};


/***********************/
/*   Content banner    */

function ctentBanner(){
	ctentBannerCount = $('.rotateCopy_sub').length;
	$('.rotateCopy_sub').fadeOut(ctentBannerSpeed);
	$('.rotateCopy_sub:eq('+ctentBannerTempI+')').fadeIn(ctentBannerSpeed);
	
	if (ctentBannerCount>1) ctentBannerAuto = setTimeout("ctentBanner()",ctentBannerDelay)
	ctentBannerTempI = ctentBannerTempI+1;
	if (ctentBannerTempI == ctentBannerCount) ctentBannerTempI=0;	
};








var caobox = {		
	fadeEffectDuration : 900,
	fade:"#fade",
	light:"#light",
	boxID:"",
	overlayBgColor:"#000",
	overlayOpacity:"85",
	
	show:function(boxId, overlayBgColor, overlayOpacity, overlayDisable, leftPosition, topPosition)
	{
		// Get layer Background color & opacity
		if (overlayBgColor) this.overlayBgColor = "#"+ overlayBgColor;
		if (overlayOpacity) this.overlayOpacity = overlayOpacity;
		
		// Add layer
		$('body').prepend('<div id="light"></div><div id="fade"></div>');		
		$('#light, #fade').css({'display':'none', 'position':'absolute'});
		$('#light').css({	'position':'fixed',
							'zIndex':'10002',
							'height':'auto',
							'overflow':'hidden'});
		$('#fade').css({	'zIndex':'10001',
					   		'left':'0',
							'top':'0',
					   		'backgroundColor': ''+ this.overlayBgColor +'',
					   		'opacity':'.'+ this.overlayOpacity+'',
							'filter':'alpha(opacity='+ this.overlayOpacity +')'
						}).click(	function(){
										//if (overlayDisable) return true;
										//else caobox.hide();
									});
	
		// Show layer
		this.boxID='#'+boxId;		
		$('object, embed, select').css('visibility','hidden');

		// Insert copy
		$(this.boxID).clone().appendTo($(this.light));
		
		
		$(this.boxID).show();
		$(this.light).show();
		//$(this.light).fadeIn('fast', function(){
			 //$(this.light).css({display:'block'}); 
		//});	

		var _top = Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		
		// Left position, default is center
		if (leftPosition){
			_left = leftPosition;
			if (leftPosition > 0) $(this.light).css({left: _left+ "px"});
			else			
				$(this.light).css({right: Math.abs(_left) + "px"});			
		}
		else{
			_left = Math.round((getDocumentSize(2) - $(this.light).width()) / 2);
			$(this.light).css({left: _left+ "px"});
		}		
		
		// Top position, default is middle
		if (topPosition){			
			if (topPosition > 0){
				_top = topPosition;
				$(this.light).css({top: _top+"px"});
			}
			else{
				_top = Math.abs(topPosition);
				$(this.light).css({bottom: _top+"px"});
			}
		}		
		else{
			if(_top < 0) _top = 20;		
			$(this.light).css({top: _top+"px"});
		}
		
		caobox.showAlertLayer();	
		caobox.setFocusElement();
		//window.scrollTo(0,0);
		window.onresize=caobox.resizeLayers;
	},
	
	hide:function(){	
		$(this.boxID).remove();
		//$(this.fade).fadeOut(this.fadeEffectDuration);
		$(this.fade).hide();
		//$(this.light).fadeOut(this.fadeEffectDuration, function(){
		$(this.light).show(function(){
			$('object, embed, select').css('visibility','');
			$('#fade, #light').remove();
		});
	},
	
	showAlertLayer : function(){
		var _height=getDocumentSize(1);
		var _width =getDocumentSize(0);
		
		if(_width < 974) 
			 _width = 974;	
		
		if($(this.boxID).height() > getDocumentSize(1))
			_height=parseInt($(this.boxID).height()) + 65;		
		
		$(this.fade).css({width:_width +'px'});
		$(this.fade).css({height:_height +'px'});	
		//$(this.fade).css({display:'block'}); 
		//$(this.fade).fadeIn('normal');
		$(this.fade).show()
	},
	
	resizeLayers : function(){
		if($(this.boxID).height() > getDocumentSize(1)){
			var _height = parseInt($(this.boxID).height());
			var pageHeight = _height;
		}
		else{
			if (getDocumentSize(1) > getDocumentSize(3)){ var pageHeight=getDocumentSize(1)}
			else{ var pageHeight=getDocumentSize(3);}
		};
		
		if(getDocumentSize(0) < 974) $('#fade').css({width:974 + "px"});
		else $('#fade').css({width:getDocumentSize(0) + "px"});
		$('#fade').css({height:pageHeight + 'px'});
		$('#light').css({left: Math.round((getDocumentSize(2) - $('#light').width()) / 2)+"px"});
		
		var _top=Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		if(_top < 0) _top = 20;
		$(this.light).css({top:_top+"px"});
	},
	
	findFucusElement:function(){
		$("#light").find('object, embed, select').css({'visibility':'visible'});
		$("#light").find('input[@type!=hidden], a, select, textarea').addClass('setFocusAble');			
		return $('.setFocusAble');
	},
	
	setFocusElement:function(){
		var i = 0;
		var cntElement = 0;	
		var allFocusElement = caobox.findFucusElement();
		var len=allFocusElement.length;	
		
		if (len>0){
			for(var temJ = 0; temJ<len-1; temJ++){
				$(allFocusElement[temJ]).attr('rel',temJ+1);
			}
			
			// fix focus on 1st hidden element
			if ( allFocusElement[0].style.display == 'none') 
				allFocusElement[1].focus();
			else
				allFocusElement[0].focus();
	
	
			allFocusElement.focus(function(){ cntElement=this.getAttribute('rel'); });
			$("#light").keydown(function(event){									 
				if(event.shiftKey){
					if(event.keyCode == 9){					
						if (i!=cntElement) i=cntElement;
						i--;			
						if (i == 0) {
							i = len-1;
							allFocusElement[i].focus();
							return false;
						}
					}
				}
				else{
					if(event.keyCode == 9){
						if (i != cntElement) i = cntElement;
						if (i == len-1){
							i=0;
							allFocusElement[0].focus();						
							return false;
						}
						else{
							i++;
						}
					}
				}			
			}); 
		}
	},
	
	unbindClickFace:function(){
		$(this.fade).unbind('click');
	},
	
	init:function()
	{		
		$(document).ready(function(){
			$('body').css({'margin':'0', 'padding':'0'}); // hack browser
		})		
	}
};
caobox.init({							
});

// Get ducument size
// @param int 0 ~ 3
// @return array [width of current page] [height of current page] [width of window] [height of window]
function getDocumentSize(val){
	var xScroll,yScroll,value;
	
	if(window.innerHeight&&window.scrollMaxY){
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight){
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
		}
		else{
			xScroll=document.body.offsetWidth;
			yScroll=document.body.offsetHeight;
		}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;
			windowHeight=document.documentElement.clientHeight;
		}
		else if(document.body){
			windowWidth=document.body.clientWidth;
			windowHeight=document.body.clientHeight;
		}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize[val];
};



function tabControl(obj, num){
	var curentTab=obj.id;
	var curentContent=curentTab.replace("tab","cont");

	curentContent_1=curentTab.replace("tab","cont");
	var tabs=$('#' + curentTab).parent().children();
	var contents=$('#' + curentContent).parent().children();

	$(tabs).each( function(){								
			$(this).removeClass('active');
	});		
	
	$(contents).each( function(){								
			$(this).hide();
	});	
	
	$('#' + curentTab).addClass('active');
	$('#' + curentContent).show();
	
	return false;
}