$().ready(function(){
	$('.ul-no-margin').hide();
	$('.active').parent('li').next('ul').show();
	//rozwijanie menu
	$('.toggle').click(function(){
		$(this).next('ul').toggle('fast');
		$('a').removeClass('active');
		$(this).find('a').addClass('active');
	});
	
	$('.podmenuActive').parent('li').parent('ul').show();
	
	$('.menu-kontakt').show();
	
	$('.galleryAllPhotos img:first-child').click();
	$('#fontSmall').click();
});


jQuery("document").ready( function() {
	var sizeArray = {
			fs01: {
				selectors: [
					'.oFirmie li a','.tresc','.aktualnosc','.ciekawostka','.text li a'
				],
				newSize: {
					fontSmall:  '11px',
					fontNormal: '13px',
					fontBig:    '15px'
				}
			},
			
			fs02: {
				selectors: [
					'.aktualnaStrona'
				],
				newSize: {
					fontSmall:  '9px',
					fontNormal: '10px',
					fontBig:    '13px'
				}
			},
			
			fs03: {
				selectors: [
					'.naglowekGlowny',
				],
				newSize: {
					fontSmall:  '15px',
					fontNormal: '17px',
					fontBig:    '19px'
				}
			},
			
			fs04:{
				selectors: [
					'.aktualnosc > .naglowek','.ciekawostka > .naglowek',
			],
				newSize: {
					fontSmall:  '13px',
					fontNormal: '15px',
					fontBig:    '17px'
				}
			},
			
			fs05:{
				selectors: [
					'#header .grupaOrlen', '#header .szukaj', '#header .zaloguj',
			],
				newSize: {
					fontSmall:  '9px',
					fontNormal: '11px',
					fontBig:    '13px'
				}
			}
	};


	function changeFont( element ) 
	{
		if( getCookie('siteTheme') == 'contrast' ) {
			return false;
		}
		$(element).addClass('clicked').siblings().removeClass('clicked');
		var newFontName = $(element).attr('id');
		$.each( sizeArray, function( fontName, newFont ) {
			$.each( newFont.selectors, function( index, selector ) {
				$(selector).each( function() {
					$(this).css('font-size', newFont.newSize[ newFontName ] );
				});
			});
		});

		$.each( fontClassMap, function( hClass, hValue ) {
			$('.' + hClass).each( function() {
				$(this).css('height', hValue[ newFontName ] );
			});
		});
		createCookie( 'fontCookie', $(element).attr('id'), 15 );
	}

	$('#changeFontSize').find('span').not('.prefix').each( function() {
		$(this).bind('click', function() { changeFont(this); } );
	} );

	setFont();
	
	//ustawianie czcionki
	function setFont() {
		var fontSize = getCookie('fontCookie');
		if( !fontSize ) {
			fontSize = 'fontSmall';
		}
		$('#' + fontSize).click();
	}

	function fontClassMap() {};
});


//tworzenie ciasteczka
function createCookie( name, value, days ) 
{
	if(days)
	{
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var expires = "; expires=" + date.toGMTString();
	}
	else
		var expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";
	
	return 0;
}

//usuwanie cookie
function remCookie(name) 
{
	createCookie( name, "", -1 );
}


//pobieranie wartosci cookie (rozmiar fonta)
function getCookie(name)
{
	var cookieEx = name + "=";
	var myCookie = document.cookie.split(';');

	for( var i=0; i < myCookie.length; i++ ) 
	{
		var tmp = myCookie[i];
		while(tmp.charAt(0)==' ') 
			tmp = tmp.substring( 1, tmp.length );
		if(tmp.indexOf( cookieEx ) == 0 )
			return tmp.substring(cookieEx.length,tmp.length);
	}

	return null;

}

function nextImg()
{
	$('img[name="actualImg"]').next('a').next('img').click();
	var nextSrc = $('img[name="actualImg"]').next('a').next('img').attr('src');
	if(nextSrc==null)
		$('.galnext').hide();
}

function prevImg()
{
	$('img[name="actualImg"]').prev('a').prev('img').click();
	var prevSrc = $('img[name="actualImg"]').prev('a').prev('img').attr('src');
	if(prevSrc==null)
		$('.galprev').hide();
}




