function switchFont(elem, diff, className, recursive) {
	$(elem).children().each(function (i) {
		if ( !$(this).hasClass(className) ) {
			$(this).removeClass('font-s');
			$(this).removeClass('font-m');
			$(this).removeClass('font-l');
			$(this).addClass(className);
			var size = parseFloat($(this).css('fontSize'), 10)+diff;
			$(this).css('fontSize', size+'px');			
		}
    	//if(recursive != false && $(this).children().length > 0)
    	//	switchFont(this, diff, className, recursive);
    });   	
}

function switchFontRecursive(elem, diff, className) {
	$(elem).children().each(function (i) {
		if ( !$(this).hasClass(className) ) {
			$(this).removeClass('font-s');
			$(this).removeClass('font-m');
			$(this).removeClass('font-l');
			$(this).addClass(className);
			var size = parseFloat($(this).css('fontSize'), 10)+diff;
			$(this).css('fontSize', size+'px');
		}
    	if(recursive != false && $(this).children().length > 0)
    		switchFontRecursive(this, diff, className);
    });   	
}
$(window).load(function(){
/*	$('ul.sf-menu').supersubs({ 
        minWidth:    12,
        maxWidth:    50, 
        extraWidth:  1   
    });
*/	
	$('ul.sf-menu').superfish({ 
    	dropShadows:false,
    	animation:	{height:'show'},
    	delay:		500,
        speed:		'fast',
        onShow:		function(){$(this).parent().css('border-bottom','2px solid rgb(174,61,78)');},
        onHide:		function(){$(this).parent().css('border-bottom','2px solid rgb(77,77,77)');}
    });
	
});

function limitChars(textid, limit, infodiv){
	var text = $('#'+textid).val();
	var textlength = text.length;
	if(textlength > limit){
		$('#' + infodiv).html('Nie można wpisać więcej znaków niż '+limit);
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else{
		$('#' + infodiv).html('Pozostało '+ (limit - textlength) +' znaków do wpisania.');
		return true;
	}
}



$(document).ready(function(){
    $(document).ready(function(){ 
        $(document).pngFix(); 
    });     
	
	//alert($(document).height()+' '+$(window).height()+' '+$('body').height());
	
	if($("#main").height() < 200)
		$("#main").css('height', 300);
	
	if(hasMsg) {
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;		
		tb_show('Komunikaty','#TB_inline?height=100&width=600&inlineId=msgbox',false); 
	}
	
	$('#fontsize-1').click(function(){
        if(fontLevel == 2) {//srednie->male (-1px)
        	switchFont('#cms-content', -1, 'font-s');
			switchFont('.news-row .text', -1, 'font-s');  
    		//ahm
			switchFont('#main-info', -1, 'font-s');  
			switchFont('#main-interview-content', -1, 'font-s');  
			switchFont('#main-bottom-navbar', -1, 'font-s');  
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)-1;
			$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', -1, 'font-s');  
			switchFont('#bio_facts', -1, 'font-s');  
			switchFont('#bio_content', -1, 'font-s'); 
			switchFont('#comments', -1, 'font-s');
			switchFont('#table-list', -1, 'font-s', false);
			switchFont('#view-news', -1, 'font-s');
        }
        else if(fontLevel == 3) {//duze->male (-4px)
        	switchFont('#cms-content', -4, 'font-s');
			switchFont('.news-row .text', -4, 'font-s');
    		//ahm
			switchFont('#main-info', -4, 'font-s');  
			switchFont('#main-interview-content', -4, 'font-s');  
			switchFont('#main-bottom-navbar', -4, 'font-s'); 
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)-4;
        	$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', -4, 'font-s');  
			switchFont('#bio_facts', -4, 'font-s');  
			switchFont('#bio_content', -4, 'font-s'); 
			switchFont('#comments', -4, 'font-s');
			switchFont('#table-list', -4, 'font-s', false);
			switchFont('#view-news', -4, 'font-s');
        }
        fontLevel = 1;		

        $('#fontsize-1').css('color','rgb(174,61,78)');
		$('#fontsize-2').css('color','rgb(128,130,133)');
		$('#fontsize-3').css('color','rgb(128,130,133)');		
		$('.right-left .news-row').css('height','180px');
	});
	$('#fontsize-2').click(function(){
        if(fontLevel == 3) {//duze->srednie (-3px)
        	switchFont('#cms-content', -3, 'font-m');
			switchFont('.news-row .text', -3, 'font-m');
    		//ahm
			switchFont('#main-info', -3, 'font-m');  
			switchFont('#main-interview-content', -3, 'font-m');  
			switchFont('#main-bottom-navbar', -3, 'font-m');  
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)-3;
			$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', -3, 'font-m');  
			switchFont('#bio_facts', -3, 'font-m');  
			switchFont('#bio_content', -3, 'font-m'); 
			switchFont('#comments', -3, 'font-m');
			switchFont('#table-list', -3, 'font-m', false);
			switchFont('#view-news', -3, 'font-m');
        }
        else if(fontLevel == 1) {//male->srednie (+1px)
        	switchFont('#cms-content', 1, 'font-m');
			switchFont('.news-row .text', 1, 'font-m');
    		//ahm
			switchFont('#main-info', 1, 'font-m');  
			switchFont('#main-interview-content', 1, 'font-m');  
			switchFont('#main-bottom-navbar', 1, 'font-m');  
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)+1;
			$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', 1, 'font-m');  
			switchFont('#bio_facts', 1, 'font-m');  
			switchFont('#bio_content', 1, 'font-m'); 
			switchFont('#comments', 1, 'font-m');
			switchFont('#table-list', 1, 'font-m', false);
			switchFont('#view-news', 1, 'font-m');
        }
        fontLevel = 2;
		
        $('#fontsize-1').css('color','rgb(128,130,133)');
		$('#fontsize-2').css('color','rgb(174,61,78)');
		$('#fontsize-3').css('color','rgb(128,130,133)');		$
		$('.right-left .news-row').css('height','180px');
	});
	
	$('#fontsize-3').click(function(){
        if(fontLevel == 2) {//srednie->duze (+3px)
        	switchFont('#cms-content', 3, 'font-l');
			switchFont('.news-row .text', 3, 'font-l');
    		//ahm
			switchFont('#main-info', 3, 'font-l');  
			switchFont('#main-interview-content', 3, 'font-l');  
			switchFont('#main-bottom-navbar', 3, 'font-l');  
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)+3;
			$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', 3, 'font-l');  
			switchFont('#bio_facts', 3, 'font-l');  
			switchFont('#bio_content', 3, 'font-l'); 
			switchFont('#comments', 3, 'font-l');
			switchFont('#table-list', 3, 'font-l', false);
			switchFont('#view-news', 3, 'font-l');
        }
        else if(fontLevel == 1) {//male->duze (+4px)
        	switchFont('#cms-content', 4, 'font-l');
    		switchFont('.news-row .text', 4, 'font-l');
    		//ahm
			switchFont('#main-info', 4, 'font-l');  
			switchFont('#main-interview-content', 4, 'font-l');  
			switchFont('#main-bottom-navbar', 4, 'font-l');  
        	size = parseFloat($('#main-interview-content').css('fontSize'), 10)+4;
			$('#main-interview-content').css('fontSize', size+'px');
			//wikibio
			switchFont('#wikibio_name', 4, 'font-l');  
			switchFont('#bio_facts', 4, 'font-l');  
			switchFont('#bio_content', 4, 'font-l'); 
			switchFont('#comments', 4, 'font-l');
			switchFont('#table-list', 4, 'font-l', false);
			switchFont('#view-news', 4, 'font-l');
        }
        fontLevel = 3;
	
        $('#fontsize-1').css('color','rgb(128,130,133)');
		$('#fontsize-2').css('color','rgb(128,130,133)');
		$('#fontsize-3').css('color','rgb(174,61,78)');			
		$('.right-left .news-row').css('height','220px');
	});
	
	$('.search-result-row').mouseenter(function(){
		$('#'+this.id+'-title').css('color', '#000000');
	});
	
	$('.search-result-row').mouseleave(function(){
		$('#'+this.id+'-title').css('color', '#5F564A');
	});
	
	
	$(".help-tooltip").click(function(){
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;		
		tb_show('Pomoc','#TB_inline?height=300&width=600&inlineId='+this.id+'-content',false); 		
		
	})
	
	$("#show-calendar").click(function () 
	{	
		if(($("#event-calendar").css("display")) == "none")
		{	
			newsCalendar.build();
		}	
		$("#event-calendar").slideToggle("slow", function()
		{    	  
			
			if(($("#event-calendar").css("display")) == "none")
    	  {
    		  $(".main-menu-cell").css("background-image","url(/img/menu-sub-bg.jpg)");
    	  }
    	  else
    	  {
    		  $(".main-menu-cell").css("background-image","url(/img/menu-sub-bg-open.jpg)");    		 
    	  }
		});
    });
	
	$(".yt-play").click(function(){
		var hash = $(this).attr("rel");
		var html = '<object width="377" height="307"><param name="movie" value="http://www.youtube.com/v/'+ hash +'&hl=pl&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ hash +'&hl=pl&border=0&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="377" height="307"></embed></object>';
		$("#yt-content").html(html);
		$(".yt-popup").show();
	});
	$("#close-yt").click(function(){
		$(".yt-popup").hide();
		$("#yt-content").html(' ');		
	})
	
	$("#form_subscribe_newsletter #email").focus( function() { 
		if($("#form_subscribe_newsletter #email").val() == "adres@")
			$("#form_subscribe_newsletter #email").val("");
		 
		});
});