// JavaScript Document
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var speed = 3000;
var speed2 = 6000;
var speed3 = 1000;
var marginLeft = 0;
var isRunning = false;
var _index = 0;
var showAboutController = {'about':'', 'social':''};
var hideAboutController = {'about':'', 'social':''};
var hideAboutRunning = {'about':false, 'social':false};
var oHeight;
var Page;
var con = 0;

$(document).ready(function () {
	$('.about').bind('mouseover', {level:'out', status:'about'}, showAboutTimeout);
	$('.about').bind('mouseout', {level:'out', status:'about'}, hideAboutTimeout);
	$('.about ul').bind('mouseover', {level:'in', status:'about'}, showAboutTimeout);
	$('.about ul').bind('mouseout', {level:'in', status:'about'}, hideAboutTimeout);
	
	$('.social').bind('mouseover', {level:'out', status:'social'}, showAboutTimeout);
	$('.social').bind('mouseout', {level:'out', status:'social'}, hideAboutTimeout);
	$('.social ul').bind('mouseover', {level:'in', status:'social'}, showAboutTimeout);
	$('.social ul').bind('mouseout', {level:'in', status:'social'}, hideAboutTimeout);
	
	if ($('.main_container').html() != null) {
		Page = $('.main_container');
		oHeight = Page.height();
	}
	else {
		Page = $('#main_content');
		oHeight = Page.height();
		con = 34;
	}
	windowResizeRun();
	$(window).resize(windowResizeRun);
	
	setTimeout(effectAbout, 250);
});

function windowResizeRun() {
	if ($(window).height() > oHeight) {
		var headerH;
		var obj;
		var footerH;
		Page.children().each(function(i) {
			if ($(this).hasClass('header') || $(this).attr('id') == 'main_banner') {
				headerH = $(this).height();
			}
			else if ($(this).hasClass('main_content') || $(this).attr('id') == 'content') {
				obj = $(this);
			}
			else if ($(this).hasClass('footer')) {
				footerH = $(this).height();
			}
		});
		var height = $(window).height()-headerH-footerH-con;
		obj.css({height:height});
	}
}

function showAboutTimeout(event) {
	try {
		clearTimeout(showAboutController[event.data.status]);
		clearTimeout(hideAboutController[event.data.status]);
	}
	catch(e) {};
	if ($('.'+event.data.status+' ul').is(':hidden') || hideAboutRunning[event.data.status])
		showAboutController[event.data.status] = setTimeout(showAbout, 250, event, $(this));
}

function hideAboutTimeout(event) {
	try {
		clearTimeout(showAboutController[event.data.status]);
		clearTimeout(hideAboutController[event.data.status]);
	}
	catch(e) {};
	if ($('.'+event.data.status+' ul').is(':visible'))
		hideAboutController[event.data.status] = setTimeout(hideAbout, 250, event, $(this));
}

function showAbout(event, _obj) {
	if (event.data.level == 'out') {
		_obj.find('ul').show('blind',300);
	}
	else {
		_obj.show('blind',300);
	}
}

function hideAbout(event, _obj) {
	hideAboutRunning[event.data.status] = true;
	var callBackFuns = function() { hideAboutRunning[event.data.status] = false; };
	
	if (event.data.level == 'out') {
		_obj.find('ul').hide('blind',300, callBackFuns);
	}
	else {
		_obj.hide('blind',300, callBackFuns);
	}
}

function effectAbout() {
	$('.about ul').hide().css({visibility:'visible'});
	$('.social ul').hide().css({visibility:'visible'});
}

function loadBanner() {
	fadeInAllObj('.layer1 .first_banner2 div:not(".green")', 300, 1000);
}

function setBannerPosition() {
	if (isRunning)
		return false;
	if ($(window).width() > 1002) {
		var bannerLeft = ($(window).width()-1002)/2;
		$('#main_banner .bannerLayer').each(function(index) {
			if (marginLeft < bannerLeft) {
				$(this).css({'left':($(this).position().left+bannerLeft-marginLeft)});
				if ($('#main_banner .bannerLayer').length-1 == index)
					marginLeft += (bannerLeft-marginLeft);
				
			}
			else if (marginLeft > bannerLeft) {
				$(this).css({'left':($(this).position().left-(marginLeft-bannerLeft))});
				if ($('#main_banner .bannerLayer').length-1 == index)
					marginLeft -= (marginLeft-bannerLeft);
			}
		});
	}
	else {
		$('#main_banner .bannerLayer').each(function(index) {
			bannerLeft = $(this).position().left;
			$(this).css({'left':($(this).position().left-marginLeft)})
		});
		marginLeft = 0;
	}
	
	var layer = 40;
	if (marginLeft < layer) {
		layer = 0;
	}
	$('#main_banner .layer_left').css({width:marginLeft-layer});
	$('#main_banner .layer_right').css({width:marginLeft-layer});
}

function fadeInAllObj(place, _speed, _speed2, index) {
	if (!isSet(index))
		var index = 0;
	if (isSet($(place+':eq('+index+')').html())) {
		if (isSet($(place+':eq('+(index+1)+')').html())) {
			$(place+':eq('+index+')').fadeIn(_speed2);
			setTimeout(fadeInAllObj, _speed, place, _speed, _speed2, (index+1));
		}
		else {
			$(place+':eq('+index+')').fadeIn(_speed2, function() { fadeInAllObjCallBack(); });
		}
	}
}

function isSet(variable) {
	return( typeof( variable ) != 'undefined'  && variable != null);
}

function fadeInAllObjCallBack() {
	$('.layer1 .first_banner2 .green:not(".last")').fadeIn(2000);
	
	$('.layer1 .first_banner2 .green.last').fadeIn(2000, function() {
		$('.main_menu').fadeIn(4000, function() { firstRun(); });
	});
}

function firstRun() {
	isRunning = true;
	$("#main_banner .layer1").animate({left:"-=5000"}, speed);
	$("#main_banner .layer2").animate({left:"-=4200"}, speed);
	$("#main_banner .layer3").animate({left:"-=3700"}, speed, function () { 
		isRunning = false;
		setBannerPosition();
		$('.layer3 .layercon:first').show('slide', { direction: "down" }, speed3, function () {
			setTimeout(runBanner, speed2);
		});
	});
}

function runBanner() {
	isRunning = true;
	_index++;
	$('.layer3 .layercon:eq('+(_index-1)+')').fadeOut(speed3);
	
	
	if (_index != 4) {
		var layer1 = "-=3869";
		var layer2 = "-=2869";
		var layer3 = "-=1018";
	}
	else {
		var layer1 = "-=8869";
		var layer2 = "-=7069";
		var layer3 = "-=4718";
	}
	
	
	$("#main_banner .layer1").animate({left:layer1}, speed);
	$("#main_banner .layer2").animate({left:layer2}, speed);
	$("#main_banner .layer3").animate({left:layer3}, speed, function () { 
		if (_index == 4) {
			$('.first_banner2 div').hide();
			$("#main_banner .layer1").css({left:(-3869+marginLeft)});
			$("#main_banner .layer2").css({left:(-2869+marginLeft)});
			$("#main_banner .layer3").css({left:(-1098+marginLeft)});
			$('.layer3 .layercon:last').hide();
			_index = 0;
			loadBanner();
		}
		else {
			$('.layer3 .layercon:eq('+_index+')').show('slide', { direction: "down" }, speed3, function () {
				setTimeout(runBanner, speed2);
			});
		}
		isRunning = false;
		setBannerPosition();
	});
}

function fixPng(){
 if(isIE()){
  $(".fixPNGFilter").each(function(){
   var obj = $(this).children();
   var src=obj.attr("src");
   var width=obj.attr("imgWidth");
   var height=obj.attr("imgHeight");
   var objDiv = $('<div></div>').css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"')", width:width, height:height});
   $(this).html(objDiv);
  })
 }
}

function isIE(){//ie7以下版本测试：在这里只对IE6作最低分界，兼容其它各mozila4.0+浏览器
 if(window.navigator.userAgent.toLowerCase().indexOf("msie")!=-1){
  return true;
 }else{
  return false;
 }
}

function popupWindow() {
	window.open ("disclaimer_privacy_policy.html", "mywindow", "menubar=no,resizable=no,width=550,height=450");
}
