﻿var countdownTime = 2;
var countdownIndex = 0;
var countdownActive = false;

function ChangeContactMap(filename) {
    $('img.contactmap').attr('src', '/App_Themes/Standard/images/' + filename);
}
function ChangeFrontpageTab(index) {
    $('a#tab_products').removeClass('selected');
    $('a#tab_solutions').removeClass('selected');
    $('a#tab_referenses').removeClass('selected');

    $('div#tab_products_content').hide();
    $('div#tab_solutions_content').hide();
    $('div#tab_referenses_content').hide();

    if (index == 1) {
        $('a#tab_products').addClass('selected');
        $('div#tab_products_content').show();
    }
    else if (index == 2) {
        $('a#tab_solutions').addClass('selected');
        $('div#tab_solutions_content').show();
    }
    else if (index == 3) {
        $('a#tab_referenses').addClass('selected');
        $('div#tab_referenses_content').show();
    }

    return false;
}
function PositionProductPopup() {
    var ppp = $('div.navholder').position();
    var newtop = ppp.top + 40;
    var newleft = ppp.left + 360;

    $('div.productpopup').css('top', newtop.toString() + 'px');
    $('div.productpopup').css('left', newleft.toString() + 'px');
}
function PositionAndShowProductPresPopup(tr, div) {
    var trp = $(tr).position();
    var newtop = trp.top - 220;
    var newleft = trp.left + 100;

    $(div).css('top', newtop.toString() + 'px');
    $(div).css('left', newleft.toString() + 'px');
    $(div).show();
}
function StartCountdownProductPopupHide() {
    if (!countdownActive) {
        countdownActive = true;
        $(document).everyTime(1000, 'popupframe', function () {
            CountdownProductPopupHide();
        });
    }
}
function CountdownProductPopupHide() {
    if (countdownIndex > 0) { countdownIndex = countdownIndex - 1; }
    if (countdownIndex == 0) {
        $('div.productpopup').hide();
        countdownActive = false;
        $(document).stopTime('popupframe');
    }
}

$(document).ready(function () {
    /*
    * Position the productgroup-popup dialog correctly for all browsers
    */
    PositionProductPopup();

    /*
    * Show the productgroup-popup dialog when the mouse enters the 'Produkter'-link
    */
    $('a#productgrouppopuplink').mouseenter(function () {
        $('div.productpopup').show();
        countdownIndex = countdownTime * 100;
        StartCountdownProductPopupHide();
    });
    $('a#productgrouppopuplink').mouseleave(function () {
        countdownIndex = countdownTime;
    });
    $('div.productpopup').mouseenter(function () {
        countdownIndex = countdownTime * 100;
    });
    $('div.productpopup').mouseleave(function () {
        countdownIndex = countdownTime;
    });
});