///<reference path="jquery-1.3.2-vsdoc.js">

// JavaScript Document
/*
$("#globalnav li").bind("mouseenter", function(e){
       var m = $(this).fide(".dropdown_pane");
	   if(m.length) return;
	   m.show();
	   var p = $(this).position();
		var x =  width( )/2+p.left;
		p = m.position();
		p.left = x
		m.position(p);
    });
$("#globalnav li").bind("mouseleave", function(e){
       var m = $(this).fide(".dropdown_pane");
	   m.hide();
    });

*/
var sub_menu_id;
var sub_menu_counter;
var sub_menu_timeout=500;
var char_server_neee_init = false;
var char_support_status=0;
var OnlineSupportGroupID = 32;
var OnlineTestStatusTime = 30*1000;
var chatService=null
$(document).ready(function() {
    //if ($.browser.msie && $.browser.version < 8) {
        if (char_server_neee_init)
            TestIMStatus();
        else
            setTimeout(TestIMStatus, OnlineTestStatusTime);
         
    $("#globalnav li").each(function() {
        var m = $(this).find(".dropdown_pane");
        if (m.length == 0) return;
        var p = $(this).position();
        var x_div = $(this).width() / 2 - m.width() / 2;
        var x = p.left + x_div;
        m.css("left", x + 'px')
        m.css('margin-left', 0);
        this.sub_menu = m;
        this.sub_x_div = x_div;

        $(this).hover(function() {
            var p = $(this).find('a').position();
            this.sub_menu.css('left', p.left + this.sub_x_div + "px");
            sub_menu_id = $(this).attr('id');
            clearTimeout(sub_menu_counter);
            sub_menu_counter = setTimeout(ShowSubMenu, sub_menu_timeout)
            //this.sub_menu.show();
        }, function() {
            this.sub_menu.hide();
            clearTimeout(sub_menu_counter);
        });
    }
        );
	if($('a.photo').lightBox){
		$('a.photo').lightBox({ fixedNavigation: true });
	}

    // }
});

function ShowSubMenu(){
    $("#" + sub_menu_id + " .dropdown_pane").show();
}

function OpenOnlineChat() {
    if (char_support_status != AgentState.Online)
        return;
    var width = "335", height = "440";
    var left = (screen.width / 2) - width / 2;
    var top = (screen.height / 2) - height / 2;
    window.open("/Online/webchat.aspx", "chatwindow" + (new Date()).getTime(), 'location=0,status=0,scrollbars=0,toolbar=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top);
    return false;
}

function OpenCallOnlineChat() {
    if (char_support_status != AgentState.Online)
        return;
    var width = "335", height = "440";
    var left = (screen.width / 2) - width / 2;
    var top = (screen.height / 2) - height / 2;
    window.open("/Online/CallOnline.aspx", "callwindow", 'location=0,status=0,scrollbars=0,toolbar=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top);
    return false;
}
function OpenCallBack() {

    var width = "335", height = "440";
    var left = (screen.width / 2) - width / 2;
    var top = (screen.height / 2) - height / 2;
    window.open("/Online/CallBack.aspx", "callbackwindow" + (new Date()).getTime(), 'location=0,status=0,scrollbars=0,toolbar=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top);
    return false;
}


function TestIMStatus(){
    chatService = new IChatService();
        chatService.GetAgentGroupState(OnlineSupportGroupID,OnGetAgentGroupState)
    

}
function OnGetAgentGroupState(status){
    var online_btn = $('#online_btn');
    var call_btn = $('#call_btn');
    char_support_status = status;
    if (char_support_status == AgentState.Online) {//Online
        online_btn.removeClass("online_disable");
        online_btn.addClass("online");
        call_btn.removeClass("call_disable");
        call_btn.addClass("call");
        
    }else{
        online_btn.removeClass("online");
        online_btn.addClass("online_disable");
        call_btn.removeClass("call");
        call_btn.addClass("call_disable");
        
    
    }
    setTimeout(TestIMStatus, OnlineTestStatusTime);
}
function OnGetAgentsState(result) {
}

///common/scripts/window_opener.js
//==========================
function open_window(href, width, height, features, window_name) {
    var iMyWidth;
    var iMyHeight;

    if (!window_name) { window_name = ""; }
    if (!width) { width = 400; }
    if (!height) { height = 400; }
    if (!features) { features = "toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes"; }

    iMyWidth = (window.screen.width - (width)) / 2;
    iMyHeight = (window.screen.height - (height)) / 2;

    var win2 = open("" + href + "", window_name, "height=" + height + ",width=" + width + ",left=" + iMyWidth + ",top=" +
		iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + "," + features + "");

    if (win2 != null) { win2.focus(); }
}
function centerPopup(popup_name, popup_url, popup_with, popup_height, myWidth, myHeight) {
    if (!myWidth) { myWidth = 10; }
    if (!myHeight) { myHeight = 40; }

    var popup_left = (window.screen.width / 2) - (popup_with / 2 + myWidth);
    var popup_top = (window.screen.height / 2) - (popup_height / 2 + myHeight);
    var fenster = window.open(popup_url, popup_name,
		"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" +
		popup_with + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top +
		",screenX=" + popup_left + ",screenY=" + popup_top);

    fenster.focus();
}

///common/scripts/centerPopup.js
function centerPopup(popup_name,popup_url,popup_with,popup_height,myWidth,myHeight)
{   if(!myWidth) {myWidth = 0;}
	if(!myHeight){myHeight = 0;}
	var popup_left = (window.screen.width/2)  - (popup_with/2 + myWidth);
	var popup_top  = (window.screen.height/2) - (popup_height/2 + myHeight);
	var fenster = window.open(popup_url ,popup_name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + popup_with + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top + ",screenX=" + popup_left + ",screenY=" + popup_top);
	fenster.focus();
}

//
