﻿var strEasingFunction = "easeOutExpo";
var blnCustomerOpened = false;
$(document).click(function () {
    if (blnCustomerOpened) {
        fnHideBigCustomerLogin();
    }
});
$(document).ready(function () {

    //$('#contentfoldings').jScrollPane({ scrollbarWidth: 48, scrollbarMargin: 20 });
    //$('#contentequipment').jScrollPane({ scrollbarWidth: 48, scrollbarMargin: 20 });

    $("#quotereqshadow").dropShadow({ left: 4, top: 4, opacity: 1, blur: 3, color: "#EAEBED" });
    $('.roundedbut').corners("20px 5px 5px 5px");
    $(".watermarked").watermark('watermark', 'Comments');
    $("#ulpagging").quickPager();
    $("#eventpagging").quickPager();
    
    $("#btnLogin").click(fnOpenCustomerLogin);
    $("#btnSend").click(fnOpenCustomerLogin);
    $("#loginopened").bind("mouseover", function () { blnCustomerOpened = false; });
    $("#loginopened").bind("mouseout", function () { blnCustomerOpened = true; });

    $("#spnHomeEvents").click(function () {
        $("#newsfeed").hide();
        $("#eventfeed").show();
        $("#spnHomeNews").attr("class", "homefeednormal");
        $("#spnHomeEvents").attr("class", "homefeedselected");

    });

    $("#spnHomeNews").click(function () {
        $("#eventfeed").hide();
        $("#newsfeed").show();
        $("#spnHomeNews").attr("class", "homefeedselected");
        $("#spnHomeEvents").attr("class", "homefeednormal");
    });

    //RoundedTop("div#nav li", "transparent", "#BEFF9A");
    var i;
    var v = getElementsBySelector("div#nav li");
    for (i = 0; i < v.length; i++) {
        if (i == 0) {
            AddTop(v[i], "transparent", "#8EC455", null);
        }
        if (i == 1) {
            AddTop(v[i], "transparent", "#4CAE71", null);
        }
        if (i == 2) {
            AddTop(v[i], "transparent", "#65B3C9", null);
        }
        if (i == 3) {
            AddTop(v[i], "transparent", "#5DA0A9", null);
        }

    }

    //submenu    
    $('a.panel2').bind("mouseover", onSubMenuMouseOver);
    $('a.panel2').bind("mouseout", onSubMenuMouseOut);

    var firstpage = $.bbq.getState("page", true) || 0;
    if (firstpage == "") {
        ChangeUrl("home");
    } else {
        $('#wrapper2').scrollTo("#" + firstpage, 1000, { onAfter: function () { ChangeUrl(firstpage); } });
        SetWindowsTitle(firstpage);
        SelectTabByPageName(firstpage);
    }

    //get all link with class panel
    $('a.panel2').click(function (event) {
        fnHideBigCustomerLogin();
        if (objCurrSubMenu != null) {
            ResetCurrentSubMenu();
        }
        ResetSelectedTab();

        objCurrSubMenu = $(this);

        $(this).unbind("mouseover");
        $(this).unbind("mouseout");

        //grab the current item, to be used in resize function
        current = $(this);

        //scroll it to the destination
        urllink = $(this).attr('href');
        urllink = urllink.replace("#", "");

        //$('#wrapper2').scrollTo($(this).attr('href'), 800, { onAfter: function () { ChangeUrl(urllink); } });
        ChangeUrl(urllink);

        return false;
    });

    // Bind an event to window.onhashchange that, when the history state changes,
    // gets the url from the hash and displays either our cached content or fetches
    // new content to be displayed.
    $(window).bind('hashchange', function (e) {

        // Get the hash (fragment) as a string, with any leading # removed. Note that
        // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
        var url = $.param.fragment();
        if (url == "") {
            document.title = "Vista Color";
            return;
        }
        url = url.replace("page=", "");
        $('#wrapper2').scrollTo("#" + url, 1000, { onAfter: function (url) {
            url = url.replace("#", "");
            if (objCurrSubMenu != null) {
                ResetCurrentSubMenu();
            }
            ResetSelectedTab();

            SetWindowsTitle(url);
            SelectTabByPageName(url);

        }
        });
    })
});
function fnHideBigCustomerLogin() {
    $("#loginopened").hide();
}
function fnOpenCustomerLogin() {
    blnCustomerOpened = true;
    $("#loginopened").show("fast", function () {
        //blnCustomerOpened = true;
    });
}
function SetWindowsTitle(url) {
    //updating windows title
    var ch = '';
    var character = "";
    var i = 0;
    while (i <= url.length) {
        character = url.charAt(i);
        if (!isNaN(character * 1)) {
            ch += character;
        } else {
            if (character == character.toUpperCase()) {
                ch += " " + character;
            }
            if (character == character.toLowerCase()) {
                ch += character;
            }
        }
        i++;
    }

    if (url == "home") {
        document.title = "Vista Color";
    } else {
        document.title = "Vista Color : " + ch;
    }
}
function SelectTabByPageName(firstpage) {
    //alert("#menu #nav #VistaColor" + firstpage)
    var obj = $("#menu #nav #VistaColor" + firstpage)
    if (obj.children()[0] == null) {
        obj = $("#VistaColor" + firstpage)
        objCurrSubMenu = obj;
        $(obj).attr("class", "hover");
        return;
    }
    var dd = obj.children()[0];
    var a = dd.childNodes;
    for (i = 0; i < a.length; i++) {
        a[i].style.backgroundColor = "#EEF2F5";
    }
    objTabSelected = $("#menu #nav #VistaColor" + firstpage).children()[1];
    objTabSelectedId = "VistaColor" + firstpage;
    objTabSelectedColor = $(dd).attr("name");
    obj.attr("id", "selected");
    $(objTabSelected).unbind("mouseover");
    $(objTabSelected).unbind("mouseout");
}

var objCurrSubMenu = null;
var urllink;

function ChangeUrl(title) {
    //    $.address.value(title);
    var state = {}
    state["page"] = title;
    $.bbq.pushState(state);
    return false;
}

function ResetCurrentSubMenu() {
    if (objCurrSubMenu != null) {
        $(objCurrSubMenu).attr("class", "normal");
        $(objCurrSubMenu).bind("mouseover", onSubMenuMouseOver);
        $(objCurrSubMenu).bind("mouseout", onSubMenuMouseOut);
    }
}

function onSubMenuMouseOver(e) {
    $(this).attr("class", "hover");
}
function onSubMenuMouseOut(e) {
    $(this).attr("class", "normal");
}

function resizePanel() {

    //get the browser width and height
    width = $(window).width();
    height = $(window).height();

    //get the mask height: height * total of items
    mask_height = height * $('.item').length;

    //set the dimension		
    $('#wrapper2, .item').css({ width: width, height: height });
    $('#mask').css({ width: width, height: mask_height });

    //if the item is displayed incorrectly, set it to the corrent pos
    $('#wrapper2').scrollTo($('a.selected').attr('href'), 0);

}

