// JavaScript Document
//監聽=======
$(document).ready(function() {
						   
	//置換各flash
	setTitle();
	setLogo();
	setTimeLine();
	setlimpid_X_Flash();
	
	//設定總寬
	getAllChildWidth(".ulAll",0);
	setMotion();
	
	//設定常數
	setBroser();
	setStillV(ScaleSide);
	
	
	//計算頁面上各個的位置
	header_and_footer();
	
	//改變視窗大小時，相關的設定...
	$(window).bind("resize",header_and_footer);
		
	//menu
	menusetup();
	
	// footer 的展開與收縮
	$("#footer .tag").toggle(
		function () {
			footer_move(true);
		},
		function () {
			footer_move(false);
		}
	);
	
	setFlashScroll();
	
	
	//footer slideshow 設定每3秒有slideshow的效果
	if($(".hot_news ul li").length>(Math.floor(($(".hot_news").width()+1)/420))){
		var setIntervalA = setInterval("newsSlideshow()", 8000);
		$(".hot_news ul li a").bind("mouseover",function(){clearInterval(setIntervalA);});
		$(".hot_news ul li a").bind("mouseout",function(){setIntervalA=setInterval("newsSlideshow()", 8000);});
	}
	
	//ajax監聽(loading圖)
	$("#loadingImg").bind("ajaxSend", function(){
	  $(this).show();
	  $("#loadingImg").css("width",$(".newslist ul").css("width")); //設定loading畫面的寬
	}).bind("ajaxComplete", function(){
	  $(this).hide();
	});
	//ajax==========================================
	newslistAjax(0);
	
	
	$('.thumbs').piroBox({
			mySpeed: 500,  
			bg_alpha: 0.7,
			pathLoader : 'url(../css/css_pirobox/ajax-loader_w.gif) center center no-repeat;', 
			gallery : '.ulAll li a', 
			gallery_li : '.ulAll li', 
			next_class : '.next_in',
			previous_class : '.previous_in'
	});
	
	
	
});

var t1 = new Sequence();
var t2 = new Sequence();
function setMotion(){
	var target = $(".ulAll").children();	
	
	for(var i=0;i<target.length;i++){
		t1.addChild(new OpacityTween(target[i],Tween.regularEaseOut,0,100,1));
		t2.addChild(new Tween(target[i].style,'marginLeft',Tween.backEaseOut,30,0,1,'px'));

	}
	t2.start();
	t1.start();
}



function setFlashScroll(){
	
	flash = thisMovie("flash/timeLine");
	$(".bar").bind("mousedown",barDown);
	$(window).bind("resize",flashBack);
}

function barUp(e){
	 $(".info").html("up");	 
	$(document).unbind("mouseup",barUp);	
	 $(document).unbind("mousemove",barMoveT);
}

function barDown(e){
	 $(".info").html("down");
	 $(document).bind("mouseup",barUp);	
	 $(document).bind("mousemove",barMoveT);
}

function barMoveT(e){	
	//flash.setPo(barLeft);	
	 var newMaxDist = Scroll.contect.outerWidth()-Scroll.contect.parent().outerWidth();
	 var newTargetPo = Scroll.contect.css("margin-left");
	 newTargetPo=(newTargetPo=='auto')?eval(0):eval(newTargetPo.replace(/px/g,""));
	
	//var w = $(".bar").parent().innerWidth()-$(".bar").outerWidth();
	//var percent = Math.ceil(barLeft/w*100);
	flash.setPo(Math.abs(newTargetPo),newMaxDist);
}
function flashBack(e){
	var w = $(".bar").parent().innerWidth()-$(".bar").outerWidth();
	flash.setPo(0,w);
}

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
}


function setTimeLineSize(tragetW,tragetH){
	var flashTimeLine = $(".flashTimeLine");
	flashTimeLine.css("width",tragetW+"px");
	flashTimeLine.css("height",tragetH+"px");	
}