function drukuj() {
	var tUrl = document.location + ( document.location.href.indexOf('?') > 0 ? '&' : '?') + '_view=print';
	var tWin = window.open( tUrl, 'tPrint', 'status=no,scrollbars=1,resizable=1,width=800,height=800,top=20,left=20');
	tWin.focus();
}
function drukujSekcje( pageCode ) {
	var tUrl = 'pageprint.php?page='+pageCode;
	var tWin = window.open( tUrl, 'tPrint', 'status=no,scrollbars=1,resizable=1,width=800,height=800,top=20,left=20');
	tWin.focus();
}
function drukujRaport( year, lang ) {
	var tUrl = 'pageprint.php?year='+year+'&lang='+lang;
	var tWin = window.open( tUrl, 'tPrint', 'status=no,scrollbars=1,resizable=1,width=800,height=800,top=20,left=20');
	tWin.focus();
}

function switchTheme( themeName ) {
	createCookie( 'siteTheme', themeName, 30 );
	document.location.reload();
}

function gotoPage( pageCode ) {
	window.open( pageCode, '_blank');
}

// galeria

function swapImage( imgIndex )
{
	if( jQuery( '#img_src_' + currentImgNo ) )
	{
		jQuery( jQuery('#img_src_' + currentImgNo ).parent() ).removeClass('active');
	}
	currentImgNo = parseInt( imgIndex );
	jQuery('#imgBig').attr( 'src', jQuery( '#img_src_' + currentImgNo ).val() );
	jQuery('#imgBig').attr( 'alt', jQuery( '#img_name_' + currentImgNo ).val() );
	jQuery('#imgName').text( jQuery( '#img_name_' + currentImgNo ).val() );
	if( jQuery( '#img_desc_' + currentImgNo ).val() )
	{
		jQuery('#imgDesc').text( jQuery( '#img_desc_' + currentImgNo ).val() );
		jQuery('#imgDesc').show();
	}
	else
	{
		jQuery('#imgDesc').hide();
	}
	jQuery( jQuery('#img_src_' + currentImgNo ).parent() ).addClass('active');

	updateButtons();
}
function prevImage()
{
	if( ( currentImgNo - 1 ) > 0 )
	{
		swapImage( currentImgNo - 1 );
	}
}
function nextImage()
{
	if( ( currentImgNo + 1 ) <= totalImgCnt )
	{
		swapImage( currentImgNo + 1 );
	}
}
function updateButtons()
{
	if( currentImgNo == 1 )
	{
		jQuery( '#btnPrev' ).hide();
	}
	else
	{
		jQuery( '#btnPrev').show();
	}
	if( currentImgNo == totalImgCnt )
	{
		jQuery( '#btnNext' ).hide();
	}
	else
	{
		jQuery( '#btnNext' ).show();
	}
}
function report(nazwa, stan) {
	if( stan == 'on' ) {
		jQuery( '#' + nazwa ).show();
	}
	else {
		jQuery( '#' + nazwa ).hide();
	}
}

// font size

jQuery("document").ready( function() {
	var fontSizesMap = {
			fs09: {
				selectors: [
					'#header #topnav', '#header #search', '#path'
				],
				newSize: {
					fontSmall:  '9px',
					fontNormal: '10px',
					fontBig:    '12px'
				}
			},
			fs10: {
				selectors: [
					'.box_03 li', '.box_03a li'
				],
				newSize: {
					fontSmall:  '10px',
					fontNormal: '11px',
					fontBig:    '13px'
				}
			},
			fs11: {
				selectors: [
					'body', 'input', 'select', 'textarea', '.box_06 .content .quote h4'
				],
				newSize: {
					fontSmall:  '11px',
					fontNormal: '12px',
					fontBig:    '14px'
				}
			},
			fs12: {
				selectors: [
					'.fs12', '#mainmenu li'
				],
				newSize: {
					fontSmall:  '12px',
					fontNormal: '13px',
					fontBig:    '16px'
				}
			},
			fs13: {
				selectors: [
					'h3', '.box_04 h2', '.box_05 .content h4', '.box_06 .content .quote h3'
				],
				newSize: {
					fontSmall:  '13px',
					fontNormal: '14px',
					fontBig:    '16px'
				}
			},
			fs14: {
				selectors: [
					'h2', '.box_03 h2', '.box_03a h2', '.box_05 h2'
				],
				newSize: {
					fontSmall:  '14px',
					fontNormal: '16px',
					fontBig:    '18px'
				}
			},
			fs18: {
				selectors: [
					'h1', '.box_01 h2'
				],
				newSize: {
					fontSmall:  '18px',
					fontNormal: '20px',
					fontBig:    '24px'
				}
			}
	};
	var fontClassMap = {
			h115px: {
				fontSmall:  '115px',
				fontNormal: '115px',
				fontBig:    '130px'
			},
			h135px: {
				fontSmall:  '135px',
				fontNormal: '135px',
				fontBig:    '145px'
			},
			h180px: {
				fontSmall:  '180px',
				fontNormal: '180px',
				fontBig:    '200px'
			},
			h200px: {
				fontSmall:  '200px',
				fontNormal: '200px',
				fontBig:    '230px'
			},
			box_03: {
				fontSmall:  '114px',
				fontNormal: '114px',
				fontBig:    '130px'
			}
	};
	function setFont() {
		var fontSize = readCookie('fontCookie');
		if( !fontSize ) {
			fontSize = 'fontSmall';
		}
		$('#' + fontSize).click();
	}
	function changeFont( element ) {
		if( readCookie('siteTheme') == 'contrast' ) {
			return false;
		}
		$(element).addClass('on').siblings().removeClass('on');
		var newFontName = $(element).attr('id');
		$.each( fontSizesMap, 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 );
	}
	$('#fontChanger').find('span').each( function() {
		$(this).bind('click', function() { changeFont(this); } );
	} );
	setFont();

	if( $('a[href^=#]').length ) {
		$('a[href^=#]').each( function( i, obj ) {
			var baseLocation = document.location.href;
			if( document.location.hash.length ) {
				baseLocation = baseLocation.substr( 0, baseLocation.indexOf('#') );
			}
			$(this).attr( 'href', baseLocation + $(this).attr('href') );
		});
	}
});

// cookie

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=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for( var i=0; i < ca.length; i++ ) {
		var c = ca[i];
		while( c.charAt(0) == ' ' ) {
			c = c.substring( 1, c.length );
		}
		if( c.indexOf( nameEQ ) == 0 ) {
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
function eraseCookie( name ) {
	createCookie( name, "", -1 );
}

