var currSize = 1;

function swichStyleSheetSrc(size) {
    var styleName = 'size'+size;
	$('link[@rel*=STYLE][@title]').each(function() {
        this.disabled = true;
        if($(this).attr('title')==styleName) {
            this.disabled = false;
        }
    });
    $.cookie('styles1',size,{expires:7,path:'/'});
}

function disableAll() {
	$('link[@rel*=STYLE]').each(function() {
        this.disabled = true;
    });
}

function openExternalWin(argURL) {
 externalWin = window.open(argURL, null, 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=760,height=500');
 if(externalWin != null) externalWin.focus();
}

function setBookmark() {

    var bookmarkurl = location.href;
    var text = document.title;
    text = text.replace(/:/ ,"");
    text = text.replace(/\*/ ,"");
    text = text.replace(/\?/ ,"");
    text = text.replace(/\\/ ,"");
    text = text.replace(/"/ ,"");
    text = text.replace(/</ ,"");
    text = text.replace(/>/ ,"");
    text = text.replace(/|/ ,"");
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(text, bookmarkurl,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( bookmarkurl, text);
    } else if(window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

$().ready(function() {

    $('#AddBookmark').click(function(){setBookmark(); return false;});
	
    if($.cookie('styles1')) {

        currSize = parseInt($.cookie('styles1'));
        var isActive = false;
        $('link[@rel*=STYLE][@title]').each(function() {
              if($(this).attr('rel').indexOf('ALTERNATE')==-1 && $(this).attr('title')=='size'+currSize) {
                    isActive = true;
              }

        });
        $('#fs_size'+currSize).addClass('active');
        if(!isActive) {
            swichStyleSheetSrc(currSize);
        }
    }
    var maxSizes = $('#FontSizer .size').size();
    if(maxSizes > 0) {
        if(currSize==1) {
            $('#fs_minus').addClass('disabled');
        } else if(currSize==maxSizes) {
            $('#fs_plus').addClass('disabled');
        }
        $('#FontSizer .size').click(function() {
            currSize = parseInt(this.id.replace(/fs_size/g,''));
            $('#FontSizer .size').each(function(){$(this).removeClass('active');});
            $(this).addClass('active');
            if(currSize==1) { $('#fs_minus').addClass('disabled');}
            else {$('#fs_minus').removeClass('disabled');}
            if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
            else {$('#fs_plus').removeClass('disabled');}
            swichStyleSheetSrc(currSize);
            return false;
        });
         $('#fs_minus').click(function(){
            if(currSize > 1) {
                currSize--;
                $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                $('#fs_size'+currSize).addClass('active');
                if(currSize==1) { $('#fs_minus').addClass('disabled');}
                else {$('#fs_minus').removeClass('disabled');}
                $('#fs_plus').removeClass('disabled');
                swichStyleSheetSrc(currSize);
            }
            return false;
         });
         $('#fs_plus').click(function(){
                 if(currSize < maxSizes) {
                     currSize++;
                     $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                     $('#fs_size'+currSize).addClass('active');
                     if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
                     else {$('#fs_plus').removeClass('disabled');}
                     $('#fs_minus').removeClass('disabled');
                     swichStyleSheetSrc(currSize);
                 }
                 return false;
         });
     }
     $('#glossarTable a').open();
     
     $('.popup .print,.popup .close').css({'cursor':'pointer'});
     $('.popup .print').click(function(){
                    window.print();
                    return false;
              });
              $('.popup .close').click(function(){
                    self.close();
                    return false;
     });
	//hidden inputs verstecken
	$("input[type='hidden']").css('display','none');
	//tabellen gestreift einfärben
	$("table.striped tr:has(td):even").css("background-color", "#EAF8FF");
	//Advanced googlesearchform einblenden
	$("#showform").click(function(){
		$("#formcontainer").css('display','block');
		$(this).css('display','none');
	});

	var winH = $(window).height();   
    var winW = $(window).width();  

	$('a[rel=leaving]').click(function(){
	$("#light").css('display','block');
	$("#fade").css('display','block');
	leavingObjurl=$(this).attr('title');                 
    return false;
	});

});