﻿$(document).ready(function(){
	var lang=$.cookies('Lang');
	$('#lang a[href$="'+lang+'"]').hide();
	$('#lang font').text($('#lang a[href$="'+lang+'"]').text());
	if(lang=='cn'){
		$('#lang font').addClass('cn');
	}else{
		$('#lang font').removeClass('cn');
	};
	$('#lang span').hover(function(){
		$(this).addClass('mouseover');
	},function(){
		$(this).removeClass('mouseover');
	});
	$('#footer').each(function(){		   
		if(parseInt($('body').height())<parseInt($.clientHeight())){
			$(this).css({position:'absolute',bottom:0});
		};
	});
	$('.prolist').each(function(){
		$(this).css('margin-top',($.clientHeight()-$(this).height()*2)/2);
	});
	$('.marquee').each(function(i){
		var me=$(this);
		var test=setInterval(function(){
				var images=me.find('img[ready=false]');
				images.each(function(){
					var _self=$(this);
					_self.hide();
					var img=new Image();
					$(img).load(function(){
						_self.attr({'src':_self.attr('src'),'ready':true});
					}).attr('src',_self.attr('src'));
				});
				if(me.find('img[ready=false]').length==0){
					me.css({background:'none'});
					var m1=me.wrapInner('<span id="m1'+i+'"></span>').attr('id','m0'+i).contents();
					var m2=m1.after('<span id="m2'+i+'">'+m1.html()+'</span>');
					var speed=20;
					var marquee=function(){
						if(document.getElementById('m2'+i).offsetWidth-document.getElementById('m0'+i).scrollLeft<=0){
							document.getElementById('m0'+i).scrollLeft-=document.getElementById('m1'+i).offsetWidth;
						}else{
							document.getElementById('m0'+i).scrollLeft++;
						};
					};
					me.find('img').fadeIn();
					var mymar=setInterval(marquee,speed);
					me.hover(function(){
						clearInterval(mymar);
					},function(){
						mymar=setInterval(marquee,speed);
					});
					clearInterval(test);
				};
			},800);
	});
	$('.prev,.next').each(function(){
		$(this).css('top',$.clientHeight()/2);
	});
	$(document).click(function(){
		if($('.mask:visible').length>0){
			$('.proinfo img,.proinfo span').fadeOut(function(){
				$('.mask').hide();
			});
		};
		$('.submenu:visible').fadeOut();
	});
	$('.prolist a').live('click',function(){
		var src=$(this).find('img').attr('src');
		var text=$(this).attr('title');
		$('.mask').css({width:$.htmlWidth(),height:$.htmlHeight()}).show();
		$('.proinfo img').attr('src',src).fadeIn();
		$('.proinfo span').text(text).fadeIn();
		$('.proinfo').center();
		return false;
	});
	$('.zs img').click(function(){
		$(this).imgshow({mask:true,maskalpha:0.5,borderColor:'#000000'});
	});
	$('.proclass').mouseover(function(){
		var me=$(this);
		var sid=me.attr('sid');
		var offset=me.offset();
		var x=offset.left;
		var y=offset.top+25;
		var w=me.width();
		var h=me.height();
		var toH=$('#submenu'+sid).innerHeight();
		var toX=x-(160-w/2);
		$('.submenu').hide();
		$('#submenu'+sid+' div').hide();
		$('#submenu'+sid)
			.css({left:x,top:y,width:w,height:h})
			.show()
			.animate({width:320,height:toH,left:toX},300,function(){
				$('#submenu'+sid+' div').fadeIn();
			});
		return false;
	});
	$('.submenu').bind('mouseleave',function(){
		$(this).fadeOut();
	});
	$('.off').click(function(){
		return false;
	});
});
