function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

// osadzanie filmu
function video() { 
	var id=$('#video').attr('title');
	$('#video').flash ({
		swf: '/swf/player.swf',
		flashvars: {
			mainurl: '/xml/flv.xml?id='+id
		},
		wmode: 'opaque',
		height: 310,
		width: 446
	})
}


// otwierania linku o rel openNew w nowym oknie
function newWindow () {
	$(document).find('a.openNew').click(function(){
		window.open(this.href);
		return false;
	})
}
// rotujace banery glowna
function banners() { 
	bannersNavAction();
}
function bannersNavNoAction() {
	$('#main_banner_navi').find('li').unbind('click');
	$('#main_banner_navi').find('li').click(function() {
		return false;
	});
}
function bannersNavAction() {
	$('#main_banner_navi li').unbind('click');
	$('#main_banner_navi li').click(function() {
		bannersNavNoAction();
		var selected=$('#main_banner_navi li').index($(this));
		var size=$('#main_banner_navi').find('li').size();		
		topBannersRotationRotate(selected, size);
		return false;
	});		
}
function topBannersRotation() { 
	bannersNavNoAction();
	$('#banner_container').removeClass('selected');
	var size=$('#main_banner_navi').find('li').size();
	var selected=$('#main_banner_navi li').index($('#main_banner_navi li.selected'));
	selected=selected+1;
	if(selected==size) {
		selected=1;
	} else {
		selected++;
	}
	topBannersRotationRotate((selected-1), size);	
	return false;
}
function topBannersRotationRotate(selected, size) {
		$('#main_banner_navi li').removeClass('selected');
		$('#main_banner_navi li:nth-child('+(selected+1)+')').addClass('selected');
		selected=selected+1;	
		for(var i=1;i<(size+1);i++) {
			if (i==selected) {
				$('#main_banner').find('div.banner_container:nth-child('+(i+1)+')').stop(true,true).fadeIn(1000);
			} else {
				$('#main_banner').find('div.banner_container:nth-child('+(i+1)+')').stop(true,true).fadeOut(1000);
			}
		}		
		setTimeout( function () {bannersNavAction();}, 1000);	
		clearTimeout(br);	
		br=setTimeout( function () { topBannersRotation(); }, 7000);
}
function bannersChannel() { 
	bannersNavActionChannel();
}
function bannersNavNoActionChannel() {
	$('#channel_navi').find('li').unbind('click');
	$('#channel_navi').find('li').click(function() {
		return false;
	});
}

function bannersNavActionChannel() {
	$('#channel_navi li').unbind('click');
	$('#channel_navi li').click(function() {
		bannersNavNoActionChannel();
		var selected=$('#channel_navi li').index($(this));
		var size=$('#channel_navi').find('li').size();		
		topBannersRotationRotateChannel(selected, size);
		return false;
	});	
	
}

function topBannersRotationChannel() { 
	bannersNavNoActionChannel();
	var size=$('#channel_navi').find('li').size();
	var selected=$('#channel_navi li').index($('#channel_navi li.selected'));
	//alert(selected+'/'+size);
	selected=selected+1;
	if(selected==size) {
		selected=1;
	} else {
		selected++;
	}
	topBannersRotationRotateChannel((selected-1), size);		
	return false;
}
function topBannersRotationRotateChannel(selected, size) {
		$('#channel_navi li').removeClass('selected');
		$('#channel_navi li:nth-child('+(selected+1)+')').addClass('selected');
		selected=selected+1;	
		for(var i=1;i<(size+1);i++) {
			if (i==selected) {
				$('#channel_gallery').find('div.channel_banner:nth-child('+(i+1)+')').stop(true,true).fadeIn(1000);
			} else {
				$('#channel_gallery').find('div.channel_banner:nth-child('+(i+1)+')').stop(true,true).fadeOut(1000);
			}
		}		
		setTimeout( function () {bannersNavActionChannel();}, 1000);	
		clearTimeout(br);	
		br=setTimeout( function () { topBannersRotationChannel(); }, 7000);
}
function opposite(number)	{
    		if (number < 0)	{
    			number = Math.abs(number);
    		}
    		else {
    			number = -(number);
    		}
    		return number;
}
function homepage_szerserwis() {
	$('#szer_wykres div, #szer_wykres2 div').each(function () {
			var ex=$(this).attr('class').split(' ');
			var ex2=ex[1].split('_');
			$(this).animate({width:ex2[1]+'px'}, 1500);	
	});
	
}
function tv_offer_menu() {
	$('#tv_offer_menu li').click(function() {
		$('#main_col div.channel_info').css('visibility', 'hidden');
		$('#tv_offer_menu li').removeClass('on');
		$(this).addClass('on');
		var clicked=$('#tv_offer_menu li').index($(this));
		//alert(clicked);
		$('#main_col table.terminarz_adult,#main_col table.terminarz_young,#main_col table.terminarz_kids').hide();
		if (clicked==0) {
			$('#main_col table.terminarz_adult').show();
			var selected=$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').index($('#tv_offer_submenu_adults li.on'));
		} else if (clicked==1) {
			$('#main_col table.terminarz_young').show();
			var selected=$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').index($('#tv_offer_submenu_young li.on'));
		} else {
			$('#main_col table.terminarz_kids').show();
			var selected=$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').index($('#tv_offer_submenu_kids li.on'));
		}
		clicked=clicked+3;
		$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').removeClass('show');
		$('#main_col ul:nth-child('+clicked+')').addClass('show');
		tv_offer_show_ul(selected);
		return false;
	});
	$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').click(function() {
		$('#main_col div.channel_info').css('visibility', 'hidden');
		var selected=$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').index($(this));
		//alert(selected);
		$(this).parent().find('li').removeClass('on');
		$(this).addClass('on');
		tv_offer_show_ul(selected);		
		return false;
	});
}
function tv_offer_mark_on_load() {
	var selected = getUrlVars()["p"];
	if (selected!="" && selected!=undefined) {
		$('#main_col table.terminarz_adult,#main_col table.terminarz_young,#main_col table.terminarz_kids').hide();
		$('#tv_offer_menu li').removeClass('on');
		//$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').removeClass('on');
		if (selected<8) {
			var clicked=0;
			$('#main_col table.terminarz_adult').show();
		} else if (selected<12) {
			var clicked=1;
			$('#main_col table.terminarz_young').show();
		} else {
			var clicked=2;
			$('#main_col table.terminarz_kids').show();
		}
		$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').each(function() {
				if($('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').find('li').index($(this))==selected) {
					$(this).parent().find('li').removeClass('on');
					$(this).addClass('on');
				}
			});
			$('#main_col div.tv_offer_info')
		$('#tv_offer_menu li:nth-child('+(clicked+1)+')').addClass('on');
		clicked=clicked+3;
		$('#tv_offer_submenu_adults, #tv_offer_submenu_young, #tv_offer_submenu_kids').removeClass('show');
		$('#main_col ul:nth-child('+clicked+')').addClass('show');		
		tv_offer_show_ul(selected);
	}
}
function tv_offer_show_ul(selected) {
		var ul_to_show=1;
		if (selected==0 || selected==1 || selected==2 || selected==3 || selected==4 || selected==5) {
			ul_to_show=0;
		} else if (selected==6) {
			ul_to_show=1;
		} else if (selected==7) {
			ul_to_show=2;
		} else if (selected==8) {
			ul_to_show=3;
		} else if (selected==9 ||selected==10) {
			ul_to_show=4;
		} else if (selected==11) {
			ul_to_show=5;
		} else if (selected==12) {
			ul_to_show=6;
		} else if (selected==13 ||selected==14 ||selected==15 ||selected==16) {
			ul_to_show=7;
		} else if (selected==17) {
			ul_to_show=8;
		} 
		$('#main_col div.channels_container div.channels').hide();		
		$('#main_col div.channels_container div.channels').each(function() {
				if ($('#main_col div.channels_container div.channels').index($(this))==ul_to_show){
					$(this).show();
				}
			});
		$('#main_col div.channels_container div.tv_offer_info').hide();
		$('#main_col div.channels_container div.tv_offer_info').each(function() {
			if($('#main_col div.channels_container div.tv_offer_info').index($(this))==selected) {
				$(this).show();
			}
		});
		//$('#main_col div.channels_container p.tv_offer_info:nth-child('+(selected+1)+')').show();	
}


//////////////////////////////////////////////////////////////////
// NEW TV OFFER -> START
//////////////////////////////////////////////////////////////////


function tv_offer_menu2() {
	$('#tv_offer_menu li').click(function() {
		$('#main_col div.channel_info').css('visibility', 'hidden');
		$('#tv_offer_menu li').removeClass('on');
		$(this).addClass('on');
		var clicked=$('#tv_offer_menu li').index($(this));
		//alert(clicked);
		$('#main_col table.terminarz_adult,#main_col table.terminarz_young,#main_col table.terminarz_kids').hide();
		if (clicked==0) {
			$('#main_col table.terminarz_adult').show();
			var selected=$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').index($('#tv_offer_submenu_adults2 li.on'));
		} else if (clicked==1) {
			$('#main_col table.terminarz_young').show();
			var selected=$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').index($('#tv_offer_submenu_young2 li.on'));
		} else {
			$('#main_col table.terminarz_kids').show();
			var selected=$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').index($('#tv_offer_submenu_kids2 li.on'));
		}
		clicked=clicked+3;
		$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').removeClass('show');
		$('#main_col ul:nth-child('+clicked+')').addClass('show');
		tv_offer_show_ul2(selected);
		return false;
	});
	$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').click(function() {
		$('#main_col div.channel_info').css('visibility', 'hidden');
		var selected=$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').index($(this));
		$(this).parent().find('li').removeClass('on');
		$(this).addClass('on');
		tv_offer_show_ul2(selected);		
		return false;
	});
}
function tv_offer_mark_on_load2() {
	var selected = getUrlVars()["p"]*1;
	if (selected!="" && selected!=undefined && selected!="NaN") {
		$('#main_col table.terminarz_adult,#main_col table.terminarz_young,#main_col table.terminarz_kids').hide();
		$('#tv_offer_menu li').removeClass('on');
		if (selected<10) {
			var clicked=0;
			$('#main_col table.terminarz_adult').show();
		} else if (selected<14) {
			var clicked=2;
			$('#main_col table.terminarz_kids').show();
		} else if (selected>=14) {
			var clicked=1;
			$('#main_col table.terminarz_young').show();
		} else {
			var clicked=0;
			$('#main_col table.terminarz_adult').show();			
		}
		//alert(selected);
		switch(selected)
		{
		case 0:
		  selected=7;
		  break;
		case 1:
		  selected=8;
		  break;
		case 2:
		  selected=1;
		  break;
		case 3:
		  selected=2;
		  break;		  
		case 4:
		  selected=3;
		  break;
		case 5:
		  selected=4;
		  break;
		case 6:
		  selected=5;
		  break;
		case 7:
		  selected=6;
		  break;
		case 8:
		  selected=0;
		  break;
		case 9:
		  selected=9;
		  break;
		case 10:
		  selected=16;
		  break;
		case 11:
		  selected=15;
		  break;		  
		case 12:
		  selected=14;
		  break;
		case 13:
		  selected=17;
		  break;
		case 14:
		  selected=12;
		  break;
		case 15:
		  selected=11;
		  break;
		case 16:
		  selected=10;
		  break;
		case 17:
		  selected=13;
		  break;		  
		default:
		  selected=0;
		}
		//alert(selected);
		$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').each(function() {
				if($('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').find('li').index($(this))==selected) {
					
					$(this).parent().find('li').removeClass('on');
					$(this).addClass('on');
				}
			});
			$('#main_col div.tv_offer_info')
		$('#tv_offer_menu li:nth-child('+(clicked+1)+')').addClass('on');
		clicked=clicked+3;
		$('#tv_offer_submenu_adults2, #tv_offer_submenu_young2, #tv_offer_submenu_kids2').removeClass('show');
		$('#main_col ul:nth-child('+clicked+')').addClass('show');		
		tv_offer_show_ul2(selected);
	}
}
function tv_offer_show_ul2(selected) {
		if (selected<=0) {
			ul_to_show=0;
		} else {
			ul_to_show=selected;
		}
		$('#main_col div.channels_container div.channels').hide();		
		$('#main_col div.channels_container div.channels').each(function() {
				if ($('#main_col div.channels_container div.channels').index($(this))==ul_to_show){
					$(this).show();
				}
			});
		$('#main_col div.channels_container div.tv_offer_info').hide();
		$('#main_col div.channels_container div.tv_offer_info').each(function() {
			if($('#main_col div.channels_container div.tv_offer_info').index($(this))==selected) {
				$(this).show();
			}
		});
		//$('#main_col div.channels_container p.tv_offer_info:nth-child('+(selected+1)+')').show();	
}

//////////////////////////////////////////////////////////////////
// NEW TV OFFER -> END
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// NEW TV OFFER WWW -> START
//////////////////////////////////////////////////////////////////


function offer_www () {
	$('.www_display li').click(function() {
		i=$(this).index()+2;
		$(this).parent().find('li').removeClass('on');
		$(this).addClass('on');
		$('#disp1 div.channels').removeClass('show');
		$('#disp1 div.channels:nth-child('+i+')').addClass('show');
		$('#disp1 div.channel_info').css({opacity: 1.0, visibility: "hidden"});
		return false;
	});
	$('.www_video li').click(function() {
		i=$(this).index()+2;
		$(this).parent().find('li').removeClass('on');
		$(this).addClass('on');
		$('#disp2 div.channels').removeClass('show');
		$('#disp2 div.channels:nth-child('+i+')').addClass('show');
		$('#disp1 div.channel_info').css({opacity: 1.0, visibility: "hidden"});
		return false;
	});
	
}

function over_li_channel_www() {
	$('#main_col div.channel_img a img').click(function() {
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').css('visibility', 'hidden');
		$(this).parent().parent().parent().parent().find('div.channel_img').removeAttr('style');
		var next_row=$(this).parent().parent().parent().find('input[name=next_row]').val();
		var image2=$(this).parent().parent().parent().find('input[name=image2]').val();
		var lead=$(this).parent().parent().parent().find('input[name=lead]').val();
		var description=$(this).parent().parent().parent().find('input[name=description]').val();
		var href=$(this).parent().parent().parent().find('input[name=href]').val();		
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('p strong').html(lead);
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('p.channel_description').html(description);
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('a.more').attr('href',href);	
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('img').attr('src','');
		$(this).parent().parent().find('div.channel_img').css('visibility', 'visible');		
		var x_step=83;
		var y_step=71;
		//alert($(this).parent().parent().parent().parent().html());
		var selected=$(this).parent().parent().parent().parent().find('div.channel_div').index($(this).parent().parent().parent());
		var column=selected%9;
		var row=Math.floor(selected/9);		
		if($('#tv_offer_menu').length) {
			var top=-50;
		} else {
			var top=-100;
		}
		if (column<5) {
			var left=95;
		} else {
			var left=-271;
		}
		top=top+y_step*row;
		left=left+x_step*column;
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').css('top',top);
		$(this).parent().parent().parent().parent().parent().find('div.channel_info').css('left',left);	
		if(image2!="") {
			$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('img').unbind('load');
			$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('img').load(function () { 
				if (navigator.appName == 'Microsoft Internet Explorer') {
					$(this).parent().parent().find('div.channel_info').css('visibility', 'visible');
				} else {
					$(this).parent().parent().parent().parent().find('div.channel_info').css({opacity: 1.0, visibility: "hidden"});
					$(this).parent().parent().find('div.channel_info').css({opacity: 0.0, visibility: "visible"}).stop(true,true).animate({opacity: 1.0}, 500);		
				}
				$(this).parent().parent().parent().parent().parent().find('div.channel_info').find('img').show();
			}).attr('src', image2);
		} else {
			$(this).parent().parent().parent().parent().find('div.channel_info').find('img').attr('src','');
			$(this).parent().parent().parent().parent().find('div.channel_info').find('img').hide();
			if (navigator.appName == 'Microsoft Internet Explorer') {
				$(this).parent().parent().parent().parent().find('div.channel_info').css('visibility', 'visible');
			} else {
				$(this).parent().parent().parent().parent().find('div.channel_info').css({opacity: 1.0, visibility: "hidden"});
				$(this).parent().parent().parent().parent().find('div.channel_info').css({opacity: 0.0, visibility: "visible"}).stop(true,true).animate({opacity: 1.0}, 500);		
			}			
		}
		return false;
	});
	$('#main_col div.channel_info a.channel_close').click(function() {
		$(this).parent().css('visibility', 'hidden');
		return false;
	});	
}
//////////////////////////////////////////////////////////////////
// NEW TV OFFER WWW > END
//////////////////////////////////////////////////////////////////

var img = new Image();
function zapiszcallback() {
  if (img.width == 1) {
    p_error('Dodano poprawnie.');
    return;
  } else if (img.width == 2) {
    p_error('Błąd, spróbuj ponownie.');
    return;
  } else if (img.width == 3) {
    p_error('Taki email już istnieje.');
    return;
  } 
}
function newsletter_zapisz() {
	$('#newsletter_submit').click(function() {
		var email=$('#newsletter_email').val();
		if (email.match(/[\w\d\.-]+@[\w\d]+.[\w\d\.]+/)==email && email.length>0) {
			$(img).load(function () { zapiszcallback();}).attr('src', 'http://biuletyn.zjednoczenie.com/a/247/449/add.html?email='+escape(email));
		try { pageTracker._trackPageview('/zapisdomailingu'); } catch (exp) {};
		} else {
			p_error('Podaj poprawny email');
		}
		return false;
	});
}
function newsletter() {
	$('#newsletter_email').focus(function() {
		if ($(this).val()=='wpisz swój email') {
			$(this).val('');
		}
		return false;
	});
	$('#newsletter_email').focusout(function() {
		if ($(this).val()=='') {
			$(this).val('wpisz swój email');
		}
		return false;
	});	
	newsletter_zapisz();
}
function p_error(t) {
	//alert(p);
	$('#newsletter_email').val(t);
	$('#newsletter_email').focus(function() {
		$(this).val('');
	});
}
function channel_list() {
	return false;
	//$('#channel_list').css('overflow','hidden');
	$('#channel_select, #portfolio_select').hover(function() {
		$('#channel_list').fadeToggle();
		return false;
	});
}
function topToolBarMouseOver(elemId){
	toolBarOut[elemId]=0;
	document.getElementById(elemId).style.overflow="visible";
}
function topToolBarMouseOut(elemId){
	toolBarOut[elemId]=1;
	setTimeout(function(){if(toolBarOut[elemId]==1)document.getElementById(elemId).style.overflow="hidden";},100);
}


function over_li_channel() {
	$('#main_col div.channel_img a img').click(function() {
		var selected_div_channels=$('#main_col div.channels').index($(this).parent().parent().parent().parent());
		//alert(selected_div_channels);
		$('#main_col div.channel_info').css('visibility', 'hidden');
		$('#main_col div.channel_img').removeAttr('style');
		var next_row=$(this).parent().parent().parent().find('input[name=next_row]').val();
		var image2=$(this).parent().parent().parent().find('input[name=image2]').val();
		var lead=$(this).parent().parent().parent().find('input[name=lead]').val();
		var description=$(this).parent().parent().parent().find('input[name=description]').val();
		var href=$(this).parent().parent().parent().find('input[name=href]').val();		
		$('#main_col div.channel_info').find('p strong').html(lead);
		$('#main_col div.channel_info').find('p.channel_description').html(description);
		$('#main_col div.channel_info').find('a.more').attr('href',href);	
		$('#main_col div.channel_info').find('img').attr('src','');
		$(this).parent().parent().find('div.channel_img').css('visibility', 'visible');		
		var x_step=83;
		var y_step=71;
		//alert($(this).parent().parent().parent().parent().html());
		var selected=$(this).parent().parent().parent().parent().find('div.channel_div').index($(this).parent().parent().parent());
		var column=selected%9;
		var row=Math.floor(selected/9);		
		if($('#tv_offer_menu').length) {
			var top=-50;
		} else {
			var top=-100;
		}
		if (column<5) {
			var left=95;
		} else {
			var left=-271;
		}
		top=top+y_step*row;
		left=left+x_step*column;
		$('#main_col div.channel_info').css('top',top);
		$('#main_col div.channel_info').css('left',left);	
		if(image2!="") {
			$('#main_col div.channel_info').find('img').unbind('load');
			$('#main_col div.channel_info').find('img').load(function () { 
				if (navigator.appName == 'Microsoft Internet Explorer') {
					$('#main_col div.channel_info').css('visibility', 'visible');
				} else {
					$('#main_col div.channel_info').css({opacity: 1.0, visibility: "hidden"});
					$('#main_col div.channel_info').css({opacity: 0.0, visibility: "visible"}).stop(true,true).animate({opacity: 1.0}, 500);		
				}
				$('#main_col div.channel_info').find('img').show();
			}).attr('src', image2);
		} else {
			$('#main_col div.channel_info').find('img').attr('src','');
			$('#main_col div.channel_info').find('img').hide();
			if (navigator.appName == 'Microsoft Internet Explorer') {
				$('#main_col div.channel_info').css('visibility', 'visible');
			} else {
				$('#main_col div.channel_info').css({opacity: 1.0, visibility: "hidden"});
				$('#main_col div.channel_info').css({opacity: 0.0, visibility: "visible"}).stop(true,true).animate({opacity: 1.0}, 500);		
			}			
		}
		return false;
	});
	$('#main_col div.channel_info a.channel_close').click(function() {
		$(this).parent().css('visibility', 'hidden');
		return false;
	});	
}
function szerserwisGetDate(){
	$('#szer_select').click(function() {
		return false;
	});
	//#szerserwis_main #szerserwis_list { visibility: hidden; }
    //#szerserwis_main:hover #szerserwis_list { visibility:visible; }
	$('#szerserwis_list li a').click(function(){
		var data = $(this).attr('name');
		var data_pretty = $(this).html();

		$.ajax({
			url: "/szerserwis_ajax.htm",
			type: "POST",
			data: ({"date": data}),
			dataType: "html",
			success: function(e){
				$('#szer_wykres2').html(e);
				$('#szer_wykres div, #szer_wykres2 div').each(function () {
						var ex=$(this).attr('class').split(' ');
						var ex2=ex[1].split('_');
						$(this).width(ex2[1]+'px');
				});		

			}
		});	
			
		$('#szerserwis_main #szerserwis_list').css('visibility','hidden');
		//$('#szerserwis_main').hover(function() {
		//	$('#szerserwis_list').css('visibility','visible');
			
		//	});	
			var fun=$('#szerserwis_list').hover();
				$('#szerserwis_list').css('visibility','hidden');
				setTimeout(function(){$('#szerserwis_list').css('visibility','visible');$('#szerserwis_list').removeAttr('style');},200);
				var b=$('#szerserwis_date b').html();
				$('#szerserwis_date').html('<b>'+b+'</b>'+'('+data_pretty+')');		
		return false;
	});
	

}
function dictionairy() {
	//On Click Event
	$("ul#dictionary li").click(function() {
		$("ul#dictionary li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		if($(activeTab).length) {
			$(activeTab).fadeIn(); //Fade in the active content
		} else {
			$('#no_phrases').fadeIn();	
		}		
		return false;
	});
}
function tv_station_filter() {
	//alert(1);
	//alert($('#stations_header form fieldset:nth-child(1) li').size());
	$('#stations_header form fieldset:first-child li').change(function() {
			//age_range
			var changed=$('#stations_header form fieldset:first-child li').index($(this));
			if(changed!=0) {
				var counter=0;				
				$('#stations_header form fieldset:first-child li').each(function(){
					if ($('#stations_header form fieldset:first-child li').index($(this))!=0) {
						if ($(this).find('input').is(':checked')) {
							counter++;
						} 
					}
				});		
				if (counter==3) {
					$('#stations_header form fieldset:first-child li:first-child input').attr("checked", true);					
				} else {
					$('#stations_header form fieldset:first-child li:first-child input').attr("checked", false);
					$('#stations_header form fieldset:first-child li:first-child input').removeAttr('checked');
				}		
			}
			var checked_amount=0;
			$('#stations_header form fieldset:last-child li').each(function() {
				if($(this).find('input').is(':checked')) {
					checked_amount++;
					return false;
				}
			});
			if (checked_amount==0) {
				$('#stations_header form fieldset:last-child li:first-child input').attr("checked", true);
			}	
			
			tv_station_ajax();		
	});
	$('#stations_header form fieldset:last-child li').change(function() {
			//category
			var changed=$('#stations_header form fieldset:last-child li').index($(this));
			if(changed!=0) {
				var counter=0;				
				$('#stations_header form fieldset:last-child li').each(function(){
					if ($('#stations_header form fieldset:last-child li').index($(this))!=0) {
						if ($(this).find('input').is(':checked')) {
							counter++;
						} 
					}
				});		
				if (counter==8) {
					$('#stations_header form fieldset:last-child li:first-child input').attr("checked", true);
				} else {
					$('#stations_header form fieldset:last-child li:first-child input').attr("checked", false);
					$('#stations_header form fieldset:last-child li:first-child input').removeAttr('checked');
				}		
			}	
			var checked_amount=0;
			$('#stations_header form fieldset:first-child li').each(function() {
				if($(this).find('input').is(':checked')) {
					checked_amount++;
					return false;
				}
			});
			if (checked_amount==0) {
				$('#stations_header form fieldset:first-child li:first-child input').attr("checked", true);
			}			
			tv_station_ajax();		
	});	
	
	
}
function tv_station_ajax() {
	
	var age_range="";
	var category="";
	$('#stations_header form fieldset:first-child li input:checked').each(function() {
		if($(this).val()=="all") {
			age_range=$(this).val();
			return false
		} else {
			age_range=age_range+'|'+$(this).val();
		}
	});
	$('#stations_header form fieldset:last-child li input:checked').each(function() {
		if($(this).val()=="all") {
			category=$(this).val();
			return false
		} else {
			category=category+'|'+$(this).val();
		}
	});	
	var query='age_range='+age_range+'&category='+category;
	var randomnumber=Math.floor(Math.random()*10001);
	document.location='#'+query;
	$.ajax({
		type: "GET",
		url: "/portfolio/tv_stations_ajax.html",
		dataType: "html",
		data: query+"&rrr="+randomnumber,
		error: function(){
				alert('Spróbuj ponownie poźniej');
		},
		beforeSend: function() {
				//please wait	
				$('#main_col').find('div.channels').hide();	
				$('#preloader').show();		
		},
		success: function(d){
				//alert(d);		
				$('#preloader').hide();				
				$('#main_col').find('div.channels').html(d);
				$('#main_col').find('div.channels').show();
				over_li_channel(); 
		}
	});
	
}


//////////////////////////////////////////////////////////////////
// NEW PORTFOLIO OFFER -> START
//////////////////////////////////////////////////////////////////

function tv_station_filter_www() {
	//alert(1);
	//alert($('#stations_header form fieldset:nth-child(1) li').size());
	$('#stations_header form fieldset:first-child li').change(function() {
			//form_of_advertising
			var changed=$('#stations_header form fieldset:first-child li').index($(this));
			if(changed!=0) {
				var counter=0;				
				$('#stations_header form fieldset:first-child li').each(function(){
					if ($('#stations_header form fieldset:first-child li').index($(this))!=0) {
						if ($(this).find('input').is(':checked')) {
							counter++;
						} 
					}
				});		
				if (counter==6) {
					$('#stations_header form fieldset:first-child li:first-child input').attr("checked", true);					
				} else {
					$('#stations_header form fieldset:first-child li:first-child input').attr("checked", false);
					$('#stations_header form fieldset:first-child li:first-child input').removeAttr('checked');
				}		
			}
			var checked_amount=0;
			$('#stations_header form fieldset:last-child li').each(function() {
				if($(this).find('input').is(':checked')) {
					checked_amount++;
					return false;
				}
			});
			if (checked_amount==0) {
				$('#stations_header form fieldset:last-child li:first-child input').attr("checked", true);
			}	
			
			tv_station_ajax_www();		
	});
	$('#stations_header form fieldset:nth-child(2) li').change(function() {
			//age_range
			var changed=$('#stations_header form fieldset:nth-child(2) li').index($(this));
			if(changed!=0) {
				var counter=0;				
				$('#stations_header form fieldset:nth-child(2) li').each(function(){
					if ($('#stations_header form fieldset:nth-child(2) li').index($(this))!=0) {
						if ($(this).find('input').is(':checked')) {
							counter++;
						} 
					}
				});		
				if (counter==4) {
					$('#stations_header form fieldset:nth-child(2) li:first-child input').attr("checked", true);
				} else {
					$('#stations_header form fieldset:nth-child(2) li:first-child input').attr("checked", false);
					$('#stations_header form fieldset:nth-child(2) li:first-child input').removeAttr('checked');
				}		
			}	
			var checked_amount=0;
			$('#stations_header form fieldset:first-child li').each(function() {
				if($(this).find('input').is(':checked')) {
					checked_amount++;
					return false;
				}
			});
			if (checked_amount==0) {
				$('#stations_header form fieldset:first-child li:first-child input').attr("checked", true);
			}			
			tv_station_ajax_www();		
	});	
	
	$('#stations_header form fieldset:last-child li').change(function() {
			//category
			var changed=$('#stations_header form fieldset:last-child li').index($(this));
			if(changed!=0) {
				var counter=0;				
				$('#stations_header form fieldset:last-child li').each(function(){
					if ($('#stations_header form fieldset:last-child li').index($(this))!=0) {
						if ($(this).find('input').is(':checked')) {
							counter++;
						} 
					}
				});		
				if (counter==10) {
					$('#stations_header form fieldset:last-child li:first-child input').attr("checked", true);
				} else {
					$('#stations_header form fieldset:last-child li:first-child input').attr("checked", false);
					$('#stations_header form fieldset:last-child li:first-child input').removeAttr('checked');
				}		
			}	
			var checked_amount=0;
			$('#stations_header form fieldset:first-child li').each(function() {
				if($(this).find('input').is(':checked')) {
					checked_amount++;
					return false;
				}
			});
			if (checked_amount==0) {
				$('#stations_header form fieldset:first-child li:first-child input').attr("checked", true);
			}			
			tv_station_ajax_www();		
	});	
	
}
function tv_station_ajax_www() {
	
	var form_of_advertising="";
	var age_range="";
	var category="";
	$('#stations_header form fieldset:first-child li input:checked').each(function() {
		if($(this).val()=="all") {
			form_of_advertising=$(this).val();
			return false
		} else {
			form_of_advertising=form_of_advertising+'|'+$(this).val();
		}
	});
	$('#stations_header form fieldset:nth-child(2) li input:checked').each(function() {
		if($(this).val()=="all") {
			age_range=$(this).val();
			return false
		} else {
			age_range=age_range+'|'+$(this).val();
		}
	});
	$('#stations_header form fieldset:last-child li input:checked').each(function() {
		if($(this).val()=="all") {
			category=$(this).val();
			return false
		} else {
			category=category+'|'+$(this).val();
		}
	});	
	var query='age_range='+age_range+'&category='+category+'&form_of_advertising='+form_of_advertising;
	var randomnumber=Math.floor(Math.random()*10001);
	document.location='#'+query;
	$.ajax({
		type: "GET",
		url: "/portfolio/websites_ajax.html",
		dataType: "html",
		data: query+"&rrr="+randomnumber,
		error: function(){
				alert('Spróbuj ponownie poźniej');
		},
		beforeSend: function() {
				//please wait	
				$('#main_col').find('div.channels').hide();	
				$('#preloader').show();		
		},
		success: function(d){
				//alert(d);		
				$('#preloader').hide();				
				$('#main_col').find('div.channels').html(d);
				$('#main_col').find('div.channels').show();
				over_li_channel(); 
		}
	});
	
}

//////////////////////////////////////////////////////////////////
// NEW PORTFOLIO OFFER -> END
//////////////////////////////////////////////////////////////////


function search_form() {
	$('#search_submit').click(function() {
		//$('#search_form').css("backgroundPosition","+25px 0px");
		//for(var i=192;i>24;i--) {
		//	$('#search_form').css("backgroundPosition","+"+i+"px 0px");
		//}
		slide_search();
		//$('#search_form').animate({backgroundPosition:'(+25px 0px)'}, 1000,"linear");
		//$('#search_input').animate({width:'153px'}, 1000);
		$('#search_input').css('padding-left','15px');
		$('#search_submit').click(function() {	
			if ($('#search_input').val()!="") {		
				$('#search_form').submit();
			}
		});
	});
}
function slide_search() {
		var bg_pos=$('#search_form').css("backgroundPosition");
		//var bg_pos=document.getElementById('search_form').style.backgroundPosition; 
		//alert(bg_pos);
		 if(typeof(bg_pos) === 'undefined') bg_pos= $('#search_form').css('background-position-x') + ' ' + $('#search_form').css('background-position-y');
		bg_pos=bg_pos.split(' ');
		
		bg_pos=bg_pos[0].replace('px','');
		var step=6;
		if((bg_pos-step)<25) {
			step=bg_pos-25;
		}
		if (bg_pos>25) {
			$('#search_form').css("backgroundPosition","+"+(bg_pos-step)+"px 0px");
			slide_search_=setTimeout( function () { slide_search(); }, 10);
		} else {
			$('#search_input').css('width','153px');
		}
		//clearTimeout(slide_search_);	
}
function newsletter_form() {
	$('#newsletter_email').focus(function() {
		if ($(this).val()=='podaj e-mail') {
			$(this).val('');
		}
		return false;
	});
	$('#newsletter_email').focusout(function() {
		if ($(this).val()=='') {
			$(this).val('podaj e-mail');
		}
		return false;
	});	
	$('#newsletter_submit').click(function() {
		//var txt=$('#newsletter_email').val();
		//$('#newsletter_email').val('');
		//$('#newsletter_email').css('padding-left','10px');
		//$('#newsletter_email').css('padding-right','64px');
		//$('#newsletter_email').stop(true,true).animate({width:'138px'}, 1000);
		//setTimeout(function(){$('#newsletter_email').val(txt);},1000);
		//$('#newsletter_submit').unbind('click');
		//$('#newsletter_submit').click(function() {			
			$('#newsletter_form').submit();
		//});
	});
}
function initZoom() {
	//main_col
	if (location.href.indexOf('/oferta/oferta-specjalna.html')!=-1 || location.href.indexOf('/article/')!=-1) {
		$('#main_col img').each(function() {
			//alert($(this).parent().get(0).tagName);
			if ($(this).parent().get(0).tagName!='A') {
			var href=$(this).attr('src');
			if(href.indexOf('/img/')!=-1) {
				var href_split=href.split('/');			
				href=href.replace(href_split[(href_split.length-2)],'/_zoom/');
				$(this).wrap('<a href="'+href+'" class="nivoZoom">');
				$(this).parent().imageZoom();
			}
			}
		})
	}
	//$('body').imageZoom();
}
function recommendRotation() { 
	var size=$('#polecamy_box a').size();
	var selected=$('#polecamy_box a').index($('#polecamy_box a:visible'));
	selected=selected+1;
	
	if(selected==size) {
		selected=1;
	} else {
		selected++;
	}
	
	$('#polecamy_box a').stop(true,true).fadeOut(500);
	setTimeout( function () {$('#polecamy_box a:nth-child('+selected+')').stop(true,true).fadeIn(500);}, 600);
	clearTimeout(br2);
	br2=setTimeout( function () { recommendRotation(); }, 7000);		
	return false;
}
function contact_persons() {
	if($('div.contact_teaser h2').length == 1) {
		$('div.contact_teaser div.person').slideDown();
		$('div.contact_teaser h2').removeClass('person_show');
		$('div.contact_teaser h2').addClass('person_hide');
	} 
	$('div.contact_teaser h2').click(function() {
		if($(this).hasClass('person_hide')) {
			$(this).removeClass('person_hide');
			$(this).addClass('person_show');
			$(this).parent().find('div.person').slideUp();
		} else {
			$(this).removeClass('person_show');
			$(this).addClass('person_hide');
			$(this).parent().find('div.person').slideDown();
		}
		
	});
	
}
function newsletter_submit() {
if(getUrlVars["action"]=="homepage") { 
		document.nsl_form.submit();
	}
}
$(document).ready( function() {
	newWindow();
	if($('#video').length) {video();}	
	if($('#main_banner').length) {banners();}	
	if($('#main_banner').length) {br=setTimeout( function () { topBannersRotation(); }, 7000);}	
	if($('#szer_wykres, #szer_wykres2').length) {homepage_szerserwis();szerserwisGetDate();}
	//TU ZMIANY DO NOWYCH PAKIETOW
	if($('#tv_offer_menu,#stations_header').length && $('#tv_offer_submenu_adults2').length) {
		tv_offer_menu2();over_li_channel();tv_offer_mark_on_load2();
	} else {
		if($('.www_video,.www_display').length) {offer_www (); over_li_channel_www();}
		if($('#tv_offer_menu,#stations_header').length) {tv_offer_menu();over_li_channel();tv_offer_mark_on_load();}
	}
	//if($('#newsletter_form').length) {newsletter();}
	if($('#channel_list,#portfolio_select').length) {channel_list();}	
			
	if($('#websitesForm').length) {tv_station_filter_www();} else {if($('#portfolio_select').length) {tv_station_filter();}}	
	if($('#channel_gallery div.channel_banner').length>1) {bannersChannel();}	
	if($('#channel_gallery div.channel_banner').length>1) {br=setTimeout( function () { topBannersRotationChannel(); }, 7000);}		
	if($('#main_col ul#dictionary').length) {dictionairy();}	
	if($('#search_form').length) {search_form();}
	if($('#newsletter_form').length) {newsletter_form();}
	if($('#polecamy_box a').length>1) {br2=setTimeout( function () { recommendRotation(); }, 7000);}	
	if($('#map_canvas').length) {map_load();}
	initZoom();	
	if($('div.contact_teaser').length) {contact_persons();}
	//filmy zoom
	/*Shadowbox.init({
		handleOversize:     "drag",
		displayNav:         true,
		handleUnsupported:  "remove",
		autoplayMovies:     false,
		gallery: "mustang",
		continuous: true,
		counterType: "skip" 
	});*/
//	if($('#newsletter_box').length) {newsletter_submit();}
	$.each($('#form_contest input.file'), function() {
		$(this).change(function() {
			$(this).parent().parent().find('input[type=text]').attr('value', $(this).val());
		});
	});

		
});


