﻿$("html").addClass("js");
$(document).ready(function(){
//  MSIE 6 only
    var IE6 = false;
	if ($.browser.msie && $.browser.version < 7) { 
        IE6 = true;
	}
	if (IE6) {
		// Set default transparent gif-file
		$.ifixpng.pixel = "/Files/System/js/pixel.gif"; 
	
		// PNG-fix on all png img-elements
		$("img[@src$=.png]").ifixpng(); 
	
		// Turn off Image Tool Bar on background image under navigation
		$("#bg img").attr({galleryimg: "no"}); 
		
		//$("#forside_top").css({zIndex:100;});
	}

	   
//  Tabpanel on frontpage
    if($("#tabs").length) {
        $("#tabs").addClass("js");

        var tab = $(".tab");
        
        var s = new Array();
	    s.push('<ul>');
	   
        for (var i=0;i<tab.length;i++) {
    	    s.push('<li><a href="#'+tab[i].id+'">'+tab[i].title+'</a></li>');
    	    tab[i].title = "";
    	    
        }
	    s.push('</ul>');
        $("#tabs .tabs .tabnavi").append(s.join(''));
        
        tab.appendTo("#tabs .tabs .tabpanel");

        $("h2.tab-header").hide();

        if (IE6) { // IE6 only
	        $("#tabs").idTabs();
        } else {
	        $("#tabs").idTabs(function(id,list,set){
	            $("a",set).removeClass("selected") 
                    .filter("[@href$='"+id+"']",set).addClass("selected"); 
                    for(i in list) 
                        $(list[i]).hide(); 
                $(id).fadeIn(1000); 
                return false;
	        });
        }

	    $("#tabs").show();

        //window.setTimeout(function() {
	        var tabs = $("#tabs .tabs .tabpanel .tab");
	        var maxHeight = 0;
            for (var i=0;i<tabs.length;i++) {
    	        if ($(tabs[i]).height() > maxHeight) {
                    maxHeight = $(tabs[i]).height();
    	        }
            }
            $("#tabs .tabs .tabpanel .tab").css("min-height",maxHeight);
            if (IE6) {
                $("#tabs .tabs .tabpanel .tab").css("height",maxHeight);
            }
        //},10);
        
	    var _timeout_slideTabs = 7000;
        var _timer_slideTabs;
        
        var slideTabs = function() {
            var $curr = $("#tabs .tabnavi a.selected");
            var $next = $curr.parent().next();
            if($next.length) {
                $next.find("a:first").click();
            } else {
                $("#tabs .tabnavi a:first").click();
            }
            _start_slideTabs();
        }

        var _stop_slideTabs = function() {clearTimeout(_timer_slideTabs);}
        var _start_slideTabs = function() {_timer_slideTabs = setTimeout(function() { slideTabs(); }, _timeout_slideTabs);}

        _start_slideTabs();
        $("#tabs .tabnavi a").bind("click", function(e) { 
            _stop_slideTabs();
        });
	}   
	
	if($("#forum").length) {
	    var a = $("#forum a");
	    for (var i=0;i<a.length;i++) {
	        a[i].href = a[i].href.replace(/\&m=forum/i, "");
        }
	} 
	
//  Search box
	$('#q')
		.attr( "value", "Søg")
		.focus(function() {
			if (this.value == this.title) {
				this.value = "";
			}
		})
		.blur(function() {
			if (this.value == "") {
				this.value = this.title;
			}
		});
	
//  Menu
if (!IE6) {
    $('#menu a')
		.css( {backgroundPosition: "0 -57px"} )
		.not(".inpath")
		.not(".selected")
		.bind("mouseenter focus", function(e) {
		    $(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		.bind("mouseleave blur", function(e) {
		    $(this).stop().animate({backgroundPosition:"(0 -57px)"}, {duration:200})
		})
		
    $('#menu a.selected,#menu a.inpath')
		.css( {backgroundPosition: "0 0"} )
		
		/*.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		.focus(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -57px)"}, {duration:200})
		})
		.blur(function(){
			$(this).stop().animate({backgroundPosition:"(0 -57px)"}, {duration:200})
		})*/
}

	
});

writePrintAndSend = function (SendFriendURL) {
    document.writeln('<div id="sendToFriend"><a href="'+SendFriendURL+'" title="Send til en ven" class="send"onclick="return !window.open(this.href,\'sendfriend\',\'width=322,height=270\');"><span>Send</span></a></div>');
    document.writeln('<div id="printThis"><a href="javascript:window.print();" title="Udskriv siden" class="print"><span>Udskriv</span></a></div>');
}