﻿var countdownTime = 1;
var countdownIndex = 0;
var countdownActive = false;

function ChangeContactMap(filename) {
	$('img.contactmap').attr('src', '/App_Themes/Standard/images/' + filename);
}

function InitFrontpageTabs() {
	if($('div#TabServicesContent'))
		$('div#TabServicesContent').hide();
}

function ChangeFrontpageTab(index) {
	$('a#tab_products').removeClass('Selected');
	$('a#tab_solutions').removeClass('Selected');
	//$('a#tab_referenses').removeClass('Selected');

	$('div#TabProductsContent').hide();
	$('div#TabServicesContent').hide();
	//$('div#tab_referenses_content').hide();

	if (index == 1) {
		$('a#tab_products').addClass('Selected');
		$('div#TabProductsContent').show();
	}
	else if (index == 2) {
		$('a#tab_solutions').addClass('Selected');
		$('div#TabServicesContent').show();
	}
	//else if (index == 3) {
	//	$('a#tab_referenses').addClass('Selected');
	//	$('div#tab_referenses_content').show();
	//}

	return false;
}

function PositionProductPopup() {
	var ppp = $('li#ProductGroupPopupLink').position();
    var newtop = ppp.top + 26;
    var newleft = ppp.left - 35;

    $('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 () {
	InitFrontpageTabs();
	/*
	* Show the productgroup-popup dialog when the mouse enters the 'Produkter'-link
	*/
	if ($('li#ProductGroupPopupLink')) {
		$('li#ProductGroupPopupLink').mouseenter(function () {
			/*
			* Position the productgroup-popup dialog correctly for all browsers
			*/
			PositionProductPopup();
			$('div.ProductPopup').show();
			countdownIndex = countdownTime * 100;
			StartCountdownProductPopupHide();
		});
		$('li#ProductGroupPopupLink').mouseleave(function () {
			countdownIndex = countdownTime;
		});
	}
	if ($('div.ProductPopup')) {
		$('div.ProductPopup').mouseenter(function () {
			countdownIndex = countdownTime * 100;
		});
		$('div.ProductPopup').mouseleave(function () {
			countdownIndex = countdownTime;
		});
	}
});

function showCountryList(whichLayer) {
	var elem, vis;
	if (document.getElementById) // this is the way the standards work
		elem = document.getElementById(whichLayer);
	else if (document.all) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if (document.layers) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}
