if(!window.wm){
	var wm = window.wm = {
	author:'Lichen.Zhou',
	version:'1.0',
	time:'2009-09-23',
	error:'',
	toerror:function(){},
	showerror:function(){},
	debug:function (){
			var w = window.location.href;
			if(w.indexOf('?') == -1){ return false;}
			w = w.substr(w.indexOf('?')+1,w.length);
			var arr = w.split("&");
			var pa = [];
			if(pa.length){return false;}
			for(var i in arr){ var p = arr[i].split("="); pa.push({name:p[0],value:p[1]}); }
			return pa;
		}
	}	
}

(function(){

var def = function(){ return {
	css:{top:66,left:0},
	src:'http://www.wanmei.com/public/images/alpha.gif',
	href:'#',
	alt:"",
	width:100,
	height:300,
	target:'_blank',
	type:'A',
	tyw:16,
	tyh:16,
	tpurl:'http://www.wanmei.com/public/images/clos.gif',
	iscol:'yes',
	ef:'yes',
	start:false,
	end:false,
	seat:'body',
	time:0,
	sl:false
}}

function timePlan(str){
	if(!str){return false;}
	if(typeof(str) != 'string'){return false;}
	var t = str.split("|");
	for(var z in t){ t[z]=parseInt(t[z]); }
	var tt = new Date();
	if(t[0]){tt.setFullYear(t[0]);}else{return false}
	if(t[1]){tt.setMonth(t[1]-1)}else{tt.setMonth(0);}
	if(t[2]){tt.setDate(t[2]);}else{tt.setDate(1);}
	if(t[3]){tt.setHours(t[3]);}else{tt.setHours(0);}
	if(t[4]){tt.setMinutes(t[4]);}else{tt.setMinutes(0);}
	if(t[5]){tt.setSeconds(t[4]);}else{tt.setSeconds(0);}
	return tt;
}

function BWTime(str,end){
	if(!str && !end){ return 1;}
	var thisT = (new Date()).getTime();
	if(!str){ if(end.getTime() >= thisT ){ return 1;}else{return -1;} }
	if(!end){ if(str.getTime() <= thisT ){ return 1;}else{return -1;} }
	if(str.getTime() <= thisT && end.getTime() >= thisT){return 1;}else{return -1;}
	return false;
}

function getcss(obj,c){
		var zy = '';
		var sx = '';
		if(obj.left || obj.left === 0){
			zy = c === 'z'? 'left:0px; ':'right:0px; ';
			zy = c === 'f'? 'right:0px; ':'left:0px; ';
			}else{
			zy =  c === 'z'? 'right:0px; ':'left:0px; ';
			zy =  c === 'f'? 'left:0px; ':'right:0px; ';
		}
		if(obj.top || obj.top === 0){
			sx =  c === 'z'? 'top:0px; ':'bottom:0px; '; 
			sx =  c === 'f'? 'bottom:0px; ':'top:0px; '; 
		}else{
			sx =  c === 'f'? 'top:0px; ':'bottom:0px; '; 
			sx =  c === 'z'? 'bottom:0px; ':'top:0px; '; 
		}
		return zy + sx;
	}

function ggCreat(obj,cs){
	var de = def() || {};
	jQuery.extend(de,obj);
	if(BWTime(timePlan(de.start),timePlan(de.end)) == -1){ return false;}
	var ty = de.src;
	ty = ty.indexOf('?') == -1 ? ty : ty.substr(0,ty.indexOf('?'));
	ty = ty.substring(ty.lastIndexOf('.')+1,ty.length);
	var div = "ggdt"+Math.floor(Math.random()*100000);
	var coltp = "";
	switch (de.type){
		case 'B':
		coltp += 'display:block; width:100%; ';
		de.height += de.tyh;
			break;
		default:
		coltp += 'position:absolute; z-index:4005; width:'+de.tyw+'px; right:0px; top:0px;';
	}
	
	
	var cssz = getcss(de.css,'z');
	var cssf = getcss(de.css,'f');
	
	var str = '<div id="'+div+'" style="position:absolute; height:'+de.height+'px; width:'+de.width+'px; z-index:3999; overflow:hidden;" zt="yes" zf="yes">';
	if(ty == 'swf'){
		//position:absolute; '+cssz+' 
		str += '<div style="position:absolute; '+cssz+' height:'+de.height+'px; width:'+de.width+'px;"><embed src="'+de.src+'" width="'+de.width+'" height="'+de.height+'" title="'+de.alt+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed></div>';
		}else{
		str += '<a href="'+de.href+'" target="'+de.target+'" ><img src="'+de.src+'" alt="'+de.alt+'" width="'+de.width+'" height="'+de.height+'" border="0" class="gg_pinminim" /></a>';
	}
	if(de.iscol == 'yes'){
		str += '<span style="'+coltp+' height:'+de.tyh+'px; background:#CCC url('+de.tpurl+') no-repeat right 0px; cursor:pointer;" class="'+cs+' colhenbuss"></span>';
	}
	
	if(de.sl){
		var slin = de.sl;
		str += '<span class="corn'+cs+' sonoslpz" style="position:absolute; '+cssz+' width:'+slin.width+'px;height:'+slin.height+'px; zindex:3999;  cursor:pointer; display:none;"><img src="'+slin.src+'" width="'+slin.width+'" height="'+slin.height+'" /></span>';
		var opdidg = 'background:url('+slin.corner+') no-repeat left bottom; _background:none; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+slin.corner+',sizingMethod=scale);';
		
		str += '<span class="jiao'+cs+' jiaoslpz" style="position:absolute; '+cssf+' width:50px; height:50px; zindex:4998; '+opdidg+' cursor:pointer;"></span>';
	}
	//'
	str += '</div>';
	var sea = de.seat;
	if(typeof(sea) == 'string'){ jQuery('body').append(str);}
	if(typeof(sea) == 'object'){ sea.append(str);}
	var di = jQuery('#'+div);
	di.css(de.css).data('xx',{width:de.width,height:de.height,bg:de.tyw,sm:de.tyh,ef:de.ef,gg:de.sl});
	di.data('jao',de.sl);
	if(de.time){ setTimeout(function(){ if(!de.sl){ colEven(di);}else{ if(di.attr('zf') != 'no'){jaoEven(di);}} },de.time); }
	return di;
}

function colEven(n){
	var da = n.data('xx');	
	var zt = n.attr('zt');
	if(zt == 'yes'){
		if(da.ef == 'yes'){
		n.animate({ width: da.bg}, 200 );
		n.find('.gg_pinminim').animate({opacity: "0.1"}, 200 );
		n.find('span').css({ 'background-position':'right -16px'});
		}else{ n.hide();}
		n.attr('zt','no');
	}else{
		if(da.ef == 'yes'){
		n.animate({ width: da.width}, 200 );
		n.find('.gg_pinminim').animate({opacity: "1"}, 200 );
		n.find('span.colhenbuss').css({ 'background-position':'right 0px'});
		}else{ n.show();}
		n.attr('zt','yes');	
	}
}

function jaoEven(n){
	var da1 = n.data('jao');	
	var da = n.data('xx');	
	var zt = n.attr('zf');
	if(zt == 'yes'){
		n.animate({ width: da1.width,height:da1.height}, 220,function(){
																	  
			n.find('span.sonoslpz').show();
			n.find('span.jiaoslpz,span.jiaoslpz img').hide();
		});
		/*n.find('span.jiaoslpz,span.jiaoslpz img').animate({ width: da.width,height:da.height}, 160 , function(){
		}).animate({ width:50,height:50}, 160,function(){})	*/
		n.attr('zf','no');
	}else{
		n.find('span.sonoslpz').hide();	
		n.find('span.jiaoslpz,span.jiaoslpz img').show();	
		n.animate({ width:da.width,height:da.height}, 220,function(){
																	 
		});
		n.attr('zf','yes');
	}
}


jQuery.extend({gg:function(ob,fun){
			if(!ob||ob.length<1){return false;}
			var the = [];
			var css = "ggcolcss"+Math.floor(Math.random()*100000);
			for(var o in ob){ var reel = ggCreat(ob[o],css); if(reel){the.push(reel);}}
			jQuery('.'+css).bind('click',function(){ jQuery.each(the,function(i,n){ colEven(n); });});
			jQuery('.jiao'+css+',.corn'+css).bind('click',function(){ jQuery.each(the,function(i,n){	 jaoEven(n); });});
			if(fun){fun();}
		}	  
});

})()
