function getCurrentStep(curr){
	return currentStep+"";
}
$(document).ready(function(){
	menuInit(0);
}); 
// on DOM
var pageLoaded = false;
$(function(){
	var tmpClick = 0;
	var imoveFlg = false;
	resizeondom();	
	$('#slide_btn').hide();
	$('#banner').hide();
	$('#vdoPanel').hide();
	$('body').prepend('<div id="overlay" style="position:absolute;background-color:#000;z-index:1022;"><'+'/div>');	
	$("#thumbSlide .handle .slide").css({cursor:"pointer"}).prepend('<div class="slidebg"><'+'/div>').hover(
      function () {
        $(this).find(".slidebg").stop().animate({opacity:0},250);
      }, 
      function () {
        $(this).find(".slidebg").stop().animate({opacity:.4},150);
      }
    )
	.mousedown(function(){
		tmpClick = $(this).offset().left;
	})
	.bind("touchstart",function(e){
		imoveFlg = false;
	})
	.bind("touchmove",function(e){
		imoveFlg = true;
	})
	.bind("touchend",function(e){
		if(!imoveFlg){
			var index = $("#thumbSlide .handle .slide").index(this);
			$('#hmSlide').animate({left:$("body").width()+"px"},500,function(){
				$('#homeSlideList').hide();
				var left = index*$("#teaserSlideList .handle .slide").width();
				var x = left/($("#teaserSlideList .handle").width() -$("#teaserSlideList").width());
				teaserSlideList.setValue(x);
			});	
			$('#overlay').hide();
		}
	})
	.click(function(){		
		if(tmpClick == $(this).offset().left){
			var index = $("#thumbSlide .handle .slide").index(this);
			$('#hmSlide').animate({left:$("body").width()+"px"},500,function(){
				$('#homeSlideList').hide();
				var left = index*$("#teaserSlideList .handle .slide").width();
				var x = left/($("#teaserSlideList .handle").width() -$("#teaserSlideList").width());
				teaserSlideList.setValue(x);
			});	
			$('#overlay').hide();
		}
	});
	$("#overlay").click(function(){
		if(!$('#homeSlideList').is(":hidden")) {
			$('#hmSlide').animate({left:$("body").width()+"px"},500,function(){
				$('#homeSlideList').hide();
			});				
		}	
		$('#overlay').hide();
		closeVDO();
	});
	$("#thumbSlide .handle .slidebg").css({opacity:.2});
	////
	$("#teaserSlideList .handle .slide").css({cursor:"pointer"}).prepend('<div style="width:740px;" align="left"><div class="slidebg"><'+'/div><'+'/div>')
	.mousedown(function(){
		tmpClick = $(this).offset().left;
	})
	.bind("touchstart",function(e){
		imoveFlg = false;
	})
	.bind("touchmove",function(e){
		imoveFlg = true;
	})
	.bind("touchend",function(e){
		if(!imoveFlg){
			var index = $("#teaserSlideList .handle .slide").index(this);
			openVDO(index);
		}
	})
	.click(function(){
		if(pageLoaded && tmpClick == $(this).offset().left){
			var index = $("#teaserSlideList .handle .slide").index(this);
			openVDO(index);
		}
	});
	$("#teaserSlideList .handle .slidebg").css({opacity:0});
	
	$('#slide_btn').click(function(){
		$('#homeSlideList').show();
		$('#thumbSlide').hide();
		$('#prevBtn').hide();
		$('#nextBtn').hide();			
		$('#hmSlide').animate({left:"0px"},1000,function(){
			$('#thumbSlide').show().css({width:"1px"}).animate({width:740+"px"},1000,function(){
				if($("#thumbSlide .handle .slide").size()>4){
					$('#prevBtn').show().css({opacity:0}).animate({opacity:1},1000);
					$('#nextBtn').show().css({opacity:0}).animate({opacity:1},1000);
				}
			});
		});	
		$('#overlay').show();
	});
	$('#prevBtn').click(function(){
		 nextAndPreviusList(1);
	});
	$('#nextBtn').click(function(){
		 nextAndPreviusList(0);
	});
	$('#overlay').css({opacity:.7,width:$("body").width()+"px",height:$("body").height()+"px"}).hide();
	$('#hmSlide').css({left:$("body").width()+"px"});
	resizesb();
});	

function nextAndPreviusList(delta){	
	///
	var left = ($("#slideshow .handle").offset().left-60)*-1;
	if(delta>0){		
		if(left>0){
			left-= $("#slideshow").width()/2;
		}
	}else{
		if(left<$("#slideshow .handle").width()){
			left+= $("#slideshow").width()/2;
		}
	}
	var x = left/($("#slideshow .handle").width() -$("#slideshow").width());
	slideshow.setValue(x);
}

var teaserSlideList;
// on load
$(window).load(function(){
	pageLoaded = true;
	resizesb();	
	$('#slide_btn').show();
	$('#banner').show();
	$("#newsPanel").show();
	// Slideshow	
	teaserSlideList = new Dragdealer('teaserSlideList',
	{
		steps: $("#teaserSlideList .handle .slide").size(),
		loose: true,
		speed:50,
		animationCallback: function(x, y)
		{			
			if(swfobject.hasFlashPlayerVersion('8.0.0')){
				var left = x * ($("#teaserSlideList .handle").width() - $("#teaserSlideList").width());
				for(var i=0;i<$("#teaserSlideList .handle .slide").size();i++){
					if(Math.ceil(left)==$("#teaserSlideList .handle .slide").width()*i){	
						if(currentStep!=i+1){
							currentStep = i+1;						
							for(var m=1;m<=$("#teaserSlideList .handle .slide").size();m++){							
								if(m==currentStep){
									thisMovie("teaser"+m).goFrame(3);
								}else{
									thisMovie("teaser"+m).stopFrame(2);
								}
							}	
						}
						break;
					}		
				}		
				animateLeft = left;			
			}
		}
	});	
	//
	$("#teaserSlideList").bind(
		'mousewheel',
		function (event, delta) {
			var left = ($("#teaserSlideList .handle").offset().left-50)*-1;
			if(delta>0){
				
				if(left>0){
					left-= $("#teaserSlideList .handle .slide").width();
				}
			}else{
				if(left<$("#teaserSlideList .handle").width()){
					left+= $("#teaserSlideList .handle .slide").width();
				}
			}
			var x = left/($("#teaserSlideList .handle").width() -$("#teaserSlideList").width());
			teaserSlideList.setValue(x);
		}
	);
	// Slideshow	
	var thumbSlide = new Dragdealer('thumbSlide',
	{
		steps: $("#teaserSlideList .handle .slide").size(),
		loose: true
	});	
});	
// on resize
$(window).resize(function(){resizesb();});

function resizesb(){
	$("#teaserSlideList .handle").width($("#teaserSlideList .handle .slide").size()*$("#teaserSlideList .handle .slide").width());
	$("#thumbSlide .handle").width($("#thumbSlide .handle .slide").size()*185);
	
	if($('body').width()<=840){
		$('#homeSlideList, #teaserSlideList, #overlay').css({width:840+"px"});	
		$('#teaserSlideList .handle .slide').css({width:840+"px"});			
		$('#vdoPanel').css({marginLeft: (840-$('#vdoPanel').width())/2+'px'});			
	}else{
		$('#homeSlideList, #teaserSlideList, #overlay').css({width:"100%"});	
		$('#teaserSlideList .handle .slide').css({width:$('body').width()+"px"});	
		$('#vdoPanel').css({marginLeft: ($('body').width()-$('#vdoPanel').width())/2+'px'});	
	}

	if($('body').height()<=600){
		$('#overlay, #teaserSlideList .handle .slide').css({height:600+"px"});	
		$('#homeSlideList').animate({marginTop: (600-185)/2+'px'});	
		$('#slide_btn').animate({marginTop: (600-58)/2+'px'});	
		$('#teaserSlideList').css({marginTop: (600-600)/2+'px'});	
		$('#vdoPanel').css({marginTop: (600-$('#vdoPanel').height())/2+'px'});	
		$('#newsPanel').css({bottom:"auto",top:(600-85)+"px"});	
		$('#banner').css({bottom:"auto",top:(600-170)+"px"});	
	}else{
		$('#overlay, #teaserSlideList .handle .slide').css({height:"100%"});	
		$('#homeSlideList').animate({marginTop: ($('body').height()-185)/2+'px'});	
		$('#slide_btn').animate({marginTop: ($('body').height()-58)/2+'px'});
		$('#teaserSlideList').css({marginTop: ($('body').height()-600)/2+'px'});
		$('#vdoPanel').css({marginTop: ($('body').height()-$('#vdoPanel').height())/2+'px'});	
		$('#newsPanel').css({bottom:"auto",top:($('body').height())-85});	
		$('#banner').css({bottom:"auto",top:($('body').height())-170});	
	}
	$("#teaserSlideList .handle").css({width:$("#teaserSlideList .handle .slide").size()*$("#teaserSlideList .handle .slide").width()+"px"});
}
function resizeondom(){
	if($('body').height()<=600){		
		$('#teaserSlideList').css({marginTop: (600-600)/2+'px'});	
		$('#homeSlideList').css({marginTop: (600-185)/2+'px'});	
		$('#slide_btn').css({marginTop: (600-58)/2+'px'});	
		$('#banner').css({bottom:"auto",top:(600-170)+"px"});	
	}else{
		$('#teaserSlideList').css({marginTop: ($('body').height()-600)/2+'px'});	
		$('#homeSlideList').css({marginTop: ($('body').height()-185)/2+'px'});	
		$('#slide_btn').css({marginTop: ($('body').height()-58)/2+'px'});
		$('#banner').css({bottom:"auto",top:($('body').height())-170});	
	}
}
var openInterval;
function openVDO(num){
	$('#vdoPanel').show();
	$('#overlay').show();
	openInterval = setInterval('setVDO('+num+')',500);
	//window.open(linkList[num],'','');	
}
function setVDO(num){	
	$("#vdoDetailLink").show();
	current = num;
	clearInterval(openInterval);
	if(swfobject.hasFlashPlayerVersion('8.0.0')){		
		thisMovie("vdoPlayer").playVDO(vdoList[num]);
	}else{
		$("#vdodsp").html('<video id="player_video" controls="controls" autoplay="autoplay" width="710" height="400" src="'+vdoMp4List[num]+'" type="video/mp4"><'+'/video>');
	}
}
function openVDOBanner(){
	$('#vdoPanel').show();
	$('#overlay').show();
	openInterval = setInterval('setVDOBanner()',500);
}
function setVDOBanner(){
	$("#vdoDetailLink").hide();
	clearInterval(openInterval);
	if(swfobject.hasFlashPlayerVersion('8.0.0')){		
		thisMovie("vdoPlayer").playVDO(vdoBannerPath);
	}else{
		$("#vdodsp").html('<video id="player_video" controls="controls" autoplay="autoplay" width="710" height="400" src="'+vdoMp4BannerPath+'" type="video/mp4"><'+'/video>');
	}
}
function closeVDO(){
	clearInterval(openInterval);
	if(swfobject.hasFlashPlayerVersion('8.0.0')){	
		try{
			thisMovie("vdoPlayer").stopVDO();
		}catch(e){}
	}else{
		$("#vdodsp").html('');
	}
	$('#vdoPanel').hide();
	$('#overlay').hide();
}
function openUrl(){
	window.open(linkList[current],'','');
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
