﻿jQuery.extend( jQuery.easing,{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});
jQuery.fn.times = function(fn,t){
	var time,self = this,start=0,end=this.length,ox;
		
	function run(){
		if(start < end){
			ox = fn.apply(self.get(start),[start]);
			if(typeof ox != 'boolean' || ox != false){
				start++;
				setTimeout(run,t ? t : 0);
			}
		}
	}
	run();
	return this;
};
$.loop = function( fn,time ){
	var TIME = setInterval(function(){
		var l = fn();
		if( typeof l == 'boolean' && !l ){
			clearInterval(TIME);
		}
	},time ? time : 100);
	return TIME;
};
jQuery.fn.mouseScroll = function( fn ){
	return this.each(function(){
		var self = this;
		function wheel(event){
			var e = event || window.event;
			e.delta = e.wheelDelta ? ( -e.wheelDelta / 120 ) : (e.detail / 3);
			e.stopPropagation ? '' : e.stopPropagation = function(){ e.cancelBubble = true;};
			!e.layerX ? e.layerX = e.offsetX : '';
			!e.layerY ? e.layerY = e.offsetY : '';
			fn.apply(self,[e])
			return false;
		}
		typeof this.onmousewheel == 'undefined' ? this.addEventListener("DOMMouseScroll", wheel, false) : this.onmousewheel = wheel;
	});
};
$.fn.draggle = function( option,fn ){
	return this.each(function(){
		var self = $(this);
		var def = {
			cursor : 'move'
		};
		$.extend(def,option);
		def.rect ? self.css({left : def.rect[0] + 'px',top : def.rect[1] + 'px'}) : self.css({left : self[0].offsetLeft + 'px',top : self[0].offsetTop + 'px'});
		self.css({position : 'absolute'});
		var hWnd = def.header ? self.find(def.header) : self;
		def.parentHWND ? hWnd = hWnd.add(self.parents(def.parentHWND)) : '';
		var draw,mx,my,ml,mt,left,top,ydraw;
		self.bind('mousedown',function(){
			if(def.index && def.index == 'auto'){
				$.fn.draggle.prototype.index ? ++$.fn.draggle.prototype.index : $.fn.draggle.prototype.index = 100;
				self.css({zIndex : $.fn.draggle.prototype.index});
			};
		});
		hWnd[0].onselectstart = function(){return false};
		hWnd.css({cursor : def.cursor,'-moz-user-select':'-moz-none'})
		.bind('mousedown',function(e){
			e.stopPropagation();
			if($(e.target).attr('tagName').toUpperCase() != 'A'){
				draw = true;
				mx = e.clientX;
				my = e.clientY;
				ml = parseInt(self.css('left'));
				mt = parseInt(self.css('top'));
			}
			return false;
		});
		$(document).bind('mousemove',function(e){
			if(draw){
				if(fn && fn.call(hWnd) === false) return;
				ydraw = true;
				left = (def.limit && def.limit == 'x') || !def.limit ? ml + e.clientX - mx : ml;
				top = (def.limit && def.limit == 'y') || !def.limit ? mt + e.clientY - my : mt;
				
				if(def.rect){
					left < def.rect[0] ? left = def.rect[0] : '';
					left > def.rect[2] ? left = def.rect[2] : '';
					top < def.rect[1] ? top = def.rect[1] : '';
					top > def.rect[3] ? top = def.rect[3] : '';
				}
				self.css({
					left : left + 'px',
					top : top + 'px'
				});
				def.move ? def.move.apply(self,[e,{left : left,top : top}]) : '';
			}
			return false;
		})
		.bind('mouseup',function(e){
			draw = false;
			if(ydraw){
				ydraw = false;
				def.stop ? def.stop.apply(self,[e,{left : left,top : top}]) : '';
			}
		});
	});
}
$(function(){
	
	var add = $('#addcol');
	var src = window.location.href;
	var animate = true;
	add.bind('click',function(){
		if($.browser.msie){
			window.external.addFavorite(src, '玩具世界'); 
		}else{
			window.sidebar.addPanel('玩具世界', src, ""); 
		}
	});
	
	var marquee = $('#marquee #sdf').width(760);
	var fW = 40;
	var str = "欢迎参展、参观";
	var fW = 40;
	var fL = (760 - str.length * fW) / 2;
	for(var i = 0,j = str.length;i < j;i++){
		$('<a/>').appendTo(marquee).html(str.substring(i,i+1)).css({fontSize:'30px',position:'absolute',left:(i*fW+fL)+'px',top:'20px'});
	}
	
	var $f = marquee.find('a');
	$.loop(function(){
		$f.times(function(i){
			$(this).css({left:(i*fW+fL)+'px',fontSize:'60px'}).show().animate({left:(i*fW+fL),fontSize:'30px'},'easeInOutElastic');
			if(i == $f.length - 1){
				$.loop(function(){
					$f.times(function(){
						$(this)
						.animate({top:-50},200).animate({top:20},400);
						
					},100);
					return false;
				},200);
			}
		
		},100);
	},4000)
	var ul;
	$('#menu > li').each(function(){
		var height;
		$(this).bind('mouseenter',function(){
			ul = $(this).find('ul');
			if(ul.length > 0){
				if(!height){
					height = ul.height();
					ul.height(0);
				}
				ul.stop().show().animate({height : height});
			}
		}).bind('mouseleave',function(){
			if(ul.length > 0){
				ul.stop().animate({height:0},function(){$(this).hide()});
			}
		});
	});
	
	$.loop(function(){
		if($('#bzh').is(':visible')){
			$('#bzh').hide().next().slideDown('slow');
		}else{
			$('#bzh').next().hide().prev().slideDown('slow');
		}
		
	},5000);
	
	var images = $('img.plan'),st;
	if(images.length > 0){
		var bg = $('<div/>').hide().appendTo('body').css({position:'absolute',left:'0px',width:$(document).width()+'px',top:'0px',opacity:0.5,backgroundColor:'#000'})
		var w = $(document).width() - 100;
		document.onselectstart = function(){return false;};
		var img = $('<img/>').bind('mousedown',function(e){return false;}).draggle({},function(){
			if(this.css('cursor') != 'move'){
				return false;
			}
		}).hide().appendTo('body').attr({width:w}).css({position:'absolute',top:'20px',left:(($(document).width()-w)/2)+'px'}).mouseScroll(function(e){
			e.stopPropagation();
			var width = $(this).width();
			var height = $(this).height();
			var c = 30,v = c * height / width;
			var w = width - c * e.delta,h = height - v * e.delta;
			var left = parseInt($(this).css('left')) + Math.round(c / width * e.layerX) * e.delta;
			var top = parseInt($(this).css('top')) + Math.round(v / height * e.layerY) * e.delta;
			$(this).css({width:w+'px',height:h+'px',left:left+'px',top:top+'px'});
			return false;
		}).bind('click',function(){
			if($(this).css('cursor') == 'pointer'){
				
				img.hide();
				bg.hide();
			}
		}).css({cursor:'pointer'});
		$(document).bind('keydown keyup',function(e){
			if(e.keyCode == 32){
				if(e.type == 'keydown')
					img.css({cursor:'move'});
				else
					img.css({cursor:'pointer'});
				return false;
			}
		});
		images.each(function(){
			$(this).css({cursor:'pointer'}).bind('click',function(){
				bg.show().css({height:$(document).height()+'px'});
				var src = $(this).attr('src');
				st = $(document).scrollTop();
				var h = $(this).height() / $(this).width() * w;
				img.attr({src:src}).show().css({top : (st + $(window).height() / 2)+'px',left:$(document).width() / 2 + 'px',width:'0px',height:'1px'})
				.animate({left:($(document).width() - w) / 2 + 'px',width:w+'px'},1000).animate({top : (st + 20) + 'px',height:h+'px'},1000);

			})
		});	
	}
	$('#zxzx').html('loading...');
	$.getScript("toysworld.php",function(msg){
		$('#zxzx').html(msg);
	})
	
	$('table div,table font,#lw font').each(function(){
		this.contentEditable = true;
		$(this).css({padding:'5px 0'});
	});
	var b = $('<div/>').hide().appendTo('body').css({position:'absolute',left:'0px',width:$(document).width()+'px',top:'0px',opacity:0.5,backgroundColor:'#000'});
	
	var tips = function( msg,hide ){
		var tp = $('#tips_ycl');
		if(tp.length == 0){
			tp = $('<div/>').appendTo('body').attr('id','tips_ycl').css({ position : 'fixed',zIndex : 100, top: '0px', height: '18px', lineHeight: '18px', padding: '2px', paddingRight: '10px', left: '0px', backgroundColor: '#f9e99d' });
		}
		tp.html(msg).show();
		this.tipsTime ? clearTimeout(this.tipsTime) : '';
		hide ? this.tipsTime = setTimeout(function(){tp.hide()},6000) : '';
		return tp;
	}
	$('#byer,#byer1').click(function(){
		b.show().css({height:$(document).height()});
		tips("邮件发送中...");
		$('#byertable *[jQuery]').removeAttr('jQuery');
		$("input[type=checkbox]").each(function(){
			if($(this).attr('checked')){
				$(this).attr('ddd','t');
			}
		});
		var content = $(this).prev('font').html();
		var title = $(this).attr('title');
		
		$.ajax({
			type:'post',
			url:'smtp/send.php',
			data:{content:content,title:title},
			success:function(s){
				if(s==1){alert("邮件发送成功");tips("邮件发送成功...",true);}
				else{tips("邮件发送失败...",true);alert('发送失败')}
				b.hide();
			}
		});
		return false;
	});
	$('#zuixindt').html('loading...').load('zuixin.php');
});