/*
 * Custom JS 0.0.9
 * Copyright(c) 2006-2007, Atmosphere CPH
 * ml@atmosphere-cph.com
 * 
 * http://www.atmosphere-cph.com
*/

var menuBackgrounds = Array();
for (var i = 1; i <= 9; i++) {
    menuBackgrounds[i] = (-19 - 97*(i-1));
}

var swfID;
var flashObj;
var bFlashReady = false;
var loginWindowHeight;
var aCompWinners = new Array();
var iCurrentCompPage = 0;


$(document).ready(function(){

    $('#GaetResultatOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/gaet_resultat/open");
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#4c85ca", overflow: "visible"} );
        this.blur(); 
        return false;
     });
     
     $('#VindereGaetResultatOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/gaet_resultat/tidligere_vindere/open");
            displayDialog($(this), true);
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#4c85ca", overflow: "visible"} );
        this.blur(); 
        return false;
     });
    
    $('#tipEnVenOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/send_til_en_ven/send_til_en_ven_pil/clicked");
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#f58220", overflow: "visible"} );
        this.blur(); 
        return false;
     });

    $('#disclaimerOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#fff", overflow: "visible"} );
        this.blur(); 
        return false;
     });

    $('#kontaktOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/dialog/kontakt");
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#fff", overflow: "visible"} );
        this.blur(); 
        return false;
     });

    $('#ansvarOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/dialog/ansvar");
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#fff", overflow: "visible"} );
        this.blur(); 
        return false;
     });
     
    $('#konkurrenceOpen').bind('click', function() { 
        if($('#window').css('display') == 'none') { 
            urchinTracker("/dialog/konkurrencebetingelser");
            displayDialog($(this));
        }
        $("#windowTopContent/DIV").css( { fontSize : "14px" , color : "#fff", overflow: "visible"} );
        this.blur(); 
        return false;
     });

    $('#windowClose').bind('click',function(){ 
            $('#window').hide(); 
    });

    getLoginStatus();
    
    $("DIV#forgottenPwError").hide();

	if(typeof sIFR == "function"){
	    sIFR.bHideBrowserText = false;
	    sIFR.bFixFragIdBug = false;
	    sIFR.replaceElement("SPAN.boxHeader", named({sFlashSrc: "resources/swf/MetaPlusBold.swf", sHoverColor: "#f58220" , sLinkColor : "#FFFFFF", sColor: "#ffffff", sBgColor : "#333333", sFlashVars : "offsetTop=-2", sWmode : "opaque" }));
	    sIFR.replaceElement("SPAN#forumHeader", named({sFlashSrc: "resources/swf/MetaPlusBold.swf", sHoverColor: "#f58220" , sLinkColor : "#FFFFFF", sColor: "#ffffff", sBgColor : "#333333", sFlashVars : "offsetTop=-2", sWmode : "opaque" }));
	    sIFR.replaceElement("SPAN.boxHeaderGreen", named({sFlashSrc: "resources/swf/MetaPlusBold.swf", sHoverColor: "#f58220" , sLinkColor : "#FFFFFF", sColor: "#4e9700", sBgColor : "#333333", sFlashVars : "offsetTop=0", sWmode : "opaque" }));
	    sIFR.setup();
	}
	
	$("DIV#menu/DIV[@id^=menuItem]").each(function(i){
          var currentItem = $("INPUT#currentPage").val();
	      if (currentItem == $(this).attr("id")){
	        $(this).css( "background-position" , (menuBackgrounds[i+1]+"px" + " " +"0px") );
	      }
	    $(this).hover( function(){ 
	      if (currentItem != $(this).attr("id")){
	        $(this).css( "background-position" , (menuBackgrounds[i+1]+"px" + " " +"0px") );
	      }
        },function(){ 
	      if (currentItem != $(this).attr("id")){
	        $(this).css( "background-position" , (menuBackgrounds[i+1]+"px" + " " +"-39px") );
	      }
        }).click( function() {
                window.location.href=$(this).find("A").attr("href");
            }
        ).css("cursor", "pointer").find("A").html("");
    });
    
	$("DIV#emergencyExit").hover( function(){ 
      $(this).css( "background-image" , "url(resources/images/noedudgang.jpg)" );
    },function(){ 
      $(this).css( "background-image" , "none" ); 
    }).click(
        function() {
            urchinTracker("/outgoing/noedudgang");
            window.location.href="http://www.borsen.dk";
        }
    ).css("cursor", "pointer");
    
    $("DIV#topLink").click( function() {
        window.location.href='Default.aspx';
    }).css("cursor", "pointer");
    
   // INTERFACE
   
   try {
      document.execCommand('BackgroundImageCache', false, true);
    } catch(e) {}
});

function openGaetResultatPop() {
   //alert("open it!");
   //displayDialog($("#GaetResultat"));

   document.getElementById("GaetResultatBoxContent").display = 'block';
}

function displayDialog(target, isShowWinners) {
    $("#heightMeasure").html($("#"+target.attr('rel')+"BoxContent").html());
    $("#windowTopContent/DIV").text($("#heightMeasure/FORM").attr("title"));
    $('#window').show();
    $("#window").css({ height: $("#heightMeasure").height()+20});
    $("#windowContent").css({ height: $("#heightMeasure").height()+5});
    $("#windowBottom").css({height: $("#heightMeasure").height()+20});
    $("#windowBottomContent").css({height: $("#heightMeasure").height()+20});
    if(isShowWinners) {
        document.getElementById("windowContent").style.top = "30px";
        //$("#windowContent").css({ top:30px;})
        showVindereGaetResultat();
    }
    else {
        document.getElementById("windowContent").style.top = "40px";
    }
}

function getLoginBox() {
    $("DIV#LoginBoxPh").load("includes/elements/Login.aspx",{},function() {
        $('#loginOpen').bind('click', function() { if($('#window').css('display') == 'none') { displayDialog($(this));}this.blur(); return false;});
    }); 
 }

function getID() {
   if (navigator.appName.indexOf("Microsoft") > -1) {
      flashObj = window[swfID];
   } else {
      flashObj = document[swfID];
   }
}

function openWindow(sURL) {
    window.open(sURL);
}

/*
QUIZ STUFF
*/

/*var oFlashObjArray = new Array();
var oQuiz1 = new Object();
var oQuiz2 = new Object();
var oQuiz3 = new Object();
var oQuiz4 = new Object();
var sQuizOverviewHTML = "";*/

/*function initQuiz() {
    oQuiz1.link = "../resources/swf/quiz_testgirlfriend/quiz_testgirlfriend.swf";
    oQuiz1.width = "721px";
    oQuiz1.height = "371px";
    oQuiz1.bgcolor = "#000000";

    oQuiz2.link = "../resources/swf/quiz_testgirlfriend/quiz_testgirlfriend.swf";
    oQuiz2.width = "721px";
    oQuiz2.height = "371px";
    oQuiz2.bgcolor = "#000000";

    oQuiz3.link = "../resources/swf/quiz_testgirlfriend/quiz_testgirlfriend.swf";
    oQuiz3.width = "721px";
    oQuiz3.height = "371px";
    oQuiz3.bgcolor = "#000000";

    oQuiz4.link = "../resources/swf/quiz_testgirlfriend/quiz_testgirlfriend.swf";
    oQuiz4.width = "721px";
    oQuiz4.height = "371px";
    oQuiz4.bgcolor = "#000000";

    oFlashObjArray[1] = oQuiz1;
    oFlashObjArray[2] = oQuiz2;
    oFlashObjArray[3] = oQuiz3;
    oFlashObjArray[4] = oQuiz4;
}

function setQuizOverviewHTML() {
    sQuizOverviewHTML += '<div class="element">';
    sQuizOverviewHTML += '<div class="imagebox">';
    sQuizOverviewHTML += '<div class="top"></div>';
    sQuizOverviewHTML += '<div class="content"><img src="../resources/images/pic_quizimage_1.jpg"></div>';
    sQuizOverviewHTML += '<div class="bottom"></div></div>';
    sQuizOverviewHTML += '<div class="textbox"><div class="top"></div><div class="content"><span class="header">Test din k&#230;reste&#8230;</span>';
    sQuizOverviewHTML += '<p>Du kender hende ud og ind, og har allerede en fornemmelse, men nu kan du f&#229; det i procent. Hvor meget procent Janni er din k&#230;reste? Vores specialudviklede test stiller en r&#230;kke sp&#248;rgsm&#229;l fra sportens verden. Og du svarer ud fra dit indg&#229;ende kendskab til din k&#230;restes paratviden!</p>';
    sQuizOverviewHTML += '<div class="link"><a href="TestKaereste.aspx"><img src="../resources/images/bn_quizelement_arrow.gif" border="0"></a></div><div class="bottom"></div></div></div></div>';
    
    sQuizOverviewHTML += '<div class="element">';
    sQuizOverviewHTML += '<div class="imagebox"><div class="top"></div><div class="content"><img src="../resources/images/pic_quizimage_3.jpg"></div><div class="bottom"></div></div>';
    sQuizOverviewHTML += '<div class="textbox"><div class="top"></div><div class="content"><span class="header">Drenger&#248;vs-testen</span>';
    sQuizOverviewHTML += '<p>Kalder du dig selv for drenger&#248;v. Eller er du godt tr&#230;t af at blive kaldt det? S&#229; er det p&#229; h&#248;je tid at f&#229; taget drenger&#248;vstesten. Her f&#229;r du nemlig din n&#248;jagtige drenger&#248;vs-procent. M&#229;lt p&#229; de vigtigste drenger&#248;vs-parametre. Og bearbejdet i en avanceret computerberegningsmodel&#8230; </p>';
    sQuizOverviewHTML += '<div class="link"><a href="TestDrengeroev.aspx"><img src="../resources/images/bn_quizelement_arrow.gif" border="0"></a></div><div class="bottom"></div></div></div></div>';
    
    sQuizOverviewHTML += '<div class="element">';
    sQuizOverviewHTML += '<div class="imagebox"><div class="top"></div><div class="content"><img src="../resources/images/pic_quizimage_4.jpg"></div><div class="bottom"></div></div>';
    sQuizOverviewHTML += '<div class="textbox"><div class="top"></div><div class="content"><span class="header">Kend din kommentator</span>';
    sQuizOverviewHTML += '<p>De st&#248;rste sports&#248;jeblikke bliver gjort uforglemmelige af ordene fra kommentatorerne. Og enhver &#230;gte sportsfan har naturligvis styr p&#229;, hvem der sagde: &#8221;Huttelihut&#8221; eller hvem der r&#229;bte &#8221;Det er genialt&#8221;. Tag vores test og find ud af, hvor mange procent kommentatorekspert du er&#8230;</p>';
    sQuizOverviewHTML += '<div class="link"><a href="TestKommentator.aspx"><img src="../resources/images/bn_quizelement_arrow.gif" border="0"></a></div><div class="bottom"></div></div></div></div>';
    
    sQuizOverviewHTML += '<div class="element">';
    sQuizOverviewHTML += '<div class="imagebox"><div class="top"></div><div class="content"><img src="../resources/images/pic_quizimage_2.jpg"></div><div class="bottom"></div></div>';
    sQuizOverviewHTML += '<div class="textbox"><div class="top"></div><div class="content"><span class="header">Karriere-eksperten</span>';
    sQuizOverviewHTML += '<p>Det er ikke kun p&#229; banen, at det g&#229;r hurtigt. Spillere k&#248;bes og s&#230;lges konstant. Det betyder, at der er masser at holde styr p&#229; for en &#230;gte sportsfan. Tag vores spiller-karriere-test, og se om du scorer h&#248;jt eller om du ender med at blive sat p&#229; b&#230;nken&#8230;</p>';
    sQuizOverviewHTML += '<div class="link"><a href="TestKarriere.aspx"><img src="../resources/images/bn_quizelement_arrow.gif" border="0"></a></div><div class="bottom"></div></div></div></div>';
}
function createContent() { 
   //if(iNum == 0) {
        document.getElementById("quiz_container").innerHTML = sQuizOverviewHTML;
  //}
   else {
        var oFlashObj = oFlashObjArray[iNum];
        document.getElementById("quiz_container").innerHTML = "";
        //document.getElementById("quiz_container").innerHTML = createFlashObject("quiz_container",oFlashObj.link,oFlashObj.width, oFlashObj.height, oFlashObj.bgcolor, "", "", null, "best", "false", "transparent");
        document.getElementById("quiz_container").innerHTML
   }
}*/


function showLink(sLink) {	
	if(sLink.substring(11,18) == "youtube" || sLink.substring(7,14) == "youtube" || sLink.substring(4,11) == "youtube" || sLink.substring(0,7) == "youtube") {
		embedYoutube(sLink);
	}
	else {
		window.open(sLink);
	}
}

function getId(sLink) {
	var sTemp = "";
	var sReturn = "";
	for(var i = 0;i<sLink.length; i++) {
		sTemp = sLink.substring(i, i + 1);
		if(sTemp == "?") {
			sReturn = sLink.substring(i + 3, sLink.length);
			return sReturn;
		}
	}
}

function embedYoutube(sLink) {
	var sMovieId = getId(sLink);
	var sHTML = ''
	sHTML += '<table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2" height="5"></td></tr><tr><td valign="top" align="center" width="435"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/' + sMovieId + '&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' + sMovieId + '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></td>';
	sHTML += '<td valign="top" style="padding-left:0px 2px;"><a href="javascript:closeYoutubeEmbed()">x</a></td></tr><tr><td colspan="2" height="5"></td></tr></table>';
	var oDiv = document.getElementById("youtubeembed");
	oDiv.innerHTML = sHTML;
	oDiv.style.display = 'block';
}

function closeYoutubeEmbed() {
    var oDiv = document.getElementById("youtubeembed");
	oDiv.innerHTML = '';
	oDiv.style.display = 'none';
}

/*function showVideoEmbed(sFileName) {
    var oVideoPop = document.getElementById("videoembed");
    var sEmbedCode = '<object width="425" height="355"><param name="movie" value="' + sFileName + '"></param><param name="wmode" value="transparent"></param><embed src="' + sFileName + '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
    alert(oVideoPop);
    alert(sEmbedCode);
    oVideoPop.innerHTML = sEmbedCode;
    oVideoPop.style.display = 'block';
}*/

function setCompetitionWinners() {
    aCompWinners[0] = "23*Peter Bruun, Herning*Mogens Bjerre, Slagelse*Carsten Lillegaard,  Odense N&Oslash;*Peter Bilstrup Rasmussen, K&oslash;benhavn &Oslash;*S&oslash;ren korsh&oslash;j, Br&oslash;nsh&oslash;j";
    
}

function getCompValue(iPos, iValuePos) {
    var aTemp = aCompWinners[iPos].split("*");
    return aTemp[iValuePos];
}
setCompetitionWinners();