/*Font size manipulation*/
var COOKIE_FONT_SIZER = 'font_sizer';
var NORMAL_FONT_SIZE = 12;
var FONT_CHANGE_SIZE_STEPS = 2;

/* Tabs - selected tab */
// var news_tab_selected = 1;
var news_header_active = 2;
var TAB_SLIDE_ITEMS = 4;
var TAB_SLIDE_SELECTED = 0;
var TAB_SLIDE_TIME = 10000;

$(document).ready(function() {
	$(document).pngFix();
	$('#search_query').bind('click', function(){
		if ($(this).val() == 'Wpisz słowo lub słowa')
		{
			$(this).val('').css({'font-style': 'normal', 'color' : '#666666'});
		}
	});
	
	if (window.cookie) {
		if (!$.cookie(COOKIE_FONT_SIZER)) {
			var date = new Date();
			date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
			$.cookie(COOKIE_FONT_SIZER, '0', {
				path : '/',
				expires : date
			});
		}
		changeFontSize();
	}
	updateFontSize();
	if ($('#search_query').val() != 'Wpisz słowo lub słowa')
	{
		$('#search_query').css({'font-style': 'normal', 'color' : '#666666'});
	}
	
});
function updateOnAir(e, url, t)
{
    jQuery.ajax( {
      type : 'GET',
      url : url,
      script : true,
      dataType : 'html',
      success : function(data, textStatus) {
        jQuery('#' + e).html(data);
      }
    });
    setTimeout("updateOnAir('"+e+"', '"+url+"', "+t+")", t);
}
function weatherMoreButton(url)
{
	if ($('#content_weather').css('display') == 'none')
	{
		$('#content_weather').html('<br /><br/><center><b>Pobieram informacje o pogodzie</b></center><br /><br/>');
		$.get(url, function(data){$('#content_weather').html(data);});
		$('#content_weather').show();
		$('#weather_btn').html('zamknij');
		$('#content_main').hide();
	}
	else
	{
		$('#content_main').show();
		$('#content_weather').hide();
		$('#weather_btn').html('więcej');
	}
}

function updateFontSize() {
	var size = NORMAL_FONT_SIZE + parseInt($.cookie(COOKIE_FONT_SIZER));
	if (isNaN(size))
	{
		var date = new Date();
		date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
		$.cookie(COOKIE_FONT_SIZER, '0', {
			path : '/',
			expires : date
		});
		size = NORMAL_FONT_SIZE;
	}
	$(".textResizailable").css( {
		'font-size' : size + 'px'
	});
}
function changeFontSize() {
	var current = 0 + parseInt($.cookie(COOKIE_FONT_SIZER)) ;
	$.cookie(COOKIE_FONT_SIZER, current < FONT_CHANGE_SIZE_STEPS ? parseInt(current + 1) : parseInt(0));
	updateFontSize();
}

function toggleTab(id, status) {
	hideTab($('#' + status).val());
	showTab(id);
	$('#' + status).val(id);
	return false;
}
function hideTab(id) {
	$('#news_tab-' + id).removeClass('active');
	$('#news_tab_content-' + id).hide();
}
function showTab(id) {
	$('#news_tab-' + id).addClass('active');
	$('#news_tab_content-' + id).show();
}

/* NewsHeaderPreview - NHP */
function toggleNHP(id, img_url, li_tab) {
	
	$('#news_header').css( {
		'background-image' : "url('" + img_url + "')"
	});
	
	hideNHP(news_header_active);
	news_header_active = id;
	showNHP(news_header_active, img_url);
	TAB_SLIDE_SELECTED = $("#news_panel li").index($("#" + li_tab));

	return false;
}
function showNHP(id, img_url) {
	
	$('#news_header').css( {
		'background-image' : "url('" + img_url + "')"
	});
	
	$('#news_header_text-' + id).show();
	$('#news_header_btn-' + id).addClass('active');
}
function hideNHP(id) {
	$('#news_header_btn-' + id).removeClass('active');
	$('#news_header_text-' + id).hide();
	/*
	$('#news_header').css( {
		'background-image' : ''
	});
	*/
}
function tabSlide() {
	var setActive = TAB_SLIDE_SELECTED < TAB_SLIDE_ITEMS ? TAB_SLIDE_SELECTED + 1 : 0;
	TAB_SLIDE_SELECTED = setActive;
	$('#news_panel li:eq(' + setActive + ') a').click();
	var switchTabTimer = setTimeout('tabSlide()', TAB_SLIDE_TIME);
}
/* Media yellow boxes */
function toggleElem(f, t) {
	$('#' + f).hide();
	$('#' + t).show();
}

function mediaGroupButtonShow(e, area_id, url, info) {
	toggleElem('mbb_show_' + area_id, 'mbb_hide_' + area_id);
	$('#' + e).show();
	if (!$('#' + e).html()) {
		jQuery.ajax( {
			type : 'GET',
			url : url,
			script : true,
			dataType : 'html',
			success : function(data, textStatus) {
				jQuery('#' + e).html(data);
			},
			beforeSend : function() {

				$('#' + e).html(info);
			}
		});
	}
	return false;
}

function mediaGroupButtonHide(e, area_id) {
	toggleElem('mbb_hide_' + area_id, 'mbb_show_' + area_id);
	$('#' + e).hide();
}

function kd_cms_submit_after_change(e, f_id, current)
{
	if ($(e).val() != current)
	{
		$('#'+f_id).click();
	}
}