﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
//鼠标放上#d2f2ff
var theURL = "http://" + window.location.host;
var theI = null;
var speedy = 400;
var speedx = 1000;
var speedScroll = 0;
var theTop = 100;
var serversWrith = "140";
//重定向至新的静态页面路径
function onloadStaticPage() {
    var pageUrl = document.URL;
    var strArray = pageUrl.split('/');
    var filename= strArray[6];
    window.location.href = "http://www.vivicall.com/html/" + filename + "";
    return;
}
//每页显示5条
var countPerPage = 5;
function openWin(tmp) {
    var theDwrith = jQuery(document).width();
    var theDheight = 300;
    var theheight = 300;
    var thewrith = 469;
    window.open(theURL + "/vivicallServer.aspx?val=" + tmp, "vivi800", "height = " + theheight + ", width = " + thewrith + ", top = " + theDheight + ", left = " + Math.floor((theDwrith * 1 - thewrith * 1) / 2) + ",toolbar = no, menubar = no, scrollbars = no, resizable = no, location = no, status = no");
    //window.open("vivicallServer.aspx", "vivi800", "height = 115, width = 255, top = 300, left = 300,toolbar = no, menubar = no, scrollbars = no, resizable = no, location = no, status = no");
}

function runOnLoad() {
    
    //初始位置设定
    var theBodyWidth = jQuery("body").width();
    var theMarginRight = jQuery("body").css("marginRight");
    theMarginRight = theMarginRight.substr(0, theMarginRight.length - 2);
    var theWidth = 189;
    var theLeft = theBodyWidth * 1 - theWidth * 1 + theMarginRight * 1;
    if (theLeft * 1 < 0) {
        theLeft = 0;
    }
    jQuery("#div_vivi800CServer").css("left", theLeft);
    jQuery("#div_vivi800CServer").css("top", theTop);
    jQuery("#div_vivi800CServer").css("display", "block");
}

jQuery(document).ready(function() {
    //初始化div_vivi800CServer中的内容
    jQuery("#div_vivi800CServer").css("z-index", "500");
    jQuery("#div_vivi800CServer").css("position", "absolute");
    jQuery("#div_vivi800CServer").css("width", "189px");
    jQuery("#div_vivi800CServer").css("display", "none");
    var theHTML = "<div id='div_vivi800CServer_right' style='float: right'>"; //right
    theHTML += "<div id='div_vivi800CServer_top' style='height: 18px; width: " + serversWrith + "px; background-image: url(" + theURL + "/images/viviAnycall/top.png);'>";
    theHTML += "<a id='a_serverList_up' href='' onclick='return false;' style='display: list-item; list-style: none; height: 18px; width: " + serversWrith + "px;'></a>";
    theHTML += "</div>";
    theHTML += "<div id='div_vivi800CServer_middle' style='background-image: url(" + theURL + "/images/viviAnycall/middle.png); height: 180px; width: " + serversWrith + "px; overflow: hidden'>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(1);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />会友通客服01</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(2);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />会友通客服02</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(3);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />会友通客服03</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(4);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />会友通客服04</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(5);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />问题咨询</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(6);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />技术支持</a></div>";
    theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(7);return false;' class='viviAnycall_server_a'><img src='" + theURL + "/images/man.png' style='vertical-align:middle; border:0;' />投诉服务</a></div>";
    theHTML += "</div>";
    theHTML += "<div id='div_vivi800CServer_bottom' style='height: 18px; width: " + serversWrith + "px; background-image: url(" + theURL + "/images/viviAnycall/bottom.png)'>";
    theHTML += "<a id='a_serverList_down' href='' onclick='return false;' style='display: list-item; list-style: none; height: 18px; width: " + serversWrith + "px;'></a>";
    theHTML += "</div>";
    theHTML += "</div>";
    theHTML += "<div id='div_vivi800CServer_left' style='height: 216px; width: 22px; float: right; background-image: url(" + theURL + "/images/viviAnycall/left.png);'>";
    theHTML += "<a id='a_hiddenChange' href='' onclick='return false;' style='display: list-item; list-style: none; height: 216px; width: 22px;'></a>";
    theHTML += "</div>";

    //预加载图片
    theHTML += "<div style='visibility: hidden'>";
    theHTML += "<img src='" + theURL + "/images/viviAnycall/left1.png' alt='' />";
    theHTML += "<img src='" + theURL + "/images/viviAnycall/buttom.png' alt='' />";
    theHTML += "<img src='" + theURL + "/images/viviAnycall/top1.png' alt='' />";
    theHTML += "</div>";

    jQuery("#div_vivi800CServer").html(theHTML);

    jQuery("#div_vivi800CServer").find("a").bind("focus", function() { this.blur() });

    jQuery(window).bind("load", runOnLoad);
    //当滚动条发生变化时触发
    jQuery(window).scroll(function() {
        var theScrollTop = jQuery(document).scrollTop();
        jQuery("#div_vivi800CServer").animate({ top: theScrollTop * 1 + 100 }, speedScroll, "linear");
    });

    jQuery(window).resize(function() {
        var theBodyWidth = jQuery("body").width();
        var theMarginRight = jQuery("body").css("marginRight");
        theMarginRight = theMarginRight.substr(0, theMarginRight.length - 2);
        var theWidth = 189;
        var theLeft = theBodyWidth * 1 - theWidth * 1 + theMarginRight * 1;
        if (theLeft * 1 < 0) {
            theLeft = 0;
        }
        jQuery("#div_vivi800CServer").css("left", theLeft);
        jQuery("#div_vivi800CServer").css("top", theTop);
        jQuery("#div_vivi800CServer_right").css("display", "none");
        jQuery("#div_vivi800CServer_right").css("width", "0");
        jQuery("#div_vivi800CServer").css("display", "block");
    });
    //鼠标覆盖
    var myArray = new Array();
    jQuery("#div_vivi800CServer_middle").find("a").each(function(i) {
        myArray[i] = jQuery(this).html();
    });
    jQuery("#div_vivi800CServer_middle").find("a").each(function(i) {
        jQuery(this).hover(function() {
            jQuery(this).parent().addClass("vivianycall_serversInfo_over");
            jQuery(this).html("<img src='" + theURL + "/images/viviAnycall/Phone_40.gif' style='vertical-align:middle; border:0;' />点击免费呼叫");

        }, function() {
            jQuery(this).parent().removeClass("vivianycall_serversInfo_over");
            jQuery(this).html(myArray[i]);
        });
    });
    jQuery("#a_hiddenChange").hover(function() {
        jQuery("#div_vivi800CServer_middle").find("a").each(function(i) {
            jQuery(this).html(myArray[i]);
            jQuery(this).parent().removeClass("vivianycall_serversInfo_over");
        });
    }, function() {
        //        jQuery("#div_vivi800CServer_middle").find("a").each(function(i) {
        //            jQuery(this).html(myArray[i]);
        //            jQuery(this).parent().removeClass("vivianycall_serversInfo_over");
        //        });
    });
    //显示，隐藏客服菜单
    jQuery("#a_hiddenChange").unbind("click");
    jQuery("#a_hiddenChange").bind("click", function() {
        if (jQuery("#div_vivi800CServer_right").css("display") == "block") {
            jQuery("#div_vivi800CServer_right").animate({ width: "0" }, speedx, "swing", function() {
                jQuery("#div_vivi800CServer_right").css("display", "none");
                jQuery("#div_vivi800CServer_left").css("background-image", "url(" + theURL + "/images/viviAnycall/left1.png)");
            });
        }
        else if (jQuery("#div_vivi800CServer_right").css("display") == "none") {
            jQuery("#div_vivi800CServer_right").css("display", "block");
            jQuery("#div_vivi800CServer_right").animate({ width: "" + serversWrith + "px" }, speedx, "swing", function() {
                jQuery("#div_vivi800CServer_left").css("background-image", "url(" + theURL + "/images/viviAnycall/left.png)");
            });
        }
    });

    var divCount = jQuery("#div_vivi800CServer_middle").find("div").length;
    var oTime = null;
    var eTime = null;

    if (divCount * 1 > countPerPage * 1) {
        //绑定向上按钮鼠标进入和移除事件
        //向下按钮
        jQuery("#a_serverList_down").hover(function() {
            for (var i = 0; i < divCount; i++) {
                var tmp1 = jQuery("#div_vivi800CServer_middle").find("div").eq(i);
                if (tmp1.css("display") == "block") {
                    if (i < divCount * 1 - 5) {
                        tmp1.css("display", "none");
                        oTime = window.setInterval("upTheDiv(" + divCount + ")", speedy);
                        break;
                    }
                }
            }
        }, function() {
            window.clearInterval(oTime);
            checkTheVisible();
        });
        //向上按钮
        jQuery("#a_serverList_up").hover(function() {
            if (jQuery("#div_vivi800CServer_middle").find("div").eq(0).css("display") == "none") {
                for (var i = 0; i < divCount; i++) {
                    var tmp1 = jQuery("#div_vivi800CServer_middle").find("div").eq(i);
                    if (tmp1.css("display") == "block") {
                        jQuery("#div_vivi800CServer_middle").find("div").eq(i - 1).css("display", "block");
                        theI = i - 1;
                        eTime = window.setInterval("downTheDiv()", speedy);
                        break;
                    }
                }
            }
        }, function() {
            window.clearInterval(eTime);
            checkTheVisible();
        });
    }
    if (jQuery("#div_vivi800CServer_middle").find("div").length > countPerPage) {
        jQuery("#div_vivi800CServer_bottom").css("background-image", "url(" + theURL + "/images/viviAnycall/bottom1.png)");
    }
});
function upTheDiv(divCount) {
    checkTheVisible();
    for (var i = 0; i < divCount; i++) {
        var tmp1 = jQuery("#div_vivi800CServer_middle").find("div").eq(i);
        if (tmp1.css("display") == "block") {
            if (i < divCount * 1 - countPerPage*1) {
                tmp1.css("display", "none");
                break;
            }
        }
    }
}

function downTheDiv() {
    checkTheVisible();
    if (theI * 1 > 0) {
        theI--;
        jQuery("#div_vivi800CServer_middle").find("div").eq(theI).css("display", "block");
    }
}

function checkTheVisible() {
    if (jQuery("#div_vivi800CServer_middle").find("div").eq(0).css("display") == "none") {
        jQuery("#div_vivi800CServer_top").css("background-image", "url(" + theURL + "/images/viviAnycall/top1.png)");
    }
    else {
        jQuery("#div_vivi800CServer_top").css("background-image", "url(" + theURL + "/images/viviAnycall/top.png)");
    }
    var divCount = jQuery("#div_vivi800CServer_middle").find("div").length;
    if(divCount*1>countPerPage*1)
    {
        if (jQuery("#div_vivi800CServer_middle").find("div").eq(divCount * 1 - countPerPage * 1 - 1).css("display") != "none") {
            jQuery("#div_vivi800CServer_bottom").css("background-image", "url(" + theURL + "/images/viviAnycall/bottom1.png)");
        }
        else {
            jQuery("#div_vivi800CServer_bottom").css("background-image", "url(" + theURL + "/images/viviAnycall/bottom.png)");
        }
    }
}
