﻿//// JavaScript Document
$.fn.getVjiaAd = function (callBack) {
    var webUrl = "http://www.vjia.com/Public/GetVJiaAD.ashx?url=http://images.vjia.com/public/floatad.html";
    var currentObj = this;
    $.ajax({
        async: "true",
        type: "GET",
        url: webUrl,
        data: "",
        dataType: "script",
        success: function () {
            currentObj.html(vjiaAd.html);
            OpenUI();
            if (callBack != null) {
                callBack();
            }
        }
    });
}

function LoadVjiaAdImg() {
    var img = new Image();
    img.src = "";
    if (img.complete) {
        OpenUI();
    } else {
        img.onload = function () {
            OpenUI();
            img.onload = null;
        };
    };
}

function OpenUI() {
//    $('<img />')
//	    .attr('src', 'http://images.vancl.com/vjiafloatad/20100906/windowBg.gif')
//	    .load(function () {
	        document.getElementById('floatad-winpop').style.height = '0px';
	        var isIE6 = !window.XMLHttpRequest;
	        if (isIE6) {
	            $("#floatad-winpop").css({ position: "absolute" });
	        }
	        setTimeout("tips_pop()", 800);
	        BindTab();
//	    });
}


var CurPopPub = 1;
var PopPubHandle = null;

function SetPopPubhandle() {
    setTab('style', CurPopPub, 4);
    PopPubHandle = setInterval(function () { setTab('style', CurPopPub, 4); CurPopPub++; if (CurPopPub == 5) CurPopPub = 1; }, 3000);
}

function BindTab() {
    $("[id^='style']").each(function (i) {
        $(this).mouseover(function () { if (PopPubHandle) clearInterval(PopPubHandle); CurPopPub = parseInt(i) + 1; setTab('style', CurPopPub, 4); })
    .mouseout(function () { SetPopPubhandle(); });
    });
    $("[id^='con_one_']").each(function () {
        $(this).mouseover(function () { if (PopPubHandle) clearInterval(PopPubHandle); }).mouseout(function () { SetPopPubhandle(); });
    });
    SetPopPubhandle();
};

function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        /*menu.className = i == cursel ? "floatad-hover" : "";
        con.style.display = i == cursel ? "block" : "none";*/
    }
}

function tips_pop() {
    var MsgPop = document.getElementById("floatad-winpop");
    var popH = parseInt(MsgPop.style.height);
    if (popH == 0) {
        MsgPop.style.display = "block";
        show = setInterval("changeH('up')", 2);
    }
    else {
        hide = setInterval("changeH('down')", 2);
    }
}


function changeH(str) {
    var MsgPop = document.getElementById("floatad-winpop");
    var popH = parseInt(MsgPop.style.height);
    if (str == "up") {
        if (popH <= 170) {
            MsgPop.style.height = (popH + 4).toString() + "px";
        }
        else {
            clearInterval(show);
        }
    }
    if (str == "down") {
        if (popH >= 4) {
            MsgPop.style.height = (popH - 4).toString() + "px";
        }
        else {
            clearInterval(hide);
            MsgPop.style.display = "none";
        }
    }
}
