/* Smaller scripts gathered - lesser http req */

function openPlayer(){
    var player = window.open("http://player.minradio.no/Player.aspx?playerkey=startsiden_no", "NWRPlayer", "width=565,height=500,scrollbars=no,resizable=no");
    player.focus();
    window.setTimeout("proceed();", 1000);
}

function proceed(){
    if (window.opener != null) {
        window.close();
    }
}

function findPos(obj){
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
        while (obj = obj.offsetParent);
        return [curleft, curtop];
    }
}

var readMoreLess = {

initialize:
    function() {
        this.moreContent = document.getElementById('flere_pekere');
        this.lessButton = document.getElementById('read_less');
        this.moreButton = document.getElementById('read_more');
    },
more:             
    function() {
        this.toggleAll();
        this.moreContent.scrollIntoView(true);
    },
less:              
    function() {
        this.toggleAll();
    },
toggleAll:         
    function() {
        this.toggle(this.moreContent);
        this.toggle(this.moreButton);
        this.toggle(this.lessButton);
    },
toggle: 
    function(el) {
        if (el.className.match('hidden')) this.show(el)
        else this.hide(el);
    },
hide:
    function(el) {
        el.className = el.className.replace('visible','hidden');
    },
show:
    function(el) {
        el.className = el.className.replace('hidden','visible');
    }
};



$().ready(function() {
    
    /* 
     * mega board magic
     */
    var d = document, megaBoard = d.getElementById('eas_ad_megaboard'), rightCol = d.getElementById('subcontent');
    readMoreLess.initialize();
    if(!megaBoard) return;
    var megaBoardPosTop = findPos(megaBoard)[1], rightColBottom = findPos(rightCol)[1] + rightCol.clientHeight;
    
    if (megaBoardPosTop < rightColBottom) {
        var heightDiff = rightColBottom - megaBoardPosTop;
        megaBoard.style.marginTop = (heightDiff + 10) + "px";
    }

    /* /okonomi_og_naringsliv/ 
     * we go to the nettbank the user choose
     */
    var nj=$("#nettbankjump");
    nj.change(function(){
        if($(this).val() == 'null') return;
        window.location = $(this).val();
    });    
    
});

var $tab = $('#ngm_header li span');
var $content = $('#ngm_content');
$content.addClass('ngm-index');

$contentt = 'concat_0';
$innhold = document.getElementById($contentt).innerHTML;
document.getElementById('ngm_content').innerHTML = $innhold;   

$('#cat_0').addClass('selected');

changeIDs(1);

$tab.click(function() {
var $catId = $(this).parent().attr('id');

    $(this).parent().siblings().removeClass('selected');
    $(this).parent().addClass('selected');

    $contentt = 'con' + $catId;
    $innhold = document.getElementById($contentt).innerHTML;
    document.getElementById('ngm_content').innerHTML = $innhold;
    
    if( $contentt == 'concat_0'){
        $content.removeClass('ngm-category');
        $content.addClass('ngm-index');
        changeIDs(1);
        
    }
    else {
        $content.removeClass('ngm-index');
        $content.addClass('ngm-category');
        changeIDs(0);
    }

    $('#selected_links ul:first').bxSlider({
        mode: 'fade',
        auto: true,
        autoStart: true,
        autoHover: true,
        controls: false,
        infiniteLoop: false,
        speed: 1000,
        randomStart: true
    });
    
    $.getScript("/img/skin/default/js/categoryfinder-008.js", "script", true);
});

function changeIDs(popul){
    $("#ngm .ngm-dynamic").each(function() {
       var oldID = $(this).attr("id");
       var newIDlength = oldID.length - 2;
       var newID = oldID.substring(0,newIDlength);
       $(this).attr("id", newID);
       $(this).removeClass("ngm-dynamic");
       
       if ($(this).attr("id") == "categoryfinderfield") {
        $(this).addClass("categoryfinderfield input-search ac_input");
       }
    });
}

/* Navigato to selected Nettbank og Kalkulator */
function jumpSelect(targ,selObj,restore){
        var toURL = selObj.options[selObj.selectedIndex].value;
        _lpAPI.logClick({
                category:[selObj.id],
                fromUrl:location.href,
                toUrl:toURL
        });
        if(toURL != "none"){
          eval(targ + ".location='" + toURL + "'");
        }
}
