﻿var g_StatusDoc;
var g_IsReady = false;
function UpdateUserElements(rq) {
    var count = parseInt(rq.find("CartItems").text());
    $("#CartItemCount").text(count.toString());
    var isAuthenticated = parseInt(rq.find("IsAuthenticated").text()) == 1;
    if (isAuthenticated) {
        $("#SignInText").text(rq.find("LoginText").text());
        $("#SignInLink").text(" [Sign Out]");
    } else {
        $("#SignInText").text("");
        $("#SignInLink").text("Sign In");
    }            
    $("#UserMenuItems").html(rq.find("MenuItems").text());
}
function rotateTile(container) {
    var tileList = $("#rotationList", container);
    var i = Math.floor(Math.random() * tileList.size());
    var tile = tileList.eq(i);
    //var imgNames = $("#rotationList", tile).val().split(',');
    var imgNames = tile.val().split(',');
    i = Math.floor(Math.random() * imgNames.length);
    var imgNameParts = imgNames[i].split(':');
    var imgName = imgNameParts[0];
    var width = imgNameParts[1];
    var height = imgNameParts[2];
    //var imgElement = tile.find("img");
    var imgElement = tile.next("img");
    var src = imgElement.attr("src");
    i = src.lastIndexOf('/');
    var j = src.lastIndexOf('.');
    src = src.substr(0, i + 1) + imgName + src.substr(j);
    imgElement.attr("style", "width:" + width + "px;height:" + height + "px");
    //imgElement.css("width", width);
    //imgElement.css("height", height);
    imgElement.attr("src", src);
}

$(document).ready(function() {
    g_IsReady = true;
    //if (g_StatusDoc != null)
    //    UpdateUserElements();

    $("#DepartmentCategoryMenu").accordion({ header: "h2", autoHeight: false, active: parseInt($("#CurrentDepartmentSelector").val()),
        change: function(event, ui) {
            $("#CurrentDepartmentSelector").val($(".ui-accordion-header").index(ui.newHeader));
        }
    });

    var tileListElement = $("#TileList");
    setInterval(function() { rotateTile(tileListElement) }, 1000);
    $("#SpotlightPanel > .tilePanel").each(function(i,e) { setInterval(function() { rotateTile(e) }, 2000) });
});
$(window).load(function() {
    $(".FB_SERVER_IFRAME").css('visibility', 'visible').show()
});

function tileSelected(tile) {
    var cname = $("h2", tile).text();
    var i = $(".ui-accordion-header").index($("h2:contains('" + cname + "')"));
    if (i < 0) i = 0;
    $("#CurrentDepartmentSelector").val(i);
}

var g_IsSearch = false;
function checkSearch() {
    var isSearch = g_IsSearch;
    g_IsSearch = false;
    return !isSearch;
}

