function selectOption(src){
	$('<div id="layer"><div id="layMain"><div id="navBar"></div><div class="clear"></div>'+
	'<div id="imag"></div>'+
	'<div id="flswf" style="display: none;"><div id="head4b"></div><div id="head1b"></div><div id="head2b"></div><div id="head3b"></div></div>'+
	'<div id="swapImg"><img src="szablony/img/imgImg.jpg" alt="img" /><br/>Wybierz zdjęcie na stronę główną</div><div id="swapFlash"><img src="szablony/img/imgFlash.jpg" alt="img" /><br/>Wybierz winietę na stronę główną</div>'+
	'<div class="clear"></div></div></div><div id="backLay"></div>').prependTo('body');
	
	var height = $(document).height();
 	$('#backLay').css('height', height+'px');
	
	var close = 'close';
	$('<div class="'+close+'">[&nbsp;x&nbsp;]</div>').prependTo('#navBar');	
	
	$('.'+close).bind('click',function(){
		$('#backLay').remove();
		$('#layer').remove();	
	});
	
	$('#swapImg').bind('click',function(){
		swapImg(src);
		$(this).remove();
		$('#swapFlash').remove();
	});
	
	$('#swapFlash').bind('click',function(){
		swapFlash(src);		
		$('#flswf').show();
		$(this).remove();
		$('#swapImg').remove();
	});
		
	$('#backLay').css({'opacity':0.7,'backgroundColor': '#000'});
}
function swapImg(src){
	var img = listImg();
	var imgAll = getImg(img, src);
	$(imgAll).prependTo('#imag');
	
	$('<h2>Wybierz zdjęcia na stronę główną</h2>').prependTo('#imag');	
	
	var imgCookie = getCookie('img');
	$('#imag img').css('opacity', 0.6);
	$('#imag img').bind('click',function(){
		$('#imag img').removeClass('actCl');
		$('#imag img').css('opacity', 0.6);
		
		$(this).addClass('actCl');
		$(this).css('opacity', 1);
	});
	$('#imag img[alt='+imgCookie+']').trigger('click');
	
	$('<div id="zapisz">zapisz</div><div class="clear"></div>').appendTo('#layMain');
	
	$('#zapisz').bind('click',function(){	
		var imgVal = $('#imag img[class=actCl]').attr('alt');
		
		var date = new Date();
		year = date.getFullYear();
		date.setFullYear(year+1);
		
		setCookie('img', imgVal, date);	
		
		$('#backLay').remove();
		$('#layer').remove();
				
		$('#imgFota').attr('src','szablony/img/obrazki/'+imgVal+'.jpg');
		
		var href;
		var title;
		if(imgVal == 'starosta'){
			href = 'http://www.zlokalnejperspektywy.blogspot.com/';
			title = 'zapraszam na mój blog';
		}else{
			href = 'http://www.strzyzowski.pl/strona/nasze-galerie-i-videogalerie,789';
			title = 'zobacz galerie i videogalerie';
		}
		$('#imgFota').parent('a').attr({href: href, title: title});
		
	});
		
	height = $(document).height();
 	$('#backLay').css('height', height+'px');
}
function swapFlash(src){
	$('<h2>Winiety</h2><br/><br/><br/>').prependTo('#flswf');
	
	getSwf('head1', 'b');
	getSwf('head2', 'b');
	getSwf('head3', 'b');
	getSwf('head4', 'b');
	
	$('<h2>Zima w powiecie strzyżowskim</h2>').insertBefore('#head1b');
	$('<h2>Powiat strzyżowski w zimowy wieczór</h2>').insertBefore('#head2b');
	$('<h2>Krajobrazy zimowe powiatu strzyzowskiego</h2>').insertBefore('#head3b');
	$('<h2>Lato w powiecie strzyżowskim</h2>').insertBefore('#head4b');
			
	var flashCookie = getCookie('flash');
			
	$('#flswf div').bind('click',function(){
		$('#flswf div').removeClass('actCl');
		$('#flswf div').css('opacity', 0.6);
		
		$(this).addClass('actCl');
		$(this).css('opacity', 1);
	});
	$('#flswf div[id='+flashCookie+'b]').trigger('click');
	
	$('<'+src+'ok.gif" class="ok" />').prependTo('#flswf div');
	
	$('<div id="zapisz">zapisz</div><div class="clear"></div>').appendTo('#layMain');
	$('#zapisz').bind('click',function(){	
		
		if($.browser.msie){
			var flaVal = $('#flswf div[class=actCl] object').attr('id');
		}
		else{
			var flaVal = $('#flswf div[class=actCl] embed').attr('id');
		}
		var date = new Date();
		year = date.getFullYear();
		date.setFullYear(year+1);
		
		setCookie('flash', flaVal, date);
		
		$('#backLay').remove();
		$('#layer').remove();
		
		$('#flashMain').empty();
		$('<div id="'+flaVal+'a"></div>').prependTo('#flashMain');
		getSwf(flaVal, 'a');
	});
			
	height = $(document).height();
 	$('#backLay').css('height', height+'px');
	
}
function layer(src){

	var img = listImg();	
		
	$('<div id="layer"><div id="layMain"><div id="navBar"></div><div class="clear"></div>'+
	'<div id="flswf"><div id="head1b"></div><div id="head2b"></div><div id="head3b"></div></div>'+
	'<div id="imag">'
	+ getImg(img, src) +
	'</div>'+
	'<div id="zapisz">zapisz</div><div class="clear"></div></div></div><div id="backLay"></div>').prependTo('body');
			
	var height = $(document).height();
 	$('#backLay').css('height', height+'px');
	
	var close = 'close';
	$('<div class="'+close+'">[&nbsp;x&nbsp;]</div>').prependTo('#navBar');			
	
	$('.'+close).bind('click',function(){
		$('#backLay').remove();
		$('#layer').remove();	
	});
	
	$('#zapisz').bind('click',function(){	
		var imgVal = $('#imag img[class=actCl]').attr('alt');
		var flaVal = $('#flswf div[class=actCl] embed').attr('id');
		
		var date = new Date();
		year = date.getFullYear();
		date.setFullYear(year+1);
		
		setCookie('img', imgVal, date);	
		setCookie('flash', flaVal, date);
		
		$('.'+close).trigger('click');
		
		$('#imgFota').attr('src','szablony/img/obrazki/'+imgVal+'.jpg');
		
		var href;
		if(imgVal == 'starosta'){
			href = 'http://www.zlokalnejperspektywy.blogspot.com/';
		}else{
			href = 'http://www.strzyzowski.pl/strona/nasze-galerie-i-videogalerie,789';
		}
		
		$('#imgFota').parent('a').attr('href', href);
				
		$('#flashMain').empty();
		$('<div id="'+flaVal+'a"></div>').prependTo('#flashMain');
		getSwf(flaVal, 'a');
		
	});
		
	$('#backLay').css({'opacity':0.7});
}

function getSwf(src, par, width, height){
	if(!width)
		var width = 970;
	if(!height)
		var height = 132;
	
	var so = new SWFObject('szablony/flash/'+src+par+'.swf', src, width, height, '9');
	so.useExpressInstall('szablony/flash/expressinstall.swf');
	so.addParam("wmode", "transparent");
	so.addParam("quality", "high");
	so.addParam("menu", "false");
	so.write(src+par);
}

function getImg(arr, src){
	var nArr = arr.split(",");	
	var len = nArr.length;
	var img = '';
	for(i=0; i<len; i++){
		img += '<'+src+nArr[i]+'.jpg" alt="'+nArr[i]+'" />';		
	}		
	return img;
}

function setCookie(name, val, expire) {
  	document.cookie = name + "=" + escape(val) + ((expire==null)?"" : ("; expires=" + expire.toUTCString()))
}

function getCookie(name){
	if(document.cookie != ''){
		var toCookie = document.cookie.split('; ');
		var len = toCookie.length;
		for(i=0; i<len; i++){
			var nameCookie = toCookie[i].split('=')[0];
			var valCookie = toCookie[i].split('=')[1];
			if(nameCookie == name) return unescape(valCookie);
		}
	}
}

function popup(src){
	$('<div id="layer"><div id="layMain"><div id="navBar"></div><div class="clear"></div>'
	+ src +
	'<div class="clear"></div></div></div><div id="backLay"></div>').prependTo('body');
			
	var height = $(document).height();
 	$('#backLay').css('height', height+'px');
	
	var close = 'close';
	$('<div class="'+close+'">[&nbsp;x&nbsp;]</div>').prependTo('#navBar');			
	
	$('.'+close).bind('click',function(){
		$('#backLay').remove();
		$('#layer').remove();	
	});
		
	$('#backLay').css({'opacity':0.7});
} 

function listImg(){
	var images;
	$.ajax({
		type: 'get',
		url: 'inc/obrazki.php',
		data: 'src=/szablony/img/obrazki',
		async: false,
		success: function(msg){
			images = msg;				
		}
	});
	return images;
}

function flashBig(){
	popup('<div id="flash_big"></div>');
	getSwf('flash_big', '', 711, 750);
	$('#navBar').remove();
	$('#layMain').css({'width': '715px', 'border': 'none', 'background': 'none'});
	$(document).scrollTop(70);
}

function flashBigClose(){
	$('#layer').remove();
	$('#backLay').remove();
}
