﻿/*对联广告居中*/
var MoveCoupletTimer = null;
var IsBlastAdFinsh = false;
var IsLeftCouplet = false;
var IsRightCouplet = false;
function MoveCoupletAd() {
    if (MoveCoupletTimer == null) {
        MoveCoupletTimer = setInterval(function() {
            $("LeftCoupletAD").style.top = document.documentElement.clientHeight / 2 + document.documentElement.scrollTop - 200 / 2 + "px";
            $("RightCoupletAD").style.top = document.documentElement.clientHeight / 2 + document.documentElement.scrollTop - 200 / 2 + "px";
        }, 100);
    }
}
/*对联广告加载完必*/
function CoupletLoad(type) {
    if (type == "Left") {
        IsLeftCouplet = true;
    }
    else if (type == "Right") {
        IsRightCouplet = true;
    }
    else if (type == "blastAd") {
        IsBlastAdFinsh = true;
    }

    if (IsLeftCouplet && IsRightCouplet && IsBlastAdFinsh) {
        $("LeftCoupletAD").style.display = "";
        $("RightCoupletAD").style.display = "";
        setTimeout(function() {
            $("LeftCoupletBigAdFrame").style.display = "none";
            $("RightCoupletBigAdFrame").style.display = "none";
            $("LeftCoupletButton").style.display = "";
            $("RightCoupletButton").style.display = "";
        }, 5000);
    }
}
/*显示对联广告*/
function ShowCoupletAD() {
    $("LeftCoupletBigAdFrame").style.display = "";
    $("RightCoupletBigAdFrame").style.display = "";
    $("LeftCoupletButton").style.display = "none";
    $("RightCoupletButton").style.display = "none";
    setTimeout(function() {
        $("LeftCoupletBigAdFrame").style.display = "none";
        $("RightCoupletBigAdFrame").style.display = "none";
        $("LeftCoupletButton").style.display = "";
        $("RightCoupletButton").style.display = "";
    }, 5000);
}
/*关闭对联广告*/
function CloseCoupletAD() {
    clearInterval(MoveCoupletTimer);
    MoveCoupletTimer = null;
    $("LeftCoupletAD").parentNode.removeChild($("LeftCoupletAD"));
    $("RightCoupletAD").parentNode.removeChild($("RightCoupletAD"));
}


/*拉幕广告*/
function CloseBlastAd(type) {
    if (type == "delay") {
        setTimeout(function() {
            CloseBlastAd();
            PopWindow(); //弹窗
            CoupletLoad("blastAd"); //对联广告
        }, 8000);
    }
    else {
        $("BlastAdDiv").style.display = "none";
        $('OpenTopAdBtn').style.display = "";
    }
}
function ShowBlastAd() {
    $('BlastAdDiv').style.display = '';
    $('OpenTopAdBtn').style.display = "none";

    setTimeout(function() {
        CloseBlastAd();
    }, 8000);
}
/*初始化拉幕广告*/
function IniBlastAd() {
    var str = '<div class="adImg">\
                  <iframe src="http://links.kugoo.com/mini/www/topAd.htm" scrolling="no" frameborder="0" style="width:950px;height:400px;" onload="ShowBlastAd();CloseBlastAd(\'delay\');"  ></iframe>\
                  <img src="Images/btn_close3.gif" style="cursor:pointer; position:absolute;top:10px;left:900px;" onclick="CloseBlastAd()" title="关闭"  />\
              </div>';

    $('BlastAdDiv').innerHTML = str; 
};


/*头条图片切换*/
var ImgChange = function() { };
ImgChange.prototype.ini = function(btn, bigImg, now, count, SliderMark) {
    this.now = now;
    this.btn = btn;
    this.bigImg = bigImg;
    this.count = count;
    this.SliderMark = SliderMark;
    this.distance = 54;
    this.timer = null;
    this.create();
}
ImgChange.prototype.create = function() {
    var self = this;
    for (i = 0; i < this.count; i++) {
        $(this.btn + "_" + i).onmouseover = function() {
            sdnClick(3808);
            clearInterval(self.timer);
            self.timer = null;
            self.now = this.id.split('_')[1];
            self.change();
        }
        $(this.bigImg + "_" + i).onmouseover = function() {
            clearInterval(self.timer);
            self.timer = null;
            self.now = this.id.split('_')[1];
            self.change();
        }
        $(this.bigImg + "_" + i).onmouseout = function() {
            self.auto();
        }
    }

    $(this.SliderMark).onmouseover = function() {
        clearInterval(self.timer);
        self.timer = null;
    }

    $(this.SliderMark).onmouseout = function() {
        self.auto();
    }

    this.auto();
}
ImgChange.prototype.auto = function() {
    var self = this;
    if (this.timer == null) {
        this.timer = setInterval(function() {
            self.now++;
            if (self.now >= self.count) {
                self.now = 0;
            }
            self.change();
        }, 5000);
    }
}
ImgChange.prototype.change = function() {
    for (i = 0; i < this.count; i++) {
        if (i == this.now) {
            $(this.bigImg + "_" + i).style.display = "";
            $(this.SliderMark).style.top = (i * this.distance) + "px";
            $(this.btn + "_" + i).style.cssText = "filter:alpha(opacity=100) !important; opacity:1.0 !important;";
        }
        else {
            $(this.bigImg + "_" + i).style.display = "none";
            $(this.btn + "_" + i).style.cssText = "cursor:pointer;";
        }
    }
}



/*今日头条新闻切换*/
function TodayTopChange(oThis) {
    var now = oThis.id.split('_')[2];
    for (i = 0; i < 4; i++) {
        if (i == now) {
            $("TodayTop_Btn_" + i).parentNode.className = "open";
            $("TodayTop_Small_" + i).style.display = "none";
            $("TodayTop_Big_" + i).style.display = "";
        }
        else {
            $("TodayTop_Btn_" + i).parentNode.className = "";
            $("TodayTop_Small_" + i).style.display = "";
            $("TodayTop_Big_" + i).style.display = "none";
        }
    }
}

function TodayTopChange1(type) {
    var now = type;
    for (i = 0; i < 4; i++) {
        if (i == now) {
            $("TodayTop_Btn_" + i).parentNode.className = "open";
            $("TodayTop_Small_" + i).style.display = "none";
            $("TodayTop_Big_" + i).style.display = "";
        }
        else {
            $("TodayTop_Btn_" + i).parentNode.className = "";
            $("TodayTop_Small_" + i).style.display = "";
            $("TodayTop_Big_" + i).style.display = "none";
        }
    }
}


/*用于标签切换*/
var TagChange = function(btn, content, now, count, selectClass, noselectClass) {
    this.btn = btn;
    this.content = content;
    this.selectClass = selectClass;
    this.noselectClass = "";
    if (noselectClass != undefined) {
        this.noselectClass = noselectClass;
    }
    this.now = now;
    this.count = count;
    this.create();
};

TagChange.prototype.create = function() {
    var self = this;
    for (i = 0; i < this.count; i++) {
        $(this.btn + "_" + i).onmouseover = function() {
            self.now = this.id.split('_')[1];
            self.change();
        }
    }
}
TagChange.prototype.change = function() {
    for (i = 0; i < this.count; i++) {
        if (i == this.now) {
            $(this.content + "_" + i).style.display = "";
            $(this.btn + "_" + i).className = this.selectClass;
        } else {
            $(this.content + "_" + i).style.display = "none";
            $(this.btn + "_" + i).className = this.noselectClass;
        }
    }
}


/*弹窗*/
function PopWindow() {
    $('PopWindowDiv').style.display = "";
    
    //视频广告
    setTimeout(function() {
        PopVideoWindow();
    }, 8000);
};
function ClosePopWindow() {
    $('PopWindowDiv').style.display = "none";
}


/*视频弹窗*/
function PopVideoWindow() {
    $('PopVideoWindowDiv').style.display = "";
}

function showVideoWindow() {
    $('PopVideoWindowDiv').style.opacity = "1";
    $('PopVideoWindowDiv').style.bottom = "0px";
    $('VideoHrefDiv').style.display = "";
    if (kg.Browser.ie) {
        $('PopVideoWindowDiv').style.filter = "";

    }
    sdnClick(3956);
    return true;
}


function closeVideoWindow() {
    $('PopVideoWindowContentDiv').style.display = "none";
    $('PopVideoWindowSmallBtnDiv').style.display = "";
    $('PopVideoWindowDiv').style.width = "70px";
    $('PopVideoWindowDiv').style.height = "17px";
}
function RealCloseVideoWindow() {
    try {
        $("flashPlayer").close();
    }
    catch (e1) {
        try {
            document.getElementsByName("flashPlayer")[1].close();
        }
        catch (e2) { }
    }
    $('PopVideoWindowDiv').parentNode.removeChild($('PopVideoWindowDiv'));
}
function replay() {
    
    $('PopVideoWindowContentDiv').style.display = "";
    $('PopVideoWindowSmallBtnDiv').style.display = "none";
    $('PopVideoWindowDiv').style.width = "337px";

    $('PopVideoWindowDiv').style.height = "268px";
    
    try {
        $("flashPlayer").replay();
    }
    catch (e1) {
        try {
            document.getElementsByName("flashPlayer")[1].replay();
        }
        catch (e2) { }
    }
}



/*投票*/
function Vote(type) {
    var isVote = kg.Cookie.read("IsVoted");
    if (isVote) {
        alert("你已经投过票了");
        var myShadeShow = new ShadeShow();
        myShadeShow.ShadeClose();
        return null;
    }
    var voteOption = document.getElementsByName('VoteOption');

    if (type == 2) {
        voteOption = document.getElementsByName('VoteOption2');
    }

    var optionid = 0;
    for (i = 0; i < voteOption.length; i++) {
        if (voteOption[i].checked) {
            optionid = voteOption[i].value;
            break;
        }
    }
    if (optionid == 0) {
        alert("请选择后再投票");
        return null;
    }

    var url = "vote.ashx";
    var para = new kg.Ajax.Param();
    para.$("action", "add").$("optionid", optionid);
    new kg.Ajax().Async(url, "post", para.stringValue(), function(re) {
        if (re.responseText == "success") {
            kg.Cookie.write("IsVoted", "true", 1, "/");
            alert("投票成功");
            var myShadeShow = new ShadeShow();
            myShadeShow.ShadeClose();
            return null;
        }
        alert(re.responseText);
    });
}

/*查看投票结果*/
function ViewVote() {
    var strTips = "<div style='text-align:center;padding:30px;'>正在获取结果</div>";

    var myShadeShow = new ShadeShow();
    myShadeShow.ini(strTips, 300, 208, true, true, false);


    var url = "vote.ashx";
    var para = new kg.Ajax.Param();
    para.$("action", "view")
    new kg.Ajax().Async(url, "post", para.stringValue(), function(re) {
        var result = JSON.parse(re.responseText);

        if (re.responseText == "wrong" && result.length) {
            alert("错误");
            return;
        }
        var sum = 0;
        for (i = 0; i < result.length; i++) {
            sum += parseInt(result[i].num);
        }

        var voteTitle = $('VoteTitleTxt').value;


        var str = '<div class="voteBox" style="margin:0px;padding:0px;">\
                        <div class="box" style="margin:0px;padding:0px;"><div class="title"><div class="left"></div><div class="text">查看投票结果</div><div class="right"></div></div><div class="content">\
                        <div class="vote"><div class="text">' + voteTitle + '</div><ul>';

        for (i = 0; i < result.length; i++) {
            var temp = parseInt((result[i].num / sum) * 100);
            str += '<li><input type="radio" id="VoteOption2" name="VoteOption2"  value="' + result[i].optionid + '" />' + $("VoteOptionTxt_" + result[i].optionid).innerHTML + '</li>\
                        <li><img src="Images/a_bar6.gif" style="width:2px; height:8px;" /><img src="Images/b_bar6.gif" style="width:' + temp + 'px; height:8px;" /><img src="Images/c_bar6.gif" style="width:4px; height:8px;" /><span class="textYellow2">' + result[i].num + '</span>票</li>';
        }
        str += '</ul>\
                        <div class="button"><br /><input type="button" name="button" id="button" class="buttonSend" onclick="Vote(2)" value="投 票" />&nbsp;&nbsp;<input type="button" name="button" id="ViewVoteCloseBtn" class="buttonClose" onclick="" style="cursor:pointer;" value="关闭" /></div>\
                        </div>\
                        </div><div class="bottom"><div class="left"></div><div class="right"></div></div></div>\
                        </div>';

        var myShadeShow = new ShadeShow();
        myShadeShow.ini(str, 300, 208, false, true, false);

        $('ViewVoteCloseBtn').onclick = function() {
            var myShadeShow = new ShadeShow();
            myShadeShow.ShadeClose();

        }
    });
}







/*歌曲全选*/
function SelectAll(type) {
    var songs = document.getElementsByName(type);
    for (i = 0; i < songs.length; i++) {
        songs[i].checked = true;
    }
}
function PlayAllSong(type) {
    var songs = document.getElementsByName(type);
    var songsStr = "";
    var count = 0;
    for (i = 0; i < songs.length; i++) {
        if (songs[i].checked) {
            var temp = songs[i].value;
            songsStr = songsStr + temp;
            count++;
        }
    }
    PlayMultiSong(songsStr, count);
}
function DownAllSong(type) {
    var songs = document.getElementsByName(type);
    var songsStr = "";
    var count = 0;
    for (i = 0; i < songs.length; i++) {
        if (songs[i].checked) {
            var temp = songs[i].value;
            songsStr = songsStr + temp;
            count++;
        }
    }
    DownMultiSong(songsStr, count);
}


function PlayBangDang(type) {
    var songs = document.getElementsByName(type);
    var songsStr = "";
    var count = songs.length;
    for (i = 0; i < songs.length; i++) {
        songsStr = songsStr + songs[i].value;
    }
    PlayMultiSong(songsStr, count);
}