var pf,pfl,pfnr;

function sliderInterval()
{
    pfnr = slider(pf,pfl,pfnr);
}

function slider(pf,pfl,pfnr)
{
    if($(pf).eq(pfnr+1).length)
    {
	$(pf).eq(pfnr).fadeOut(800);

	pfnr += 1;

	$(pf).eq(pfnr).fadeIn(800);

    } else
    {
	$(pf).eq(pfnr).fadeOut(800);

	pfnr = 0;

	$(pf).eq(pfnr).fadeIn(800);
    }
    
    return pfnr;
}
/*TUTAJ FUNKCJA DO OBSŁUGI POPUPA ŚWIĄTECZNEGO*/
function hidePopup()
{
	if($('#trans_over').css('display') != 'none')
	{
		$('#over_cover').fadeOut(300)
		setTimeout(function() {$('#trans_over').fadeOut(300);}, 280);
	}

}
/*KONIEC OBSŁUGI POPUPA ŚWIĄTECZNEGO*/
$(document).ready(function(){
//=================================================================

/*TUTAJ FUNKCJE DO OBSŁUGI POPUPA ŚWIĄTECZNEGO*/
	/*
	if($('#trans_cover').length > 0)
	{
		$(document).keypress(function(e) {
			if(e.keyCode == 27)
			{
				e.preventDefault();
				hidePopup()
			}
		});
		$('#trans_over').fadeIn(700)
		setTimeout(function() { $('#over_cover').fadeIn(700); }, 350);

		setTimeout(hidePopup, 17000);
		$('#trans_over').click(hidePopup)
		$('#trans_cover').click(hidePopup)
		$('#over_cover').click(hidePopup)
		$('#popup_content').click(hidePopup)
		$('#popup_button').click(hidePopup)
	}
	*/
/*KONIEC OBSŁUGI POPUPA ŚWIĄTECZNEGO*/
function mycarousel_initCallback(carousel){
	carousel.buttonNext.bind('click', function(){
			carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function(){
			carousel.startAuto(0);
	});


	carousel.clip.hover(function(){
			carousel.stopAuto();
	}, function(){
			carousel.startAuto();
	});
};

$('.g-box ul').jcarousel({
	scroll: 1,
	wrap: 'last',

	initCallback: mycarousel_initCallback
});




i = 1;
$('#menu>li>a').each(function(){
	$(this).attr('id', 'menu'+i);
	i++;
});





// strona z fakturami
if($('.invoice').length){
	$('<div id="tooltip"></div>').appendTo($(document.body)).hide();

	$('map *').hover(
		function(e){
			$('#tooltip').html($(this).attr('txt'));
			$('#tooltip').css({'top': e.pageY+20, 'left': e.pageX+20});
			$('#tooltip').show();
		},
		function(e)
		{
			$('#tooltip').html('').hide();
		}
	);

	$('map *').click(
	function(e){
			$('#tooltip').html($(this).attr('txt'));
			$('#tooltip').css({'top': e.pageY+20, 'left': e.pageX+20});
			$('#tooltip').show();

			return false;
		}
	);
}

$('.slid-header').toggle(
	function()
	{
		$(this).next('.slid-text').show();
	},
	function()
	{
		$(this).next('.slid-text').hide();
	}
);

$('a[rel=external]').click(function()
{
    window.open(this.href);

    return false;
});

if($('.cw13 .w2').length)
{
	if(!$('.cw13 .w1').length)
	{
		$('.cw13 .w2').css('margin', '0px auto');
		$('.cw13 .w2').css('float', 'none');
	}
}
if($('.cw13 .w1').length)
{
	if(!$('.cw13 .w2').length)
	{
		$('.cw13 .w1').css('margin', '0px auto');
		$('.cw13 .w1').css('float', 'none');
	}
}

$("a[class='colorbox']").colorbox({
			current: "{current} ({total})",
			maxWidth: '100%',
			maxHeight: '700px'
		});


/*Cufon.replace('#menu > li > a > span, #submenu dt, #submenu li, '+
				'h1, #font-size span, '+
				'.sw1 .h h3, .sw2 .h h3, .sw3 .h h3, '+
				'.cw1 .h h2, .cw2 .h h2, .cw3 .h h2, .cw4 .h h2, .cw5 .h h2, .cw6 .h h2, .cw7 .h h2, .cw14 .h h2, '+
				'.cw15, .cw13 h2',
				{fontFamily: 'Sakkal Majalla', hover: true}
			);*/



//=================================================================
//== menu główne drugiego poziomu
//=================================================================

//$('#menu .submenu1')

$('#menu a').hover(
	function(){
		$(this).next('.submenu1').show();
	},
	function()
	{
		$(this).next('.submenu1').hide();
	}
);

$('#menu .submenu1').hover(
	function(){
		$(this).show();
	},
	function()
	{
		$(this).hide();
	}
);
	





//=================================================================
//== pole wyszukiwarki
//=================================================================

$('#search .input label').bind('click', function()
{
    $(this).hide().siblings('input').focus();
});

$('#search .input input').bind('focus', function()
{
    $(this).siblings('label').hide();
});

//=================================================================
//== dopisanie wysoko�ci do boksa z aktualno�ciami na homie
//=================================================================

//var cw3height = $('.cw3 .w').outerHeight(true);
//var cw4height = $('.cw4 .w').outerHeight(true);
//
//
//if(cw4height>cw3height)
//{
//    $('.cw3 .w').height(cw4height)
//} else {
//    $('.cw3 .w').height(cw3height)
//}

//=================================================================
//== slajdy aktualno�ci na homie
//=================================================================

var slidesLength = $('.cw3 .w').length;

var slidesNav = '';
for(var i=1; i<=slidesLength; i++)
{
    slidesNav += '<li>'+i+'</li>'
}

$('.cw3 .h').append('<ul class="nav">'+slidesNav+'</ul>');


$('.cw3 .w:first').show();
$('.cw3 .h .nav li:first').addClass('selected');

$('.cw3 .h .nav li').click(function()
{
    $('.cw3 .h .nav li.selected').removeClass();
	$('.cw3 .w').hide().eq($('.cw3 .h .nav li').index(this)).show();
	$(this).addClass('selected');
});

//=================================================================
//== rozwijana lista i przycisk wybierz
//=================================================================

if(typeof $('.choice .list a')!='undefined')
{
	 if($('.sw1 .choice .list').length)
		 $('.sw1 .choice .list li:first').addClass('selected');
	 
	 $('.choice .list').each(function(){
		if(typeof $(this).find('li.selected')!= 'undefined'  && !$(this).parent().parent().is('.footer2'))
		{
			if (!$(this).find('li.selected').hasClass('none'))
				$(this).find('li.selected').clone().appendTo($(this).find('ul')).removeClass('selected').addClass('fake');
		}
	 });
	
}


$('.choice .btn').click(function()
{
	if($(this).is('.red'))
	{
		//window.open(base+ $(this).children('a').attr('href'));
		$(this).children('a').click();
		return false;
	}
		
   window.open(base + $(this).siblings('.list').find('.selected a').attr('href'));
});



var selectarray = new Array();
$('.choice .list').each(function()
{
	selectarray.push($(this));
});

$('.choice .list').toggle(function()
{
	for(i=0; i<selectarray.length; i++)
		{
			if(selectarray[i].find('ul').height() > 0)
				selectarray[i].click();
		}
    $(this).find('ul').css({'height': 'auto'});
	
}, function()
{
    $(this).find('ul').css({'height': '0'});
});

$('*:not(.choice *)').click(function(event){
	if ($.browser.msie)
	{
		if(event.srcElement == this){
			$('.choice .list ul').each(function()
			{
				if($(this).height() > 0)
					$(this).parents('.list').click();
			});
		}
	} else
	{
		if(event.target == this){
			$('.choice .list ul').each(function()
			{
				if($(this).height() > 0)
					$(this).parents('.list').click();
			});
		}
	}
});



$('.choice .list a').click(function()
{
   if($(this).parents('.footer-calc').length)
   {
       $(this).parents('ul').find('li').removeClass('selected');

       $(this).parent().addClass('selected');
	  
       $(this).parents('li').click();
       
       return false;
   }

   if(!($(this).parent().is('.selected') || $(this).parent().is('.fake')) && !$(this).parents('.footer2').length)
   {
       $(this).parents('ul').find('li').removeClass('selected');

	   $(this).parents('ul').find('li.fake').remove();
	   $(this).parent().clone().appendTo($(this).parents('ul')).addClass('fake');

       $(this).parent().addClass('selected');

	  // $(this).parent().appendTo($(this).parents('ul'));
	  
       $(this).parents('ul').click();
       
       return false;
   }

});

$('.footer2 .choice .list a').click(function()
{
	if(!$(this).parent().is('.selected') )
	{
		 window.location = base + $(this).attr('href');
	}
});

//=================================================================
//== rotator fotek w tle
//=================================================================

pf = $('#slider .slide');
pfl = pf.length;
pfnr = 0;

$('#slider .slide:first-child').show();

if($('#slider .slide').length > 1)
    setInterval("sliderInterval()", 4000);


//=================================================================
//== tabelki - resetowanie marginesu dla IE6
//=================================================================

if($.browser.msie && $.browser.version == 6.0)
    $('table + table').css('margin-top', '-1px');

	
	
//=================================================================
//== ukrywanie menu
//=================================================================
	
if($('#submenu').length)
{
	$('#submenu li ul').css('display', 'none');
	//$('#submenu li li ul').css('display', 'none');
	$('#submenu li.selected ul').css('display', 'block');
	$('#submenu li.selected li ul').css('display', 'none');
	$('#submenu li ul li.selected').parent().parent().parent().addClass('selected');
	$('#submenu li ul li.selected').parent().css('display', 'block');

	$('#submenu li ul li ul li.selected').parent().parent().parent().addClass('selected');
	$('#submenu li ul li ul li.selected').parent().parent().parent().parent().parent().parent().addClass('selected');
	$('#submenu li ul li ul li.selected').parent().css('display', 'block');
}	
//=================================================================

});


//=================================================================
//== funkcje do obsługi klienta
//=================================================================



function serviceChange(service, region)
{

	if(typeof region =='undefined')
		region = '';

	if(typeof homePage =='undefined')
		homePage = false;

//	alert(service);
	///alert(region);

	if(region=='')
	{
		// ładowanie mapy
		$('#services-list').html('');
		$('#services-map').spinner();
		url = base + 'services/get_map/' + service;
		$('#services-map').load(url);
		if (typeof event!='undefined')
			event.returnValue=false;
		return false;
	}
	if (!homePage && region)
	{
		// ładowanie listy serwisów
		url = base + 'services/get_services/' + service + '/' + region;
		$('#services-list').load(url, function(){
			return false;
			if (typeof event!='undefined')
				event.returnValue=false;
		});

		return false;
			if (typeof event!='undefined')
				event.returnValue=false;
		
	}
	
	if(homePage && region!='' && region)
	{
		// nowa strona
		location.href = base + '/biura-obslugi-klienta/' + service + '/' + region;

		if (typeof event!='undefined')
			event.returnValue=false;

		return false;
	}

	if (typeof event!='undefined')
			event.returnValue=false;
		
	return false;
}




// ================================== zmiana fontow
function changeFont(size)
{
	var date;
        switch(size)
	{
            case 11:
                $('#font-size span').removeClass();
                $('#font11').addClass('selected');
				Cufon.refresh();

                $('#content').css({
                    'font-size': '11px',
                    'line-height': '18px'
		});
                $('#documents .pdf').css({
                    'font-size': '9px',
                    'line-height': '14px'
                });
                 $('.mw5 h2').css({
                    'font-size': '11px',
                    'line-height': '18px'
                });
                $('#content .date span').css({
                    'font-size': '9px'
                });
                $('.mw1 .w').css({
                    'font-size': '11px',
                    'line-height': '14px'
		});
                $('.mw2 .w').css({
                    'font-size': '11px',
                    'line-height': '14px'
		});
                $('.mw3 .w').css({
                    'font-size': '11px',
                    'line-height': '14px'
		});
                $('.mw4 .w').css({
                    'font-size': '11px',
                    'line-height': '14px'
		});
                $('.mw6 .w').css({
                    'font-size': '11px',
                    'line-height': '14px'
		});

                $.cookie('CakeCookie[Font][size]', null, {path: '/'});
                return false;


                break;



            case 13:
                $('#font-size span').removeClass();
                $('#font13').addClass('selected');
				Cufon.refresh();

                $('#content').css({
                    'font-size': '13px',
                    'line-height': '21px'
		});
                $('#documents .pdf').css({
                    'font-size': '11px',
                    'line-height': '16px'
                });
                $('.mw5 h2').css({
                    'font-size': '13px',
                    'line-height': '20px'
                });
                $('#content .date span').css({
                    'font-size': '11px'
                });
                $('.mw1 .w').css({
                    'font-size': '13px',
                    'line-height': '16px'
		});
                $('.mw2 .w').css({
                    'font-size': '13px',
                    'line-height': '16px'
		});
                $('.mw3 .w').css({
                    'font-size': '13px',
                    'line-height': '16px'
		});
                $('.mw4 .w').css({
                    'font-size': '13px',
                    'line-height': '16px'
		});
                $('.mw6 .w').css({
                    'font-size': '13px',
                    'line-height': '16px'
		});

                date = new Date();
                date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
                $.cookie('CakeCookie[Font][size]', size, {path: '/', expires: date});
                return false;

                break;


            case 15:
                $('#font-size span').removeClass();
                $('#font15').addClass('selected');
				Cufon.refresh();

                $('#content').css({
                    'font-size': '15px',
                    'line-height': '23px'
		});
                $('#documents .pdf').css({
                    'font-size': '13px',
                    'line-height': '18px'
                });
                $('.mw5 h2').css({
                    'font-size': '15px',
                    'line-height': '22px'
                });
                $('#content .date span').css({
                    'font-size': '13px'
                });
                $('.mw1 .w').css({
                    'font-size': '15px',
                    'line-height': '18px'
		});
                $('.mw2 .w').css({
                    'font-size': '15px',
                    'line-height': '18px'
		});
                $('.mw3 .w').css({
                    'font-size': '15px',
                    'line-height': '18px'
		});
                $('.mw4 .w').css({
                    'font-size': '15px',
                    'line-height': '18px'
		});
                $('.mw6 .w').css({
                    'font-size': '15px',
                    'line-height': '18px'
		});

                date = new Date();
                date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
                $.cookie('CakeCookie[Font][size]', size, {path: '/', expires: date});
                return false;

                break;
        }
}

//=================================================================

