function $(el){
	if(typeof el == 'string')
		return document.getElementById(el);
	if(typeof el == 'object')
		return el;
	return null;
}
var CookieManager = {
	getExpiresDate:function(days, hours, minutes) {
	    var ExpiresDate = new Date();
	    if (typeof days == "number" && typeof hours == "number" && 
	        typeof hours == "number") {
	        ExpiresDate.setDate(ExpiresDate.getDate() + parseInt(days));
	        ExpiresDate.setHours(ExpiresDate.getHours() + parseInt(hours));
	        ExpiresDate.setMinutes(ExpiresDate.getMinutes() + parseInt(minutes));
	        return ExpiresDate.toGMTString();
	    }
	},  
	_getValue:function(offset) {
	    var endstr = document.cookie.indexOf (";", offset);
	    if (endstr == -1) {
	        endstr = document.cookie.length;
	    }
	    return unescape(document.cookie.substring(offset, endstr));
	},
	get:function(name) {
	    var arg = name + "=";
	    var alen = arg.length;
	    var clen = document.cookie.length;
	    var i = 0;
	    while (i < clen) {
	        var j = i + alen;
	        if (document.cookie.substring(i, j) == arg) {
	            return this._getValue(j);
	        }
	        i = document.cookie.indexOf(" ", i) + 1;
	        if (i == 0) break; 
	    }
	    return "";
	},
	set:function(name, value, expires, path, domain, secure) {
	    document.cookie = name + "=" + escape (value) +
	        ((expires) ? "; expires=" + expires : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	},
	remove:function(name,path,domain) {
	    if (this.get(name)) {
	        document.cookie = name + "=" +
	            ((path) ? "; path=" + path : "") +
	            ((domain) ? "; domain=" + domain : "") +
	            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	    }
	},
	clear:function(){
		var cookies = document.cookie.split(';');
		for(var i=0; i < cookies.length; i++)
			this.remove(cookies[i].split('=')[0]);
	}
}
function FlashWriter(args){
	this.params = {};
	this.variables = {};
	this.properties = { url:'', width:300, height:225,id:''};
	for(var i in args)
		this.properties[i] = args[i];
}
FlashWriter.prototype = {
	render:function(){
		var html='<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ this.properties.width +'" height="'+ this.properties.height +'"  id="'+this.properties.id+'"  name="'+this.properties.id+'">';
		html += '<param name="movie" value="'+this.properties.url+'">';
        html += '<param name="FlashVars" value="'+this.getVariableString()+'">';
		//html += '<param name="wmode" value="opaque">';
		html += this.getParamString(true);
        html += '<embed src="'+this.properties.url+ '" width="'+ this.properties.width +'" height="'+this.properties.height+'"  id="'+this.properties.id+'" name="'+this.properties.id+'"'+this.getParamString(false)+' FlashVars="'+this.getVariableString()+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';  
        html+='</object>';

        return html;
	},
	addParam:function(name, value){
		this.params[name] = value;
	},
	addVariable:function(name, value){
		this.variables[name] = value;
	},
	getVariableString:function(){
		var arr = [];
		for(var i in this.variables)
			arr.push(i+"="+this.variables[i])
		return arr.join('&');
	},
	getParamString:function(isIE){
		var arr = [];
		for(var i in this.params)
			if(isIE)
				arr.push('<param name="'+i+'" value="'+this.params[i]+'">');
			else
				arr.push(i+"="+this.params[i]);
		return arr.join(' ');
	},
	write:function(el){
		var o = document.getElementById(el);
		if(o == null) return;
		
		if(CookieManager.get('userid').length > 0)
			this.addVariable('uid',CookieManager.get('userid'));
		else
			this.addVariable('userid','');			
		if(CookieManager.get('sid').length > 0)	
			this.addVariable('sid',CookieManager.get('sid'));
		else
			this.addVariable('sid','');	
		if(CookieManager.get('location').length > 0)
			this.addVariable('locid',CookieManager.get('location'));
		else
			this.addVariable('locid','');		
		
		var ref = location.href;

/*
		var rindex=ref.indexOf("#");
		
		if(rindex!=-1)
		{
			ref=ref.substring(0, rindex);
			alert(ref);
		}
*/
		if(ref.length > 0)
			this.addVariable('pageurl',ref);
		else
			this.addVariable('pageurl','');

	    fo.addVariable("from","free");
	    fo.addVariable("adcpid",1210);
	
		var fls=this.getVersion();
		
		if(!(parseInt(fls[0]+fls[1]+fls[2])>901))//版本小于901 则提示
		{
			var otishi='<div style="margin:50px auto;width:288px;height:163px;border:2px outset #05ABEA;font-size:12px;background-color:#eee;">';
			otishi+='<p style="padding:20px;line-height:160%;color:#000;">请先确认是否安装了 最新Flash 播放器<br/>请点击安装按钮</p>';
			otishi+='<a style="display:block;height:31px;width:115px;line-height:31px;color:#000;text-decoration:none;text-align:center;margin:10px auto 0 auto;border:2px outset #999;" href="http://get.adobe.com/flashplayer/" target="_blank">安装</a></div>';
			
			o.style.width=this.properties.width;
			o.style.height=this.properties.height;
			o.innerHTML =otishi;
			
		}
		else
		{
			o.innerHTML = this.render();
		}		
	},
	getVersion:function(){
	var b=[0,0,0];
	if(navigator.plugins&&navigator.mimeTypes.length){
		var a=navigator.plugins["Shockwave Flash"];
		if(a&&a.description){
			b=a.description.replace(/^\D+/,"").replace(/\s*r/,".").replace(/\s*[a-z]+\d*/,".0").split(".")
		}
	}else{
		if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){
			var c=1;
			var f=3;
			while(c){
				try{
					f++;
					c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+f);
					b=[f,0,0]
				}catch(d){
					c=null
				}
			}
		}else{
			try{
				var c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")
			}catch(d){
				try{
					var c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					b=[6,0,21];
					c.AllowScriptAccess="always"
				}catch(d){
					if(b.major==6){
						return b
					}
				}
				try{
					c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")
				}catch(d){}
			}
			if(c!=null){
				b=c.GetVariable("$version").split(" ")[1].split(",")
			}
		}
	}
	return b
}
}
/* MSN分享 */
var cookieName = 'FIRSTVIDEOINFO';
var domain = ".ifeng.com";
var objMessengerActiveP4;
var appID = "99995879";
function IMThis(videoType,VideoFirst,Vmenu)
{  
	var videoinfo = videoType + "^" +  VideoFirst + "^" + Vmenu;
	SetMsnCookie(cookieName,videoinfo);//用cookie记录视频ID
    CheckMessenger();//检测msn版本
    if( objMessengerActiveP4 != null) 
    {
    	objMessengerActiveP4.LaunchApp(appID, '');	
    }
}

function SetMsnCookie(strCookieName,strCookieValue,strExpireDate)
{
    var strExpires;
    if(strExpireDate=="session")
    {
        strExpires="";
    }
    else
    {
        if(strExpireDate)
            strExpires=";expires="+strExpireDate;
        else
            strExpires=";expires="+(new Date( (new Date()).getTime() + 1000 * 60 * 60 * 24 )).toGMTString();
    }
	
    document.cookie=strCookieName+"="+encodeURI(strCookieValue)+strExpires+";path=/;domain=" + domain;
}
function getCookie (name) 
{
	 var arg = name + "="; 
	 var alen = arg.length; 
	 var clen = document.cookie.length; 
	 var i = 0; 
	 while (i < clen) { 
		 var j = i + alen; 
		 if (document.cookie.substring(i, j) == arg) return getCookieVal (j); 
		 i = document.cookie.indexOf(" ", i) + 1; 
		 if (i == 0) break; 
	 } 
	 return null; 
}
function getCookieVal (offset)
{ 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) endstr = document.cookie.length; 
	return decodeURI(document.cookie.substring(offset, endstr)); 
} 
function CheckMessenger(){
    this.gid=function(i){return document.getElementById(i);};
    try 
    { 
        objMessengerActiveP4 = new ActiveXObject("MSNMessenger.P4QuickLaunch");
    } 
    catch(e)
    {
        if(!gid("noMSNImDiv"))
        {
            noMSNImDiv=document.createElement("div");
            noMSNImDiv.setAttribute("id","noMSNImDiv");
            contentContainer=document.createElement("div");
            noMSNImDiv.appendChild(contentContainer);
        }
        else
        {
        gid("noMSNImDiv").style.display="block";
        };
        noMSNImDiv.className="floatBox";
        contentContainer.className="floatBoxContent";
        contentContainer.innerHTML="<div class='floatBoxHead'><span onmouseover='document.body.style.cursor=\"pointer\"' onmouseout='document.body.style.cursor=\"auto\"' onclick='document.getElementById(\"noMSNImDiv\").style.display=\"none\"'>[x]</a></div>对不起，您当前的配置不支持此功能.<br>要求安装 Messenger6.0 或以上版本及 IE5.5 或以上版本.<br><a href='http://im.live.cn' style='color:black;text-decoration:underline'  target='msnwin'>立即安装 Windows Live Messenger！</a><br><br>";
        dt=gid("P4_IMToolbar");
        dt.appendChild(noMSNImDiv);
        objMessengerActiveP4 = null;
    }
}

/*播放器调用分享MSN方法*/
function SendVideoInfo(videoType,VideoFirst,Vmenu)
{
	IMThis(videoType,VideoFirst,Vmenu);
}

