var NEEDACCEPTATION = true;
var hidemuz = true;

function sluchajOnline()
{
	window.open('http://weekendfm.pl/_radio', 'radioonline', 'width=350,height=131,left=50,top=50,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0').focus();
}

$(function() {

	$("#lista_p .glosuj a.active").click(function(){
		$("#lista_p .glosuj a.active").attr("class","inactive");
		$("#lista_p .glosuj a").unbind('click');
		$.ajax({
			url:"_i/glosuj.php?id="+$(this).attr("href").substr(1),
			success:function(data){
				alert("Dziękujemy! Twój głos został zapisany.");	
			}
		});
		return false;
	});

	$("a.zoom, a.thickbox.galobraz").fancybox();

	$(".muz_menu a").mouseover(function(e){
		var m_class;
		switch ($(this).attr('class'))
		{
			case 'm1':
				m_class = 'muz_lista';
				break;
			case 'm2': 
				m_class = 'muz_pp';
				break;	
			case 'm3': 
				m_class = 'muz_pt';
				break;	
		}
		
		hidemuz = false;
		$('.muz_float').show();
		$('.muz_float div').each(function (e)
		{
			if ($(this).hasClass(m_class)) 
				$(this).stop().fadeTo(300,1).css('z-index','31');
				
			else
				$(this).stop().fadeTo(300,0).css('z-index','30');
		});
	}).mouseout(function(e){
		//hidemuz = true;
		//setTimeout(function(e){
			//if (hidemuz)
			//{
				//$('.muz_float div').stop().fadeTo(300,0).css('z-index','30');
				//setTimeout(function(e){
				$('.muz_float').hide();
				//},300);
			//}
		//},100);
	});
	
	$('.muz_float div, .muz_float div *').mouseover(function(e){
		hidemuz = false;
	}).mouseout(function(e){
		hidemuz = true;
		setTimeout(function(e){
			if (hidemuz)
			{
				$('.muz_float div').stop().fadeTo(300,0).css('z-index','30');
				setTimeout(function(e){$('.muz_float').hide()},300);
			}
		},100);
	});
});

function tabsy(klasa)
{
	klasa = typeof(klasa) != 'undefined' ? klasa : '.week_life_h a';
	
	$(klasa).click(function(e){
		$(klasa).removeClass('active');
		$(this).addClass('active');
		
		var boxno = 0;
		
		if ($(this).hasClass ('wl01')) {$("#week_life_filtr").val('none'); $("#week_life_current").val(0);}
		if ($(this).hasClass ('wl03')) {$("#week_life_filtr").val('moto'); $("#week_life_current").val(0);}
		if ($(this).hasClass ('wl04')) {$("#week_life_filtr").val('las'); $("#week_life_current").val(0);}
		if ($(this).hasClass ('wl05')) {$("#week_life_filtr").val('his'); $("#week_life_current").val(0);}
		
		if ($(this).hasClass ('mu01')) {$("#week_muz_filtr").val('none'); $("#week_muz_current").val(0); boxno = 1;}
		if ($(this).hasClass ('mu02')) {$("#week_muz_filtr").val('house'); $("#week_muz_current").val(0); boxno = 1;}
		if ($(this).hasClass ('mu03')) {$("#week_muz_filtr").val('gwt'); $("#week_muz_current").val(0); boxno = 1;}

		if (boxno == 0)
		{
			doNextPrev(false,'week_life');
		}
		
		return false;
	});
}

function regnews_thumbs(ramka)
{
	ramka = typeof(ramka) != 'undefined' ? ramka : 'region_news';

	$("#"+ramka+" .k_tytul a").mouseover
	(function(e){
	
		var gotoh = ($(this).offset().top - $("."+ramka+"_in").offset().top);
		var gotomax = $("."+ramka+"_in").height()-62-5;
		
		if (gotoh > gotomax) gotoh = gotomax;
	
		if ($(this).attr('name') == '')
			$('#'+ramka+' .'+$(this).attr('rel')+' img').attr('src','_css2/wfm.png');
		else
			$('#'+ramka+' .'+$(this).attr('rel')+' img').attr('src',$(this).attr('name'));
			
		$('#'+ramka+' .'+$(this).attr('rel')).stop().animate({'top':gotoh+'px'},250).attr('href',$(this).attr('href'));
		
		
		
		
	})
}

var wyk = '';
function wykorzystane()
{		
	$(".top_news_id").each(function(e){
		wyk = wyk+','+$(this).val();
	});		
}

function doNextPrev(thiss, hidField)
{
	var go = false;
	var goDest = false;
			
	//alert($("#ff").val());
		
		if (thiss != false)
		{
			if (thiss.hasClass('new') && parseInt($("#"+hidField+"_current").val()) > 0) 
			{
				go = true;
				goDest = parseInt($("#"+hidField+"_current").val()) - 1;
			}
			
			if (thiss.hasClass('old'))
			{
				go = true;
				goDest = parseInt($("#"+hidField+"_current").val()) + 1;
			}
		}
		else
		{
			go = true;
			goDest = 0;
		}
			
			if (go)
			{
				var wykfix = '';
				if (hidField == 'region_news') wykfix = "&wyk="+wyk;
				
				var openURL = hidField;
				var boxFix = '';
				
				if (openURL == 'week_sport') {openURL = 'week_life'; boxFix = '&sport';}
				if (openURL == 'week_muz') {openURL = 'week_life'; boxFix = '&muz';}
				
				
				var filtrFix = '';
				if ($('#'+hidField+"_filtr") != 'undefined') 
				{
					
					var ff = $('#'+hidField+"_filtr").val();
					if (ff != 'none')
					{
						filtrFix = '&f='+ff;
					}
				}
				
				
				$("."+hidField+"_in .kalend").fadeTo(100,0.5);
				
				$.ajax({
					url: '_i/sg_'+openURL+'.php?sub_s='+goDest+wykfix+boxFix+filtrFix,
					success: function(d){
						if (d != '')
						{
							$("#"+hidField+"_current").val(goDest);
							$("."+hidField+"_in").html(d);
							regnews_thumbs(hidField);
						}
						else
						{
							$("."+hidField+"_in .kalend").fadeTo(100,1);
						}
					}
				});
			}
}

function old_new(hidField)
{
	$("."+hidField+"_out .stopka a").click(
		function (e)
		{
			doNextPrev($(this),hidField);
			return false;
		}
	);
}
