// page object
var Page = new function(){
    // Utility functions object (all functions declared in utilities)
    this.Util = new Object();
    // Page element Objects array
    this.Objects = new Array();

    // defining Page.HOST, Page.GFX based on hosts page.js inclusion path
    this.SRC = document.getElementById("page.js") ? document.getElementById("page.js").src : false;
    if(this.SRC){
        this.HOST = this.SRC.replace("page.js", "");
        this.GFX = this.HOST+"/upload/images";
    }else{
        alert("Fejl%20i%20inkluderingen%20af%20page.html");
    }

}

/* obj_tabs.js|global */
Page.Objects["tabs"] = new function(){

    this.init = function(tabset){
        var tab, i;
        // select tab, closing open panels before opening new
        tabset.selectTab = function(tab){
            tab = typeof(tab) == "object" ? tab : this.tabs[tab];
            // unselect previously selected tab
            if(this.selectedTab){
                this.selectedTab.className = this.selectedTab.className.replace(/ selected|selected/g,"");
                this.selectedTab.panel.className = this.selectedTab.panel.className.replace(/ open|open/g,"");
            }
            // enable tab (in case is was inactive)
            this.enableTab(tab);
            // select tab
            tab.className += (tab.className) ? " selected" : "selected";
            tab.panel.className += (tab.panel.className) ? " open" : "open";
            this.selectedTab = tab;
        }

        // enable tab button
        tabset.enableTab = function(tab){
            tab = typeof(tab) == "object" ? tab : this.tabs[tab];
            tab.className = tab.className.replace(/ inactive|inactive/g,"");
            // set mouseover
            tab.onmouseover = function(){
                if(!this.className.match(/selected|inactive/g)){
                    this.className += (this.className) ? " over" : "over";
                }
            }
            // set mouseout
            tab.onmouseout = function(){
                this.className = this.className.replace(/ over|over/g,"");
            }
            // if element has a panel, set mousedown
            if(tab.panel){
                tab.onclick = function(event){
                    this.tabset.selectTab(this);
                }
            }
        }
        // disable tab button
        tabset.disableTab = function(tab){
            var i, replacement;
            tab = typeof(tab) == "object" ? tab : this.tabs[tab];
            tab.className = tab.className.replace(/ selected|selected/g,"");
            tab.className = tab.className.replace(/ over|over/g,"");
            tab.className += tab.className ? " inactive" : "inactive";
            // remove events
            tab.onmouseout = null;
            tab.onmouseover = null;
            tab.onclick = null;

            // check if panel is open
            if(tab == this.selectedTab){
                // try to replace open panel
                for(i = 0; replacement = this.tabs[i]; i++){
                    if(replacement != tab){
                        this.selectTab(replacement);
                        break;
                    }
                }
            }
        }
        
        tabset.tabs = Page.Util.getElementsByClassName("tab:([a-zA-Z0-9])+", tabset);
        for(i = 0; tab = tabset.tabs[i]; i++){
            Page.Util.unSelectify(tab);
            // tell each tab which tabset it belongs to and find its panel
            tab.tabset = tabset;
            tab.panel = this.getPanel(Page.Util.getTypeDefinitionByClassName("tab", tab), tabset);
            if(tab.className.match(/selected/g)){
                tabset.selectTab(tab);
            }
            if(!tab.className.match(/inactive/g)){
                tabset.enableTab(tab);
            }
        }
    }

    // get panel based on class/id relation
    this.getPanel = function(identifier, tabset){
        var i, panel;
        if(identifier){
            tabset.panels = Page.Util.getElementsByClassName("panel:([a-zA-Z0-9])+", tabset);
            for(i = 0; panel = tabset.panels[i]; i++){
                if(Page.Util.getTypeDefinitionByClassName("panel", panel) == identifier){
                    return panel;
                }
            }
        }
        return false;
    }

}

// --------------------
// iframe size START
//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("index.html")[1]
var FFextraHeight=getFFVersion>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller()
{
    var dyniframe=new Array()
    for (i=0; i<iframeids.length; i++)
    {
        if (document.getElementById)
            resizeIframe(iframeids[i])
        
        //reveal iframe for lower end browsers? (see var above):
        if ((document.all || document.getElementById) && iframehide=="no")
        {
            var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
            tempobj.style.display="block"
        }
    }
    setTimeout("resizeCaller()", 100);

}

function resizeIframe(frameid)
{
    var currentfr=document.getElementById(frameid)
    if (currentfr && !window.opera)
    {
        currentfr.style.display="block";
        if (currentfr.contentDocument != null && currentfr.contentDocument.body != null && currentfr.contentDocument.body.offsetHeight != null) //ns6 syntax
            currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight+10; 
        else if (currentfr.Document != null && currentfr.Document.body != null && currentfr.Document.body.scrollHeight != null) //ie5+ syntax
            currentfr.height = currentfr.Document.body.scrollHeight+10;
        
        if (currentfr.addEventListener)
            currentfr.addEventListener("load", readjustIframe, false)
        else if (currentfr.attachEvent)
        {
            currentfr.detachEvent("onload", readjustIframe) // Bug fix line
            currentfr.attachEvent("onload", readjustIframe)
        }
    }
}

function readjustIframe(loadevt) 
{
    var crossevt=(window.event)? event : loadevt
    var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
    if (iframeroot)
        resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url)
{
    if (document.getElementById)
        document.getElementById(iframeid).src=url
}
// iframe size END
// --------------------


function sagsvisning_setTabActive(activeTabId)
{
    sagsvisning_setTabsInactive();
    document.getElementById(activeTabId).className =
        document.getElementById(activeTabId).className.replace('Inactive', 'Active tabActive');
}

function sagsvisning_setTabsInactive()
{
    //Tab1 Casefacts
    if(document.getElementById('tab01') != null)    
        document.getElementById('tab01').className = document.getElementById('tab01').className.replace('Active tabActive', 'Inactive');
    //Tab2 Around the house, multimedia
    if(document.getElementById('tab02') != null)
        document.getElementById('tab02').className = document.getElementById('tab02').className.replace('Active tabActive', 'Inactive');
    //Tab3 Drawing of the house
    if(document.getElementById('tab03') != null)
        document.getElementById('tab03').className = document.getElementById('tab03').className.replace('Active tabActive', 'Inactive');
    //Tab4 Krak Map
    if(document.getElementById('tab04') != null)
        document.getElementById('tab04').className = document.getElementById('tab04').className.replace('Active tabActive', 'Inactive');
    //Tab5 Municipal Info
    if(document.getElementById('tab05') != null)
        document.getElementById('tab05').className = document.getElementById('tab05').className.replace('Active tabActive', 'Inactive');
}

function toggleDiv(divID, gotoTargetOnShow) {
    var oDiv = document.getElementById(divID);
    if (oDiv != null) {
        var display = oDiv.style.display;
        if (display == "none") {
            oDiv.style.display = "block";
            if (gotoTargetOnShow != "") document.location.href = "#" + gotoTargetOnShow;
        } else {
            oDiv.style.display = "none";
        }
    }
}