﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
//鼠标放上#d2f2ff
//var theURL = "http://" + window.location.host;
var theURL = "http://www.vivicall.com"; //"http://192.193.193.10:9002"; //
var theI = null;
var user = "";
var language = "";
var speedy = 400;
var speedx = 1000;
var speedScroll = 0;
var theTop = 130;
var serversWrith = "140";
//每页显示5条
var countPerPage = 5;
/*****分组图标1******/
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("position", "absolute");
    jQuery("#div_vivi800CServer").css("left", theLeft);
    jQuery("#div_vivi800CServer").css("top", theTop);
    jQuery("#div_vivi800CServer").css("z-index", "500");
    jQuery("#div_vivi800CServer").css("width", "189px");
    jQuery("#div_vivi800CServer_right").css("display", "block");
    //jQuery("#div_vivi800CServer").css("display", "block");
}

function showDIV() {
    jQuery("#div_vivi800CServer").css("display", "block");
}

function show_vivi800(language_in,user_in,code_id) {
    language = language_in;
    user = user_in;
    runOnLoad();
    var rdm = Math.round(Math.random() * 100000);
    jQuery.getJSON(theURL + "/VIVI800/vivi800_pages/server_rs.aspx?type=get_serveruser&value=" + user + "&code_id="+code_id+"&rdm=" + rdm + "&jsoncallback=?", function(data) {
        //初始化div_vivi800CServer中的内容
        var theHTML = "<div id='div_vivi800CServer_right' style='float: right'>";
        theHTML += "<div id='div_vivi800CServer_top' style='height: 18px; width: " + serversWrith + "px; background-image: url(" + theURL + "/VIVI800/vivi800_images/viviAnycall/top1.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>";

        /*var div_vivi800CServer_middle_height = 0;
        jQuery.each(data, function(i) {
            div_vivi800CServer_middle_height += 40;
        });*/

        theHTML += "<div id='div_vivi800CServer_middle' style='background-image: url(" + theURL + "/VIVI800/vivi800_images/viviAnycall/middle.png); height:180px; width: " + serversWrith + "px; overflow: hidden'>";

        jQuery.each(data, function(i) {
            var group_id = data[i].Id;
            var tel_explain = "";
            if (language == "ch") {
                tel_explain = data[i].Tel_explain_ch;
            }
            else {
                tel_explain = data[i].Tel_explain_en;
            }
            theHTML += "<div class='vivianycall_serversInfo'><a href='' onclick='openWin(" + group_id + ",\"" + language + "\");return false;' class='viviAnycall_server_a'><img src='" + theURL + "/VIVI800/vivi800_images/man.png' style='vertical-align:middle; border:0;' />" + unescape(tel_explain) + "</a></div>";
        });

        theHTML += "</div>";
        theHTML += "<div id='div_vivi800CServer_bottom' style='height: 18px; width: " + serversWrith + "px; background-image: url(" + theURL + "/VIVI800/vivi800_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 + "/VIVI800/vivi800_images/viviAnycall/left" + "_" + language + ".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 + "/VIVI800/vivi800_images/viviAnycall/left1" + "_" + language + ".png' alt='' />";
        theHTML += "<img src='" + theURL + "/VIVI800/vivi800_images/viviAnycall/buttom.png' alt='' />";
        theHTML += "<img src='" + theURL + "/VIVI800/vivi800_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 + 130 }, 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 + "/VIVI800/vivi800_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 + "/VIVI800/vivi800_images/viviAnycall/left1" + "_" + language + ".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 + "/VIVI800/vivi800_images/viviAnycall/left" + "_" + language + ".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 + "/VIVI800/vivi800_images/viviAnycall/bottom1.png)");
        }
        //jQuery(window).bind("load", showDIV);
        jQuery("#div_vivi800CServer").css("display", "block");
    });
}
//});


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 + "/VIVI800/vivi800_images/viviAnycall/top1.png)");
    }
    else {
        jQuery("#div_vivi800CServer_top").css("background-image", "url(" + theURL + "/VIVI800/vivi800_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 + "/VIVI800/vivi800_images/viviAnycall/bottom1.png)");
        }
        else {
            jQuery("#div_vivi800CServer_bottom").css("background-image", "url(" + theURL + "/VIVI800/vivi800_images/viviAnycall/bottom.png)");
        }
    }
}

function openWin(tmp, lang) {
    var theDwrith = jQuery(document).width();
    var theDheight = 300;
    var theheight = 300;
    var thewrith = 469;
    var url_tmp = "";
    if (lang == "ch") {
        url_tmp = "VIVI800/ServerPage.aspx";
    }
    else if (lang == "en") {
        url_tmp = "VIVI800/ServerPage_en.aspx";
    }
    window.open(theURL + "/" + url_tmp + "?val=" + tmp + "&value=" + user, "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");
}
