$(document).ready(function(){
	
	var width = (screen.availWidth);
	if(width > 1000) width = (width -960)/2 
	$('#layer .layer-close').css({marginRight: width});
	
	$('.layer-close').click(function(){		
		$('#layer').hide();
		$('#layer-content').html('');
	});
	
	$('.popup-close').click(function(){
		$(this).parent().parent().fadeOut(function(){
			$('.popup .popup-inside').html('Ładowanie zawartości ... ');		
		});
		
	});

	$('.newsletter_send').live('click',function(){
		sendNewsletter();
	})	
	
	function sendNewsletter() {
		var email = $('.newsletter input[name=email]').val();
		if( $('.newsletter input[name=zgoda]').is(':checked') && email.length > 0) {
			console.info(email);			
			$.post('index.php', {
				ajax: 1,
				zgoda: 'on',
				email: email
			}, function(response){
				$('.newsletter_info').text(response.newsletter);
				// console.info(response.newsletter);
			}, 'json');
		}		
	}

	$('#news-input').live("keypress", function(e) {
	     if(e.keyCode == 13)
	     {
		  sendNewsletter();
		  return false;
	     }
	});

});

function runGame(game) {
	popup(988, 620, 'flash/show.php?id='+game,'','',1);
}

function newsFile(file_id) {
	window.location = 'download.php?plik='+file_id;
}

function printNews(news_id) {
	popup(600, 600, 'aktualnosci.php?news_id='+news_id+'&print=1','','',1);
}
function printPrzepis(id) {
	popup(600, 600, 'przepisy_kulinarne.php?id='+id+'&print=1','','',1);
}
function newsGallery(news_id) {
	$.post('actions/news_gallery.php', {currentNews: news_id}, function(){
		// var so = new SWFObject("serenada_galeria.swf", "layer-content2", "100%", "100%", "9", "#000000");
		// so.addParam('wmode', 'transparent');
		// so.write("layer-content");		
		swfobject.embedSWF("serenada_galeria.swf", "layer-content", "100%", "100%", "9.0.0", "expressInstall.swf", {}, {'wmode':'transparent'},{});				
	})
	$('#layer').fadeIn();	
	// console.info('newsGallery ' + news_id);
}

// showNewsletter, hideNewsletter

function showNewsletter() {
	$('#newsletter').fadeIn('fast');
	/// console.info('tset');
}
function hideNewsletter() {
	$('#newsletter').fadeOut('fast');
}
function runNewsletter() {	
	// $('.popup').fadeIn();

	$('.popup').fadeIn('fast', function(){
		// console.info('zaladuj kontent');
		// $('.popup .popup-inside').html( $('#newsletter').html());
		setTimeout("$('.popup .popup-inside').html( $('#newsletter').html());", 2000);	
	});
		
	
	// console.info('Newsletter');
}

function closePopup() {
	window.close();
}

function runPlan() {
	// window.location = 'download.php?id=1';
	
}

//funkcje do podmiany zdjec
function fon(n){document.images[n].src='grafika/'+n+'1.gif';}
function foff(n){document.images[n].src='grafika/'+n+'.gif';}

//funkcja do wyswietlania popupu
var okno_pop='';
function popup(wi,he,uerel,alignx,aligny,scrol)
{
	// Bartosz Szczecinski
	// 20.04.2006
	// Opera 8.x nie obsluguje !okno_pop.closed
	if(okno_pop && okno_pop.closed==false) {
		okno_pop.close()
	}
	if(wi=='100%'){wi=screen.availWidth-30}
	if(he=='100%'){he=screen.availHeight-0}
	if(alignx=='left'){xx=0}
	else if(alignx=='right'){xx=(screen.availWidth-wi)-10}
	else{xx=(screen.availWidth-wi)/2}
	if(aligny=='top'){yy=0}
	else if(aligny=='bottom'){yy=(screen.availHeight-he)}
	else{yy=(screen.availHeight-he)/2}
	okno_pop=window.open(uerel, '_blank', 'scrollbars='+scrol+',height='+he+',width='+wi+',top='+yy+',left='+xx);
}

function popupFrame(wi, he, url, alignX, alignY, scroll) {
	popup(wi, he, 'popup.php?popupFile='+url.replace(/\?/, '&'), alignX, alignY, scroll);
}

function blurall() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++){
		links[i].onfocus = blurme;
	}
}

function blurme()
{
	this.blur();
}


function printversion(id,path)
{
	var okno='';
	(okno && !okno.closed)?okno.close():'';
	he=400;
	wi=730;
	xx=(screen.availHeight-he)/2-10;
	yy=(screen.availWidth-wi)/2;
	okno=window.open('print_version.php?id='+id, '_blank', 'menubar=yes,scrollbars=yes,height='+he+',width='+wi+',top='+xx+',left='+yy);
}


/*ladowanie do casch-u zdjec
foto=new Array('pl','en');
menuA=new Array();menuB=new Array();
for(n=0;n<foto.length;n++){
menuA[n]=new Image();
menuA[n].src='grafika/'+foto[n]+'.gif';
menuB[n]=new Image();
menuB[n].src='grafika/'+foto[n]+'1.gif';
}
*/



