﻿$(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;
	});
	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);
	//});
	$(window).scroll(function(){
		var y=document.documentElement.scrollTop || document.body.scrollTop;
		$('.logo').css({'top':y});
		$('#Advertisement').css({'top':y+150});
		$('.worksStr').css({marginTop:-(275-y)});
	});
	$(document).PngForIE({
		AutoSize:true,
		ReplacImg:'images/mblank.gif'
	});
	//文件列表
	var fold=$('#workslist').attr('path');
	$.ajax({
		type	: 'get',
		url		: 'folder.asp',
		data	: 'f='+fold+'&timer='+new Date().getTime(),
		success	: function(msg){
			$('#workslist').append(msg);
			var imglist=$('.imglist');
			imglist.each(function(i){
				var me=$(this);
				var imgsrc=$(this).attr('src');
				$(this).css({width:120,height:120,'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+imgsrc+'", sizingmethod=scale) gray alpha(opacity=75)'});
				$(this).attr('src','images/blank.gif');
				$(this).hover(function(){
					$(this).css({opacity:'1','filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+imgsrc+'", sizingmethod=scale) alpha(opacity=100)'});
				},function(){
					$(this).css({opacity:'0.75','filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+imgsrc+'", sizingmethod=scale) gray alpha(opacity=75)'});
				});
				me.click(function(){
					var p=me.attr('path');
					var h=document.body.scrollHeight;
					var w=document.body.scrollWidth;
					var sh=document.documentElement.scrollTop || document.body.scrollTop;
					$('.worksStr,.worksBg').remove();
					$('body').append('<div class="worksBg"></div><div class="worksStr"><div class="worksTit"><a href="close" title="关闭">&times;</a><div class="worksList"></div><div class="worksShow"></div></div></div><div class="imgloading"><div>正在载入图片列表，请稍候...</div></div>');
					$('.worksBg').css({width:w,height:h});
					$('.worksStr').css({marginTop:-(275-sh)});
					$('.imgloading').css({marginTop:-(256-sh)});
					$('.worksTit a').click(function(){
						$('.worksStr,.worksBg').remove();
						return false;
					});
					$('.imgloading').show();
					$.ajax({
						type	: 'get',
						url		: 'files.asp',
						data	: 'file='+p+'&fold='+fold+'&timer='+new Date().getTime(),
						success	: function(msg){
							$('.worksList').html(msg);
							$('.worksList img[@src*=logo]').parent().insertBefore($('.worksList a:first'));
							imglist=function(){
								$('.worksList img').each(function(){
									var w=$(this).width();
									var h=$(this).height();
									var workimg=$(this).attr('src');
									$(this).css({width:60,'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+workimg+'", sizingmethod=scale)'});
									$(this).attr('src','images/blank.gif');
									$(this).click(function(){
										if($('.worksList img').length>16){
											var thish=h/2+sh;
											var mh=mousePos.y;
											var th=Math.round($('.worksList img').length/2)*64;
											if(mh>thish){
												$('.worksList').find('div').animate({top:512-th},800);
											}else{
												$('.worksList').find('div').animate({top:0},800);
											};
										};
										$('.worksShow').html('<img src="images/blank.gif" />');
										$('.worksShow img').css({width:w,height:h,'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+workimg+'", sizingmethod=scale)'});
									});
								});
								$('.worksList img:first').click();
							};
							imgComplete1=function(s){
								var a=true;
								if(s==false){
									var img=$('.worksList img');
									for(i=0;i<img.length;i++){
										if(img[i].readyState!="complete"){
											a=false;
											break;
										};
									};
								};
								if(a==true){
									$('.imgloading').hide();
									imglist();
								}else{
									setTimeout("imgComplete1("+a+")",50);
								};
							};
							imgComplete1(false);
						}
					});
				});
			});
			$(document).keydown(function(event){
				$('#search').focus();
				if(event.keyCode==27){
					$('#search').val('');
					$('.list').remove();
				};
			});
			$('#search').keyup(function(){
				var text=$(this).val();
				if(text.length>0){
					var s=$('#workslist div').contains(text);
					var n=$('#workslist div').not(s);
					n.removeClass('click');
					s.addClass('click');
				}else{
					$('#workslist div').removeClass('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;
