// JavaScript Document
//偵測出視窗的高與寬
var viewportwidth;
var viewportheight;

//用來儲存size的物件
var DataSize = new Object();


//監聽=======
$(document).ready(function() {
						   
	//flash 呈現
	setOpening()
	
	//計算頁面上各個的位置
	header_and_footer();
	
	//改變視窗大小時，相關的設定...
	$(window).bind("resize",header_and_footer);
	
	
});

//當 window resize 調整相關大小與位置
function header_and_footer(){
	//偵測視窗等各個相關寬高(大小)
	window_width_size(); 
	fixed_all_fun();
	viewportheight = (DataSize.box_height > viewportheight)?DataSize.box_height:viewportheight;
	var background =  (DataSize.box_height > viewportheight || DataSize.box_width > viewportwidth)?footer_open_fun():footer_close_fun();
}

//固定兩邊，視窗大小的處理
function fixed_all_fun(){
	//content留白區(上下)
	DataSize.padding_top = (viewportheight-DataSize.box_height)/2;
	//改變位置
	$("#box").css("margin-top",(DataSize.padding_top)+"px");
	
}

//偵測出視窗的高寬
function window_width_size(){
	viewportwidth = eval($(window).width());
	viewportheight = eval($(window).height());
	
	//將資訊加入物件
	DataSize.box_height = $("#box").height();   //content中間圖的高
	DataSize.box_width = $("#box").width();   //content中間圖的寬
}


//當footer展開時，視窗過小的反黑背
function footer_open_fun(){	
	$(".bgerror").css("display","block");
	$(".bgerror").css("height",viewportheight+"px");
	$(".bgerror").css("width",viewportwidth+"px");
	$(".bgerror img").css("margin-top",(viewportheight - $(".bgerror img").height())/2+"px");	
	$("#box").css("display","none");
}

function footer_close_fun(){
	$(".bgerror").css("display","none");
	$("#box").css("display","block")
}

//===========================================================
function removeSkip(){
	var lang = $("div.langurage");
	var skip = $("div.skip");
	skip.css("display","none");
	lang.css("display","block");
	//alert(lang[0]);
	if(lang[0].opTween == undefined){
		   lang[0].opTween = new OpacityTween(lang[0],Tween.regularEaseOut, 0, 100, 1);
		   lang[0].opTween.start();
		}else{
		   lang[0].opTween.start();
	}
	//lang.css("display","block");
}


function setOpening(){
	var opening = $("div.opening");	
	if(opening){
	opening.flash(
        { 
            src: 'flash/open/loading.swf',
			wmode: 'transparent'
        },
        { version: 9 },
        function(htmlOptions) {
			 htmlOptions.height = 510;
            htmlOptions.width = 870;
			 this.innerHTML ='';
            $(this).prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	}
}
