$(document).ready(function(){


   // Global Vars //
// for TAB tx-mfsces-pi10
window.activeTab = ':first';


// empty on click
$("input:text, textarea").focus(function(){
    if(typeof ($(this).attr('default')) == 'undefined' || $(this).val() == $(this).attr('default')){
        $(this).attr('default',$(this).val());
        $(this).val('');
    }
}).blur(function(){
    var newValue = $(this).val();
    if (newValue == '') {
        var myVal = $(this).attr('default');
        $(this).val(myVal);
    }
});


//Functions starts when the Document is Ready
// TAB tx-mfsces-pi10
hideTabs();



if($.trim($("div.toolbox").text()) != "") {
        $(".toolbox").ShowToolBox();
}

    if($.trim($("div.addToSidebar div.media div.mediaContainer").text()) != "") {
        $(".addToSidebar .mediaContainer").prependTo($("#sidebar"));
        $("#main").css("width","382px").css("float","left");
    }

        //IE6 Fix
    document.getElementById("navbar").style.width = "200px";
    
    var stageHeight = Math.max(document.getElementById('stage').offsetHeight);
    var navbarHeight = Math.max(document.getElementById('wholeNav').offsetHeight);
    var itemHeight = navbarHeight;

    if(navbarHeight < stageHeight){
        itemHeight = (stageHeight + 20);
        $('div.ccBox').css('position','absolute');
        $('div.ccBox').css('top',itemHeight +'px');
        $('div.ccBox').css('padding','0');

    }

 
    $('[id^="acc"]').removeClass('active');
    
   // Sitemap Single
    $('.twoSame p.expanded, .sitemapHead p.collapsed').click(function(){
        $(this).toggleClass('expanded');
        $(this).toggleClass('collapsed');
        $(this).next('ul').toggle();
    });

    // Sitemap All
    $('.sitemapHead p.collapsed').click(function(){
        if($('.sitemapHead p.collapsed').hasClass('collapsed')){
            $('.twoSame p.collapsed').each(function(key,item){
                $(item).toggleClass('expanded');
                $(item).toggleClass('collapsed');
                $(item).next('ul').toggle();
            });

        }else{
            $('.twoSame p.expanded').each(function(key,item){
                $(item).toggleClass('expanded');
                $(item).toggleClass('collapsed');
                $(item).next('ul').toggle();
            });
        }
        
    });
    
    
    
    // DL cleaning
    
    $('dt').each(function(dt){
        if($(this).text() == ''){
    	   $(this).next().remove();
    	   $(this).remove();
    	   
    	   
    	}
    });
    /*
     $('dd').each(function(dd){
        if($(this).html() == ''){
    	   $(this).remove();
    	}
    });
   */
    
    
    //Footer setzen
    var mope = document.getElementById("navbar").offsetHeight + 150;   
    if (mope > document.getElementById("container").offsetHeight) {
    	$('#container').css('min-height',mope);
    	if($.browser.msie && $.browser.version <= "7.0"){
    	    $('#container').css('height',mope);}	
    }    
    	
    
    
    // Main Navigation zusätzlicher Grauer Kasten unterhalb
    var $countNavs = 0;
    $('#wholeNav ul').each(function(ul){
            $countNavs++;
    });
    if($countNavs == 1){
        $('#wholeNav').append('<ul style="visibility: visible; height: 15px;border:0px;" class="subNav"/>');
    }
   
    /*
    // Nicht benötigte Punkte ausblenden
    $('ul.subNav:not(:last)').each(function(ul){
	$('ul.subNav li').each(function(li){
        	if($('ul.subNav:eq('+ul+') li:eq('+li+')').hasClass('active')){
            	$('ul.subNav:eq('+ul+') li:not(.active)').remove();
        	}
     	});
    });
    $('ul.subNav').css("visibility",'visible');
    */
    
    
        // Nicht benötigte Punkte ausblenden

    var mLi = 0;
    $('ul.subNav').each(function(ul){
        mLi++;
    });

    var mLiCount = 1;
    $('ul.subNav').each(function(ul){
	$('ul.subNav li').each(function(li){
            if(mLiCount != mLi){
                if($('ul.subNav:eq('+ul+') li:eq('+li+')').hasClass('active')){
                    $('ul.subNav:eq('+ul+') li:not(.active)').remove();
                }
            }
     	});
        mLiCount++;

    });
    $('ul.subNav').css("visibility",'visible');

    
    
    $('a').click(function(e){
        if($(this).attr('href') == '#'){
            //Cancel the link behavior
            e.preventDefault();
        }
    });





})

// Teaser tx_editmatrix
function toggleTeaser(item){
    $(item).parents('div:eq(0)').toggleClass('active');
};

// TAB tx-mfsces-pi10
function hideTabs(){
    $('p.tabby:not('+window.activeTab+')').hide();
};

function switchTab(jID){
    window.activeTab = '#'+jID;
    hideTabs();
    $('#'+jID).show();
}


// ACC tx-mfsces-pi10
function switchAcc(jID){
if(window.activeAcc == jID){
	$('[id^="acc"]').removeClass('active');
	window.activeAcc = '';
}else{
    $('ul.toggleList li.active:not(#'+jID+')').removeClass('active');$('#'+jID).addClass('active');
    	window.activeAcc = jID;
    }
}

function switchLL(LL){
    if($('#swLL').val() != '0'){
        location.href = $('#swLL').val();
    }
}


function openGeo(args)
{
    argsArr = args.split(",");
    id_country=argsArr[0];
    id_continent=argsArr[1];

    
    if(id_country != ''){
	location.href="index.php?id=413&L=0&tx_editfiltersystem_pi1[cmd]=search&tx_editfiltersystem_pi1[land]="+id_country+"&no_cache=1&L="+L;
    }
    
    if(id_continent != ''){
	//location.href="index.php";
    }
    
    
}
