﻿var _isSitemapOpen = false;
var sm_tWidth = 46;
var sm_scroll_index = 0;
var sm_scroll_xPos = 50;

function initHpFooterSitemap() {

    $(".sm_thumb_dim").fadeTo(0, 0);

    $(".sm_arr_left").mousedown(function () {
        sm_moveThumbs(-1);
    });
    $(".sm_arr_right").mousedown(function () {
        sm_moveThumbs(1);
    });
    $(".sm_btnOpenTree").mousedown(function () {
        sm_toogleFooter(!_isSitemapOpen);
    });
    $('.sm_thumb').hover(function () {
        var tIndex = $('.sm_thumb').index(this);
        var imgObj = $(this).find("img");
        var imgH = $(imgObj).height();
        var imgY = 30 - imgH + 9;
        var tt = $(this).attr("tt");

        if (jQuery.browser.msie) {
            $(this).css("top", imgY + "px");
            $(this).css("height", imgH + "px");
            sm_setTooltip(tIndex, 90 - imgY, tt);
        }
        else {
            $(this).stop();
            $(this).animate({ height: imgH, top: imgY },{easing: 'easeInOutCubic', duration: 50, complete: function () {sm_setTooltip(tIndex, 90 - imgY, tt);}});
        }
    });

    $('.sm_thumb').mouseout(function () {
        $("#sm_tt").hide();
        var imgObj = $(this).find("img");
        if (jQuery.browser.msie) {
            $(this).css("top", "0px");
            $(this).css("height", "30px");
        }
        else {
            $(this).stop();
            $(this).animate({ height: 30, top: 0 },{easing: 'easeInOutCubic', duration: 400, complete: function () { }});
        }        
    });
}

function sm_setTooltip(itemIndex, yPos,ttText) {

    $("#sm_tt_text").html(ttText);
    var ttW = $("#sm_tt").width();
    var ttX = (itemIndex * sm_tWidth) + sm_scroll_xPos + (sm_tWidth / 2) - 3 - (ttW / 2);
    $("#sm_tt").css("left", ttX);
    $("#sm_tt").css("bottom", yPos);
    $("#sm_tt").show();
}

function sm_moveThumbs(direction) 
{
    var thumbCount = $('.sm_thumb').length;
    var thumbsWidth = sm_tWidth * thumbCount;
    var minX = getWindowWidth() - thumbsWidth - 45;//45=arrow width
    var maxThumbsMove = 3 + Math.ceil((thumbsWidth - getWindowWidth()) / sm_tWidth); //  thumbCount;
    var _tempIndex = sm_scroll_index + direction;
    if (_tempIndex > -1 && _tempIndex < maxThumbsMove) {
        var newX = 50 - (sm_tWidth * _tempIndex);
        sm_scroll_index = _tempIndex;
        sm_scroll_xPos = newX;
        $(".sm_slider").animate({ left: newX }, { duration: 80, complete: function () { } });
    }

}
function sm_jumpToThumbIndex(index) 
{
    var thumbCount = $('.sm_thumb').length;
    var thumbsWidth = sm_tWidth * thumbCount;
    var minX = getWindowWidth() - thumbsWidth - 45; //45=arrow width
    var maxThumbsMove = 2 + Math.ceil((thumbsWidth - getWindowWidth()) / sm_tWidth); //  thumbCount;//var maxThumbsMove = thumbCount;
    if (index > maxThumbsMove) {index = maxThumbsMove;}
    var tmpX = 50 - (sm_tWidth * index);
    newX = tmpX;
    sm_scroll_index = index;
    sm_scroll_xPos = newX;
    $(".sm_slider").animate({ left: newX }, { duration: 500, complete: function () { } });
}




function sm_toogleFooter(isOpen) {
    _isSitemapOpen = isOpen;
    var smY = 40;
    if (!_isSitemapOpen) {
        smY = -10;
        $(".sm_btnOpenTree").css("background-position", "0px 0px");
    }
    else {
        $(".sm_btnOpenTree").css("background-position", "0px -17px");
    }    
    $(".sm_wrapper").animate({ bottom: smY },
        {
            easing: 'easeInOutCubic',
            duration: 350, complete: function () {
            }
     });
}




function sm_removeHpHightlight() {
    if (IsHP == 'True') {
        $(".sm_thumb_dim").fadeTo(0, 0);
    }
}
function sm_highlightSectionFromMenu(junctionID) 
{
    var foundIndex = -1;
    $('.sm_thumb').each(function (index) {
        if ($(this).attr("jn") == junctionID) {
            if (foundIndex < 0) { foundIndex = index };
            $(this).find(".sm_thumb_dim").fadeTo(0, 0);
        }
        else {
            $(this).find(".sm_thumb_dim").fadeTo(0, 0.6);
        }
    });
    if (foundIndex > -1) {
        sm_jumpToThumbIndex(foundIndex);
    }
}



