function ieHover()
{
	var nav = document.getElementById("navigation");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function() 
			{
				this.className += " hover";
			}
			nodes[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}

if (window.attachEvent && !window.opera){
	window.attachEvent("onload", ieHover);
}
// ------------------------------------------------------------
// Returns the x coordinate of the specified object
// ------------------------------------------------------------
function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.clientLeft)
    {
        curleft += obj.clientLeft;
    }
    return curleft;
}
// ------------------------------------------------------------
// Returns the y coordinate of the specified object
// ------------------------------------------------------------
function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.clientTop)
    {
        curtop += obj.clientTop;
    }
    return curtop;
}

function adjustModules(hiddenFieldID)
{
    var hiddenField = document.getElementById(hiddenFieldID);
    if(hiddenField && hiddenField.value != '')
    {
        var values = '';
        if(hiddenField.value.endsWith(';'))
        {
            values = hiddenField.value.substring(0, hiddenField.value.length - 1);
        }
        var ModuleRows = values.split(';');
        
        for(var i = 0; i < ModuleRows.length; i++)
        {
            var ModuleIDs = ModuleRows[i].split(',');
            var maxHeight = 0;
            if (document.getElementById(ModuleIDs[0]) != null)
                maxHeight = document.getElementById(ModuleIDs[0]).clientHeight;
            for(var j = 0; j < ModuleIDs.length; j++)
            {
                if(document.getElementById(ModuleIDs[j]) != null && maxHeight < document.getElementById(ModuleIDs[j]).clientHeight)
                {
                    maxHeight = document.getElementById(ModuleIDs[j]).clientHeight;
                }
            }
            if(maxHeight > 0)
            {
                for(var k = 0; k < ModuleIDs.length; k++)
                {
                    if (document.getElementById(ModuleIDs[k]) != null)
                        document.getElementById(ModuleIDs[k]).style.height = maxHeight;                
                }
            }
            else{
                setTimeout("adjustModules('" +hiddenFieldID + "')",1000);
            }
        }
    }
}
function setBgColor(element, color)
{
    if(element)
    {
        element.style.backgroundColor = color;
    }
}

function ShowAmarantinImage(imageID,textID)
{
    var image = document.getElementById(imageID)
    var text =  document.getElementById(textID)
    if(image && text)
    {
        image.style.display = 'block';
        text.style.display = 'none';
    }
}
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}


// ------------------------------------------------------------
// Builds an html-page for printing
// ------------------------------------------------------------
function printPage(pagename, appRoot) {
    
    if (!window.print) {
        window.status = 'No print';
        return;
    }

    // Get the main content area and other stuff we need
    var contentdiv = document.getElementById('print-div');

    if (contentdiv) {
    
        var contentHtml = '<div style="width: 100%; padding: 30px 20px 0px 20px;">' + contentdiv.innerHTML + '</div>';
        //contentHtml += '<img src="/Templates/Styles/Images/exp_printmall_logo.gif" border="0" alt="Exportr&aring;det" style="margin-bottom: 30px;" />';

        var beginHtml =
		      '<html>' +
			  '<head>' +
			  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' +
			  '<link rel="stylesheet" type="text/css" href="' + appRoot + 'Templates/Styles/all.css">' +
			  '<title>Moderna Museet - ' + pagename + '</title>' +
			  '<style type="text/css">' +  
			    '.printExclude { visibility: hidden; position: absolute; top: 0px; height: 0px; }' +
			    'ul.tools-small { visibility: hidden; position: absolute; top: 0px; height: 0px; }' +
			    '.info { width: 100%; }' +
			    '.info-wide { width: 100%; }' +
			  '</style>' +
			  '</head>' +
			  '<body style="margin: 0px; background-image: none; background-color: #fff;">';

        var endHtml = '</body></html>';

        var printWin = window.open('about:blank', '', 'width=700,height=600,scrollbars=yes,toolbar=no');
        
        
        printWin.document.write(beginHtml + contentHtml + endHtml);

        //
        printWin.print();
        //printWin.close();
        printWin.document.close();
    }
}
function PlayGame(pagename, appRoot,flashurl,width,height) 
{
    if (flashurl != '') {

        window.open(appRoot +'Pages/FlashGame.aspx?flashUrl='+flashurl+'&width=' + width + '&height=' + height, '', 'width='+width+',height='+height+',scrollbars=no,toolbar=no');

    }
}

function resizeIframe(frameid) {

   var currentfr = document.getElementById(frameid);
   if (currentfr && !window.opera) {
       currentfr.style.display = "block";

       if (currentfr.contentDocument && currentfr.contentDocument.body && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
           currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight;
       else if (currentfr.Document && currentfr.Document.body && currentfr.Document.body.scrollHeight) //ie5+ syntax
       {
           if (currentfr.Document.body.scrollHeight == 35)	//Avantime fix for hiding iframe if empty.
               currentfr.style.display = "none";
           else
               currentfr.height = currentfr.Document.body.scrollHeight;
       }
       if (currentfr.addEventListener)
           currentfr.addEventListener("load", readjustIframe, false);
       else if (currentfr.attachEvent) {
           currentfr.detachEvent("onload", readjustIframe);
           currentfr.attachEvent("onload", readjustIframe);
       }

   }
}
//----------------
// Shows a YouTube video
//----------------
function showYoutubeVideo(url, insertIntoID, title, autoplay, width, height) {
    var swfObject;

    if (autoplay == true)
        autoplay = "&autoplay=1;"
    else
        autoplay = "";

    swfObject = new SWFObject(url + "&enablejsapi=1&playerapiid=ytplayer&color1=0x006699&color2=0x54abd6&rel=0" + autoplay, "ytapiplayer", width, height, "8", "#FFFFFF");
    swfObject.addParam("wmode", "transparent");
    swfObject.write(insertIntoID);

    // Send to SiteCatalyst
//    SendVideoToSC(title);
}

//---------------
// Send YouTube data to SiteCatalyst
//---------------
//function SendVideoToSC(videoTitle) {
//    var t = s_gi('exportradetswedishtrade');
//    if (t != null) {
//        t.linkTrackVars = 'prop10';
//        t.linkTrackEvents = 'None';
//        t.prop10 = videoTitle;
//        t.tl('YouTube: ' + videoTitle, 'o', 'YouTube');
//    }
//}

// ---------------
// Opens a dialog. The first parameter should be the dialog name.
// ---------------
//function openDialog() {
//    //gCounter = gCounter + 1;
//    var dialogName = arguments[0];
//    var dialog = document.getElementById('DialogContainer');
//    var hiddenField = document.getElementById(gDialogHiddenFieldId);

//// SiteCatalyst //////////////////////////////////////////////////////
////    try {
////        if (dialogName = "TipFriend") {
////            s.prop9 = "Tipsa van";
////        }
////        if (dialogName = "ObjectIntrestRegistration") {
////            s.prop9 = "Anmal intresse";
////        }
////    } catch (err) { }
//// ///////////////////////////////////////////////////////////////////

//    if (dialog && hiddenField) 
//    {
//        dialog.className = 'Dialog ' + dialogName;
//        hiddenField.value = '';
//        // Make a delimited string with the dialogname and parameters
//        for (var i = 0; i < arguments.length; i++) {
//            hiddenField.value += arguments[i];
//            if (i + 1 < arguments.length) hiddenField.value += '|';
//        }

//        //__doPostBack(gDialogHiddenFieldId, '');

//        hideWindowedControls();
//        showDialogBackground();
//    }
//}

// ---------------
// Closes the dialog-layer.
// ---------------
function closeDialog() {
    //gCounter = gCounter - 1;
    var dialog = document.getElementById('DialogContainer');
    var hiddenField = document.getElementById(gDialogHiddenFieldId);
    if (dialog && hiddenField) {
        dialog.style.display = 'none';
        hiddenField.value = '';
        __doPostBack(gDialogHiddenFieldId, '');

        hideDialogBackground();
        showWindowedControls();
    }
    var helpDialog = document.getElementById('DialogHelpContainer');
    var helphiddenField = document.getElementById(gHelpDialogHiddenFieldId);
    if (helpDialog) {
        helpDialog.style.display = 'none';
        helphiddenField.value = '';
        __doPostBack(gHelpDialogHiddenFieldId, '');
    }

}

// ---------------
// Sets the dialog layout. This one shall be called before openDialog()
// ---------------
function setDialogLayout(index) {
    var hiddenField = document.getElementById(gHiddenFieActiveDialogLayoutID);
    if (hiddenField)
        hiddenField.value = index;
} 

// ---------------
// Hides all windowed controls in browsers that
// can't display layers on top of them.
// ---------------
function hideWindowedControls()
{
	if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version < 7))
	{
	    // Hides all listboxes
		for (var i = 0; i < document.getElementsByTagName('select').length; i++)
		{
			document.getElementsByTagName('select')[i].style.visibility = 'hidden';
		}
	}
}

// ---------------
// Shows all windowed controls.
// ---------------
function showWindowedControls()
{
	if ((BrowserDetect.browser) == 'Explorer' && (BrowserDetect.version < 7))
	{
	    // Show all listboxes
		for (var i = 0; i < document.getElementsByTagName('select').length; i++)
	    {
		    document.getElementsByTagName('select')[i].style.visibility = 'visible';
	    }
    }
}

// ---------------
// Creates a semi-transparent div and places it over the entire screen.
// ---------------
function showDialogBackground()
{
	var bgDiv = document.getElementById('DialogBG');
	if (bgDiv)
	{
		var height = document.getElementById('outerdiv').clientHeight + 40;
		bgDiv.style.height	= height + 'px';
		bgDiv.style.display	= 'block';

		// IE6 and below needs a special class
		if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version < 7))
		{
			bgDiv.className = 'DialogBGIE6';
		}	
	}
}

// ---------------
// Hides the semi-transparent div
// ---------------
function hideDialogBackground()
{
	var bgDiv = document.getElementById('DialogBG');
	if (bgDiv)
	{
		bgDiv.style.display = 'none';
	}
}

// ---------------
// Positions the dialog layer in the center of the screen.
// ---------------
//function positionDialog()
//{
//	var dialog = document.getElementById('DialogContainer');
//	if (dialog)
//	{
//		var viewSize   = getViewportSize();
//		var scrollSize = getScrollOffset();
//		dialog.style.display = 'block';
//		
//		// Center window on screen
//		dialog.style.left = (scrollSize.x + (viewSize.width  - dialog.clientWidth)  / 2) + 'px';
//				
//		var marginTop = dialog.clientHeight>viewSize.height ? ((viewSize.height-dialog.clientHeight)/2):100;
//        var top = (scrollSize.y + ((viewSize.height - dialog.clientHeight) / 2) - marginTop);
//		if( top>scrollSize.y)
//		    dialog.style.top  = top  + 'px';    
//		 else
//		    dialog.style.top  = scrollSize.y  + 'px';    		 		
//	}
//}
function vIE() { return (navigator.appName == 'Microsoft Internet Explorer') ? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]) : -1; }