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('styles',size,{expires:7,path:'/'});
}

function disableAll() {
    $('link[@rel*=STYLE]').each(function() {
        this.disabled = true;
    });
}


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() {
	/**
	*  ### Accordion 
	* @author Simon Wölfl cekom GmbH
	*/
	$('#accordion .head').mouseover( function(){
		if(!$(this).hasClass('open')){
			$(this).addClass('hover');
		}
	});
	$('#accordion .head').mouseout( function(){
		if(!$(this).hasClass('open')){
			$(this).removeClass('hover');
		}
	});
	$('#accordion .head').click(function() {
		var open = $(this).hasClass('open');
		if($('#displayPageHead').size() <= 0){
			$('.pageHead').before('<a id="displayPageHead" href="javascript:return;" onClick="$(\'.content_right .image_item\').fadeIn();$(\'#displayPageHead\').remove();$(\'.pageHead\').slideDown();$(\'.open\').removeClass(\'open\').next().slideUp();">Einleitung</a>');
		}
		$('.pageHead').slideUp('fast');
		$('#accordion .head').each(function(){
			$(this).next().slideUp();
			if($(this).hasClass('open')){
				$(this).removeClass('open');
			}
			if($(this).hasClass('hover')){
				$(this).removeClass('hover');
			}
		});
		if(!open){
			$(this).next().slideDown('fast');
			if($(this).next().children('.paragraph-image-box-block').size() > 0)
			{
				$('.content_right .image_item').fadeOut();
				$('.paragraph-image-box-block').hide();
				$('.paragraph-image-box-block').fadeIn();
			}
			else
			{
				$('.content_right .image_item').fadeIn();
			}
			$(this).addClass('open');
		}
		else
		{
			$(this).removeClass('open');
			$('.content_right .image_item').fadeIn();
			$('.pageHead').slideDown();
			$('#displayPageHead').remove();
		}
		return false;
	});

	$('#accordion .container').css("display", "none");
	$(".right_grid_item").css('zoom', '1');
	
	
    if(document.all) {
        try {document.execCommand("BackgroundImageCache",false,true);} catch(e){}
    }
    $('#AddBookmark').click(function(){setBookmark(); return false;});
    $('#TextVersion').click(function(){disableAll(); return false;});

    if($.cookie('styles')) {
        currSize = parseInt($.cookie('styles'));
        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();
/*     $('a[@rel*=mail]').click(function() {
                 var url = this.href;
                 if (navigator.appName == "Netscape"){
                     url = url.replace(/index\.php/,'index_ns.php');
                 }
                 window.open(url,'Mail','width=468,height=565,scrollbars=yes');
                 return false;
     });*/
     $('.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');
	});
	
	$(".login_row INPUT").labelify();
});
