$(document).ready(function(){
	$('body').each(function(){
		var m=5;
		var n=Math.floor(Math.random()*m+1) 
		switch(n){
			case 1:
				$(this).css({backgroundImage:'url(images/f01.gif)'})
				break;
			case 2:
				$(this).css({backgroundImage:'url(images/f02.gif)'})
				break;
			case 3:
				$(this).css({backgroundImage:'url(images/f03.gif)'})
				break;
			case 4:
				$(this).css({backgroundImage:'url(images/f04.gif)'})
				break;
			case 5:
				$(this).css({backgroundImage:'url(images/f05.gif)'})
				break;
		}
	});
	var doch=document.documentElement.clientHeight;
	var docw=document.body.clientWidth;
	$('body').bind('copy',function(){
		window.clipboardData.setData('text','上海墨攻文化传播有限公司[http://www.mogul.com.cn]');
		return false;
	});
	$('.imglist').each(function(){
		var p=$(this).attr('p');
		var c=$(this).attr('c');
		$(this).ajaxStart(function(){
			$(this).html('<img src="images/1-1.gif" align="absmiddle" /> 正在加载图片列表...');
		});
		$(this).load('img.asp?t='+new Date().getTime(),{p:p,c:c},function(msg){
			imgwrap=function(){
				$('.thumb').each(function(i){
					var me=$(this);
					var top=me.offset().top;
					var left=me.offset().left;
					var w=me.width();
					var h=me.height();
					var s=me.attr('src');
					if(w>h){
						me.height(150);
						me.css({marginTop:-75,marginLeft:-(me.width()/2)});
					}else{
						me.width(150);
						me.css({marginTop:-(me.height()/2),marginLeft:-75});
					};
					me.wrap('<div class="wrap"></div>');
					$('<img src="images/blank.gif" class="blank" />').insertBefore(me);
					if(!((i+1)%4)){
						me.parent('.wrap').css({marginRight:0});
					};
					me.animate({opacity:'toggle'},500);
					setTimeout(function(){
						me.animate({opacity:'0.75'},1000);
					},1000);
					me.prev('.blank').hover(function(){
						me.parents('.wrap').css({'filter':'none'});
						me.animate({opacity:'1'},500);
					},function(){
						me.parents('.wrap').css({'filter':'gray'});
						me.animate({opacity:'0.75'},500);
					});
					me.prev('.blank').each(function(i){
						var blank=$(this);
						var blankIndex=$('*').index(blank[i]);
						var st=blank.offset().top;
						var sl=blank.offset().left;
						var sw=blank.width();
						var sh=blank.height();
						$(this).click(function(){
							var docah=document.body.scrollHeight;
							var docs=document.documentElement.scrollTop || document.body.scrollTop;
							$('.imgStr,.imgBg').remove();
							$('body').append('<div class="imgBg" id="imgBg'+blankIndex+'"></div>');
							$('#imgBg'+blankIndex).css({width:sw,height:sh,top:st,left:sl,opacity:'0.5'});
							$('#imgBg'+blankIndex).animate({width:w,height:h,top:doch/2-h/2+docs,left:docw/2-w/2},600,function(){
								$('body').append('<img src="images/blank.gif" class="imgStr" style="background:url('+s+');" alt="单击关闭" />');
								$('.imgStr').css({left:docw/2-w/2-8,top:doch/2-h/2+docs-8,width:w,height:h});
								$('.imgStr').animate({opacity:'toggle'},300);
								$('.imgStr,.imgBg').click(function(){
									$('.imgStr').animate({opacity:'toggle'},300,function(){
										$(this).remove();
										$('.imgBg').animate({width:sw,height:sh,top:st,left:sl,opacity:'toggle'},600,function(){
											$(this).remove();
										});
									});
								});
							});
						});
					});
				});
			};
			imgComplete1=function(s){
				var a=true;
				if(s==false){
					var img=$(this).find('img');
					for(i=0;i<img.length;i++){
						if(img[i].readyState!="complete"){
							a=false;
							break;
						};
					};
				};
				//alert(a);
				if(a==true){
					imgwrap();
				}else{
					setTimeout("imgComplete1("+a+")",100);
				};
			};
			imgComplete1(false);
		});
	});
	imgComplete=function(s){
		var a=true;
		if(s==false){
			var img=$('.page img');
			for(i=0;i<img.length;i++){
				if(img[i].readyState!="complete"){
					a=false;
					break;
				};
			};
		};
		if(a==true){
			$('#loading').remove();
			$('.page').animate({opacity:'toggle'},2000);
		}else{
			setTimeout("imgComplete("+a+")",100);
		};
	};
	imgComplete(false);
	$('a').focus(function(){
		this.blur();
	});
	setTimeout(function(){
		$('.logo').animate({top:0},800);
	},800);
	setTimeout(function(){
		$('#Advertisement').css({'width':13,'height':1,opacity:'toggle'});
		$('#Advertisement').animate({height:261},1200);
	},1200);
	$('#menu').Fisheye({
		maxWidth: 40,
		items: 'a',
		itemsText: 'span',
		container: '.fisheyeContainter',
		itemWidth: 80,
		proximity: 80,
		halign : 'center'
	});
	$('#menu a').each(function(){
		var me=$(this)
		var t=me.attr('title');
		me.removeAttr('title');
		me.hover(function(){
			$('#mTip').html(t);
			$('#mTip').show();
		},function(){
			$('#mTip').hide();
		});
		me.mousemove(function(){
			var x=mousePos.x-23;
			$('#mTip').css({left:x});
			
		});
	});
	//$('#smenu a').animate({opacity:'0.5'},300);
	//$('#smenu a').hover(function(){
	//	$(this).animate({opacity:'1'},300);
	//},function(){
	//	$(this).animate({opacity:'0.5'},300);
	//});
	$('#movetop').each(function(){
		$(this).click(function(){
			scroll(0,0);
		});
		for(i=0;i<10;i++){
			$(this).animate({opacity:'toggle'},300);
		};
	});
	$(window).scroll(function(){
		var y=document.documentElement.scrollTop || document.body.scrollTop;
		$('.logo').css({'top':y});
		$('#Advertisement').css({'top':y+150});
		$('#movetop').css({'top':y+336});
	});
	$(document).PngForIE({
		AutoSize:true,
		ReplacImg:'images/mblank.gif'
	});
	$('#myform').submit(function(){
		var to=$(this).find('input[@name=to]').val();
		var nn=$(this).find('input[@name=name]').val();
		var add=$(this).find('input[@name=add]').val();
		var fax=$(this).find('input[@name=fax]').val();
		var tt=$(this).find('input[@name=tel]').val();
		var ee=$(this).find('input[@name=email]').val();
		var ss=$(this).find('input[@name=web]').val();
		var mm=$(this).find('textarea[@name=message]').html();
		if(nn==''){
			alert('请填写您的姓名！');
			$(this).find('input[@name=name]').focus();
			return false;
		}else if(tt==''){
			alert('电话号码不能为空，以便我们可以及时与您联系！');
			$(this).find('input[@name=tel]').focus();
			return false;
		}else if(ee==''){
			alert('电子信箱必须填写，以便我们可以及时与您联系！');
			$(this).find('input[@name=email]').focus();
			return false;
		}else if(mm==''){
			alert('留言的内容不能为空！');
			$(this).find('input[@name=message]').focus();
			return false;
		};
		$.post('guestbook.asp',{
			to:to,
			add:add,
			fax:fax,
			name:nn,
			tel:tt,
			email:ee,
			web:ss,
			message:mm
		},function(data){
			alert('非常感谢您的留言，我们会尽快与您联系！');
			$('#myform input').val('');
			$('#myform textarea').html('');
		});
		return false;
	});
	$('.sub a[@show!=""]').each(function(){
		var me=$(this);
		var show=me.attr('show');
		me.click(function(){
			$('.zpshow').hide();
			$('#'+show).animate({opacity:'toggle'},300);
		});
	});
	$('.sub a[@show!=""]:first').click();
});
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {
			x:ev.pageX, y:ev.pageY
		};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop - document.body.clientTop
	};
};
function mouseMove(ev){
	ev = ev || window.event;
	return mousePos = mouseCoords(ev);
};
document.onmousemove = mouseMove;
function killErrors() {
return true;
}
window.onerror = killErrors;
