﻿var ipadautoplay = 'false';
function play(videoid, autoplay, adplay)
{
    if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1)// ipad,iphone
    {
        if (autoplay) { ipadautoplay = autoplay ;}
        var url = "http://partner.itv.ifeng.com/IfengVideoSearch/getplayermsgnew.aspx?msg="+ videoid +"&callback=showhtml5video&param=playermsg";
        getScript_cds(url);
    }
    else
    {
        var _sitedomain = ph_get_ad_chl();
        var fo = new FlashWriter({
                    url : 'http://vimg.ifeng.com/swf/zuheVplayer_v1.80.swf',
                    width : '480',
                    height : '380',
                    id : 'fplay'
                });
        fo.addVariable('guid', videoid);
        fo.addVariable('from', _sitedomain);
		fo.addVariable('playerName', "VZHPlayer");
		fo.addVariable('adType', "1");

        if (typeof(autoplay) != "undefined")
            fo.addVariable('AutoPlay', autoplay);
        else
            fo.addVariable('AutoPlay', 'false');

        if (typeof(adplay) != "undefined")
            fo.addVariable('ADPlay', adplay);
        else
            fo.addVariable('ADPlay', 'true');
        fo.addVariable('writeby','webjs');//为了兼容以前的组合传播页面。如果source=webjs，表示是js渲染播放器，此时分享功能直接调用脚本方法；否则调用swf自身的分享方法
        fo.addVariable('clickPlay', 'true');
		fo.addVariable('width','480');
		fo.addVariable('height','380');
        fo.addParam('allowFullScreen', 'true');
        fo.addParam('wmode', 'transparent');
		fo.addVariable('canShare','true');
        fo.addParam('allowScriptAccess', 'always');
        fo.write('VideoPlayerDiv');
    }
}
function ph_get_ad_chl()
{
    var _domain = location.host;
    var _domain_array = _domain.split('.');
    if (_domain_array.length >= 3 && _domain.indexOf("ifeng.com") != -1)
        _domain = _domain_array[_domain_array.length - 3];
    return _domain;
}
var thisvideo = 0;

function initHtml5Video(id, src) {
	var video = document.createElement('video');
	video.width = 480;
	video.height = 360;
	video.setAttribute('id', id);
	video.setAttribute('controls', 'controls');
	video.setAttribute('src', src);
	return video;
}

function showhtml5video(data) {
	if(!data) { return; }
	var video = initHtml5Video('fplayer', data.videoplayurl),
		list = data.parts,
		count = 0;
	if(ipadautoplay){ video.setAttribute('autoplay', true); }
	var container = document.getElementById('VideoPlayerDiv');
	container.innerHTML = '';
	container.appendChild(video);
	video.addEventListener('ended', function(){
		if(!list[++count]) { return; }
		video.setAttribute('src', list[count]);
		video.play();
	});	
}

function getScript_cds(src, callback)
{
    var head = document.getElementsByTagName("head")[0];
    var js = document.createElement("script");
    js.setAttribute("src", src);
    js.onload = js.onreadystatechange = function()
    {
        if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")
        {
            head.removeChild(js);
            if (callback)
                callback();
        }
    }
    head.appendChild(js);
}

/*2011-04-15 bshare begin*/
function shareTo(site,pic,url,title,smallimg) {	
    var _url = encodeURIComponent(url);	
    var _title = encodeURIComponent(title);
    var _content = "";
    /*if (eval("_oFlv_c.Content != null")) {
        _content = encodeURIComponent(_oFlv_c.Content);
    }*/
    switch (site) {
      case "kaixin001":
        window.open("http://www.kaixin001.com/repaste/share.php?rurl=" + _url + "&rtitle=" + _title);
        break;
      case "renren":
        window.open("http://share.renren.com/share/buttonshare.do?link=" + _url + "&title=" + _title);
        break;
      case "weibo":
        var l = (screen.width - 440) / 2;
        var t = (screen.height - 430) / 2;
		//window.open("http://v.t.sina.com.cn/share/share.php?appkey=168486312&c=spr_web_bd_56_weibo&url=" + _url + "&title=" + _title + "&source=56&sourceUrl=http://www.56.com/&content=utf8&pic="+smallimg, "_blank", "toolbar=0,status=0,resizable=1,width=440,height=430,left=" + l + ",top=" + t);
        window.open("http://v.t.sina.com.cn/share/share.php?appkey=168486312&url=" + _url + "&title=" + _title + "&source=ifeng&sourceUrl=http://v.ifeng.com/&content=utf8&pic="+smallimg+"&ralateUid=1806128454", "_blank", "toolbar=0,status=0,resizable=1,width=440,height=430,left=" + l + ",top=" + t);
		break;
	 case "qqzone":
        window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + _url);
        break;
      case "qqweibo":
       var _appkey = encodeURI("f8ca1cd768da4529ab190fae9f1bf21d");//appkey
       var _pic = encodeURI("");
       var _site = "http://v.ifeng.com";
       var _u = "http://v.t.qq.com/share/share.php?title=" + _title + "&url=" + _url + "&appkey=" + _appkey + "&site=" + _site + "&pic=" + _pic;
       window.open(_u, "\u8F6C\u64AD\u5230\u817E\u8BAF\u5FAE\u535A", "width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no");
        break;
      default:
        return false;
    }
}

function shareToTweet(t, z, id, p, type, s, d, e) {
    if (undefined == s) {
        s = screen;
    }
    if (undefined == d) {
        d = document;
    }
    if (undefined == e) {
        e = encodeURIComponent;
    }
    var f = "http://t.ifeng.com/interface.php?_c=share&_a=share&", u = z || d.location, pa = ["sourceUrl=", e(u), "&title=", e(t || d.title), "&pic=", e(p || ""), "&source=", e(id || ""), "&type=", e(type || 0)].join("");

    function a() {
        if (!window.open([f, pa].join(""), "", ["toolbar=0,status=0,resizable=1,width=640,height=481,left=", (s.width - 640) / 2, ",top=", (s.height - 480) / 2].join(""))) {
            u.href = [f, pa].join("");
        }
    }

    if (/Firefox/.test(navigator.userAgent)) {
        setTimeout(a, 0);
    } else {
        a();
    }
}
/*2011-04-15 end*/
