var BIGGG=0;
function openWindow(url, w, h,name) {
        var Win = window.open(url,name,'width=' + w + ',height=' + h + ',resizable=1,scrollbars=yes,menubar=no' )
}
function show_hide(ggg)
{

var val;
   val=document.getElementById(ggg);
   if(val.style.display=='none') val.style.display='';
   else val.style.display='none';


}
function hide(ggg)
{

var val=false;
   val=document.getElementById(ggg);
if(!val) alert(ggg);
   val.style.display='none';
}
function show(ggg)
{

var val;
   val=document.getElementById(ggg);
   val.style.display='';


}

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);
}

var BIG;

var MAKE_BIGGER_TAB='';
window.addEvent('domready', function(){
 if($$('.mb').length > 0)//only triggered if 'mb' class found on page
 {
 var initMultiBox = new multiBox('mb', {
 descClassName: 'multiBoxDesc',//the class name of the description divs
 path: './Files/',//path to mp3 and flv players
 useOverlay: true,//use a semi-transparent background. default: false;
 maxWidth: 600,//max width (set to false to disable)
 maxHeight: 400,//max height (set to false to disable)
 addDownload: false,//do you want the files to be downloadable?
 pathToDownloadScript: './Scripts/forceDownload.asp',//if above is true, specify download script
 addRollover: false,//add rollover fade to each multibox link
 addOverlayIcon: false,//adds overlay icons to images within multibox links
 addChain: true,//cycle through all images fading them out then in
 recalcTop: true//subtract the height of controls panel from top position
 });
 };
 if($$('.page_log').length > 0)//only triggered if 'mb' class found on page
 {
	$$('.page_log').addEvents({ 
		'mouseenter':function (e) { this.set('tween',{duration: 200 }); this.tween('height','100');  },
		'mouseleave':function (e) {  this.tween('height','20');   }
	
	});
 }
if($$('.menu_items').length) {
	var ITEMS=new Array();
		$$('.podmenu_items_overflow').each(function(e) {
		var idd=e.id.split('_');
		ITEMS[idd[1]]=0;
//		if(e.getPrevious().get('class')=='menu_item') e.set('morph',{'duration':'300'});
		});
		$$('.menu_plusik').each(function(e) {
			e.addEvent('click',function(eve)
			{
				$$('.podmenu_items_overflow').each(function(e) {
					var h=e.getStyle('height');
					if(h!='0px') 
					{
	                    e.morph({'height':'0px'});
						e.getPrevious().getPrevious().getPrevious().setStyle('background-image','url(images/page/menu_plusik.png)');


					}

//		if(e.getPrevious().get('class')=='menu_item') e.set('morph',{'duration':'300'});
				});




				var items= this.getParent().getElement('.podmenu_items');
//				var cla=this.getParent().getChildren()[1].get('class');
				if(items )
				{
				var size=items.getSize();
				var size2=e.getParent().getElement('.podmenu_items_overflow').getSize();
				if(!size2.y)
				{

				items.getParent().set('morph',{'duration':'200'});
				items.getParent().morph({'height':size.y+'px'});
					idd=e.getParent().getElement('.podmenu_items_overflow').id.split('_');
					ITEMS[idd[1]]=1;
					this.setStyle('background-image','url(images/page/menu_plusik2.png)');
				}
				else
				{
					
					items.getParent().set('morph',{'duration':'200'});
					items.getParent().morph({'height':'0px'});
					idd=e.getParent().getElement('.podmenu_items_overflow').id.split('_');
					ITEMS[idd[1]]=0;
					this.setStyle('background-image','url(images/page/menu_plusik.png)');
				}
				}
			});
			/*
			e.addEvent('mousealeave',function(eve){
				var items= this.getElement('.podmenu_items');
				var cla=this.getChildren()[0].get('class');
				if(items && cla=='menu_item')
				{
					idd=e.getElement('.podmenu_items_overflow').id.split('_');
					ITEMS[idd[1]]=0;	
					e.fireEvent('mouseleave_kor','',2000);
				}
			});
			e.addEvent('mouseleave_kor',function(eve)
			{
					idd=e.getElement('.podmenu_items_overflow').id.split('_');
					if(ITEMS[idd[1]]) {	return ; }


				var items= this.getElement('.podmenu_items');
				if(items) {
					items.getParent().set('morph',{'duration':'500'});
					items.getParent().morph({'height':'0px'});
				}
			});
			*/

		} );
}

 var	BIGGG1=readCookie('setBigger');
var req=new Request({'url':'modules/page_modules/Pup.php',method:'post',onSuccess:function(txt) 
{
	MAKE_BIGGER_TAB=txt;
//alert(BIGCookie);
	if(BIGGG1!=null)
	{
		var i=0;
		for(i;i<BIGGG1;i++)
		make_bigger();
	}
	else BIGGG1=0;

}}).send('action=get_bigger');



	if($('galeria_prev'))
	{
		var gal_move=0;
		var over=$('galeria_overflow');
		var ile=over.getElements('img').length;


		over.getElement('div').set('morph',{onComplete:function(){gal_move=0;},onStart:function(){gal_move=1;},'transition':'back:out','duration':'300'});



		$('galeria_next').addEvent('click',function() {
			if(gal_move) return;
			var left=over.getElement('div').getStyle('left').replace('px','');

			if(left>0 && left<141 )
				over.getElement('div').morph({'left':[left+'px','0px']});
			else if(left > -((ile-2)*141)) 
			{
//			if(left <-1400) alert(left+' '+ile);
				over.getElement('div').morph({'left':[left+'px',parseInt(parseInt(left)-141)+'px']});
			}
		});

		$('galeria_prev').addEvent('click',function() {
		
			if(gal_move) return;
		var left=over.getElement('div').getStyle('left').replace('px','');
		if(left>=0) return;
			over.getElement('div').morph({'left':[left+'px',parseInt(parseInt(left)+141)+'px']});
		});

	}
	if($$('.odp_ankieta_tab').length)
		$$('.odp_ankieta_tab').each(function(a) {
//		a.set('morph',{'duration':2000});
		a.set('morph',{duration:3000});
		a.morph({'width':['0',a.get('alt')]});
		});


});
function make_smaller()
{
//var sizes= new Array(1,1);
//BIG--;
//if(BIG<0) BIG=sizes.length-1;
if(!BIGGG) return false;
BIGGG--;
eraseCookie('setBigger');
createCookie('setBigger',BIGGG,0);

var plus=1;
var tab="menu,.module_news_txt,.module_news_title,.module_title_news,.artykul_tresc";
	tab=MAKE_BIGGER_TAB;
	tabs=tab.split(',');
	tabs.each(function(tt) {
		if(tt.length)
		{
		if($(tt))
		{
			var size=$(tt).getStyle('font-size');
			size=size.replace('px','');
			$(tt).setStyle('font-size',parseInt(parseInt(size)-plus)+'px');

		}
		else
		if($$(tt).length)
		{
		$$(tt).each(function(a) {
				var size=a.getStyle('font-size');
			size=size.replace('px','');
			a.setStyle('font-size',parseInt(parseInt(size)-plus)+'px');
		});
		}
		}
	});
}
function make_bigger()
{
if(BIGGG>5) return false;
//var sizes= new Array(1,1);
//BIG++
//if(BIG>(sizes.length-1)) BIG=0;
BIGGG++;
eraseCookie('setBigger');
createCookie('setBigger',BIGGG,0);

var plus=1
var tab="menu,.module_news_txt,.module_news_title,.module_title_news,.artykul_tresc";
	tab=MAKE_BIGGER_TAB;
	tabs=tab.split(',');
	tabs.each(function(tt) {
		if(tt.length)
		{
		if($(tt))
		{
			var size=$(tt).getStyle('font-size');
			size=size.replace('px','');
			$(tt).setStyle('font-size',parseInt(parseInt(size)+plus)+'px');

		}
		else
		if($$(tt).length)
		{
		$$(tt).each(function(a) {
				var size=a.getStyle('font-size');
			size=size.replace('px','');
			a.setStyle('font-size',parseInt(parseInt(size)+plus)+'px');
		});
		}
		}
	});
}

var img_polec_time_id;
function show_polecane(i,div)
{
	$$('.numer_active').set('class','numer_not_active');
	$$('.art_polec').setStyle('display','none');
	var polec=$('art_polec_'+i)
		polec.setStyle('display','');
	$(div).set('class','numer_active');
	clearTimeout(img_polec_time_id);
	img_polec_time_id=setTimeout('change_fota_polecane()',5000);


}
function change_fota_polecane()
{
	var id=$('polecane_artykuly').getElement('.numer_active').get('text');
	var div=$('art_polec_'+id);
if(div.getElements('img').length<=1) return;
	div.getElements('img').each(function(i){ i.set('morph',{duration:1000});} );
	var img_active=div.getElement('img[alt=disp]');
	var img_next=img_active.getNext();

	
	if(!img_next)  {
		var img_next=div.getElements('img')[0];
	}
	img_active.set('alt','nodisp');
	img_next.set('alt','disp');
	img_active.morph({'opacity':[1,0]});
	img_next.morph({'opacity':[0,1]});
	
	img_polec_time_id=setTimeout('change_fota_polecane()',5000);
}

var img_najczesciej_czytane_time_id;
var img_najczesciej_czytane_ktore=0;
function change_fota_najczesciej_czytane()
{
	
	var divs=$('najczesciej_czytane').getElements('.modul_middle_item');
//	alert(divs);
	var ile=divs.length;	
	var II=-1;
	divs.each(function(div){
		II++;
//		alert(ile+' '+II+' '+img_najczesciej_czytane_ktore);

		if(img_najczesciej_czytane_ktore==(ile-1)) img_najczesciej_czytane_ktore=0;
		if(img_najczesciej_czytane_ktore==II)
		{
		if(div.getElements('img').length<=1) return;
		
		div.getElements('img').each(function(i){ i.set('morph',{duration:1000});} );
		var img_active=div.getElement('img[alt=disp]');
		var img_next=img_active.getNext();
		if(!img_next)  {
			var img_next=div.getElements('img')[0];
		}
		img_active.set('alt','nodisp');
		img_next.set('alt','disp');
		img_active.morph({'opacity':[1,0]});
		img_next.morph({'opacity':[0,1]});
		}
		
		
	});
		img_najczesciej_czytane_ktore++;
	img_najczesciej_czytne_time_id=setTimeout('change_fota_najczesciej_czytane()',2000);

}
function change_fota_artykul()
{
	var div=$('artykul_content').getElement('.artykul_fotki');
	if(div.getElements('img').length<=1) return;
	div.getElements('img').each(function(i){ i.set('morph',{duration:1000});} );
	var img_active=div.getElement('img[alt=disp]');
	var img_next=img_active.getNext();

	
	if(!img_next)  {
		var img_next=div.getElements('img')[0];
	}
	img_active.set('alt','nodisp');
	img_next.set('alt','disp');
	img_active.morph({'opacity':[1,0]});
	img_next.morph({'opacity':[0,1]});
	
	setTimeout('change_fota_artykul()',5000);
}
function add_art_2_ulubione(div,id_art)
{
	var req = new Request({method: 'get', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
//		createCookie('add_pkts_'+id_art,"1",0);
	}
	}).send('action=add_art_2_ulubione&id_art='+id_art);

}
function add_art_pkts(div,id_art)
{
	var req = new Request({method: 'get', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
		createCookie('add_pkts_'+id_art,"1",1);
		if(txt.length) $('ocena_artykulu').set('text',txt);

	}
	}).send('action=add_pkts&pkts='+div.get('text')+'&id_art='+id_art);

}
function add_koment_db(div,id_art)
{
	var txt=div.getPrevious().value;
	var req = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
		var tt=txt.split('###');
		$('liczba_komentarzy').set('text',tt[0]);
		var div=new Element('div',{'style':'border-top: 1px dotted rgb(119, 153, 119); margin-top: 10px; padding-top: 5px;','class':'artykul_komentarz'});
		div.set('html',tt[1]);
		div.inject($(document.body).getElement('.artykul_komentarze'),'top');
		$('artykul_add_komentarz').setStyle('display','none');
		$('artykul_add_komentarz').getElement('textarea').value='';

	}
	}).send('action=add_art_comments&id_art='+id_art+'&txt='+txt);

}
function add_komentarz(div,id_art)
{
	$('artykul_add_komentarz').setStyle('display','');




}
function wyszukiwanie_zaawansowane(co)
{
	if(co=='1') { 	
		$('szukaj_div').getElement('div').set('morph',{duration:500,transition:'back:out'});
		$('szukaj_div').getElement('div').morph({'top':'-93px'});
		$('szukaj_div').set('morph',{duration:500,transition:'back:out'});
		$('szukaj_div').morph({'height':'250px'});
	}
	else
	{
		$('szukaj_div').morph({'height':'93px'});
		$('szukaj_div').getElement('div').morph({'top':'0px'});
	}
}
function check_email_newsletter(inp)
{

str=inp.form.send_newsletter_request.value;  k=str.indexOf("."); m=str.indexOf("@");
if(!(m>0 && k>0) )  {        
if($('alert_newsletter')) $('alert_newsletter').destroy();
var span=new Element('span',{'id':'alert_newsletter','class':'alert_span','text':'Podany adres email jest nieprawidłowy'}).inject(inp.getParent('div'));
span.addEvent('close',function() { this.destroy();});
span.fireEvent('close','',5000);
return false; } 
else {  inp.form.submit(); }

}
function build_chart(myData,max)
	{
		//var myData=new Hash( { str });	
		var ii=0;
		var colors = ['#454545','#5f5f5f','#818181','#ababab','#c6c6c6','#c6c6c6','#dcdcdc'];
		myData.each(function(value,key) {
		//	    alert(key + ":" + value);
			ii++;
			var col=colors.getRandom();
			colors.erase(col);
			new Element('div',{'class':'ankieta_odpowiedz_txt','style':'height:14px;float:left;clear:both;','text':ii+'. '+key}).inject($('ankieta_odp'));
			new Element('div',{'style':'height:0px;clear:both;width:1px'}).inject($('ankieta_odp'));
			new Element('div',{'class':'odp_ankieta_tab','alt':parseInt(parseInt(196*value)/max),'html':'<span>'+value+'</span>','style':'background-color:'+col+';text-align:right;float:left;height:16px;width:0px;'}).inject(new Element('div',{'style':'width:196px;border:1px solid #a9a9a8 ;height:16px'}).inject($('ankieta_odp')));
			new Element('div',{'style':'clear:both;width:1px;height:0px;'}).inject($('ankieta_odp'));
		});
	}

function glosuj_ankieta(div,id)
{
	var ID=0;
	var inps=div.getParent().getElements('input');
	inps.each(function(i) {
		if(i.checked) ID=i.value;
	});
	if(!ID) {	
	if($('alert_ankieta') ) $('alert_ankieta').destroy();
	var span=new Element('span',{'id':'alert_ankieta','class':'alert_span','text':'Wybierz odpowiedź'}).inject(div,'after');
	span.addEvent('close',function() { this.destroy();});
	span.fireEvent('close','',5000);
	return false;
	}
	createCookie('ankieta_'+id,1,365);
	var req = new Request({method: 'post', url: 'modules/page_modules/Ankiety.php', evalScripts:true, onSuccess: function(txt){
		tt=txt.split('###');

		div.getParent().getParent().getParent().getParent().set('html',tt[0]);
		build_chart(myData,tt[2]);
		  if($$('.odp_ankieta_tab').length)
		          $$('.odp_ankieta_tab').each(function(a) {
			                a.set('morph',{duration:3000});
	                        a.morph({'width':['0',a.get('alt')]});
                  });
				  
	}
	}).send('action=add_ankieta_odp&id_ankieta='+id+'&odp='+ID);


}
function show_panel(id)
{
$$('.swiff-uploader-box').each(function(a) { a.destroy();});
	$('panel_content').set('html','<div id="panel_loading"> </div>');
	var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
		$('panel_content').set('html',txt);
	
		}
	}).send('action=show_panel&what_panel='+id);

}
function show_panel_artykuly(id,sort)
{
	$('panel_content').set('html','<div id="panel_loading"> </div>');
	var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
		$('panel_content').set('html',txt);
		}
	}).send('action=show_panel&what_panel='+id+'&sort='+sort);
}


function gallery_edit(id)
{
		$('panel_content').set('html','<div id="panel_loading"> </div><div id="panel_content1"></div><div id="panel_content2"></div>');
	var req_a = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
			$('panel_content2').set('html',txt);
			$('panel_loading').destroy();

	}}).send('action=show_gal_foto_edit&id_gal='+id);
	var req1 = new Request({method: 'get', url: 'fancy/source/Swiff.Uploader.js', evalScripts:true,onSuccess:function(){


		var req2 = new Request({method: 'get', url: 'fancy/source/Fx.ProgressBar.js', evalScripts:true,onSuccess:function(){
			var req3 = new Request({method: 'get', url: 'fancy/source/FancyUpload2.js', evalScripts:true,onSuccess:function(){
				var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
					$('panel_content1').set('html',txt);
					init_fancy(id);
					}
			}).send('action=gallery_edit&id_gal='+id);
		}}).send(); 
	}}).send(); 
}}).send(); 


}
function init_fancy(id_gall)
{
var up = new FancyUpload2($('demo-status'), $('demo-list'), { // options object
		// we console.log infos, remove that in production!!
		verbose: true,
		
		// url is read from the form, so you just have to change one place
		url: $('form-demo').action,
		
		// path to the SWF file
		path: 'fancy/source/Swiff.Uploader.swf',
		
		// remove that line to select all files, or edit it, add more items
		typeFilter: {
			'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'
		},
        appendCookieData: false,

		// this is our browse button, *target* is overlayed with the Flash movie
		target: 'demo-browse',
//		container: 'panel_content',	
		// graceful degradation, onLoad is only called if all went well with Flash
		onLoad: function() {
			$('demo-status').removeClass('hide'); // we show the actual UI
			$('demo-fallback').destroy(); // ... and hide the plain form
			
			// We relay the interactions with the overlayed flash to the link
			this.target.addEvents({
				click: function() {
					return false;
				},
				mouseenter: function() {
					this.addClass('hover');
				},
				mouseleave: function() {
					this.removeClass('hover');
					this.blur();
				},
				mousedown: function() {
					this.focus();
				}
			});

			// Interactions for the 2 other buttons
			
			$('demo-clear').addEvent('click', function() {
				up.remove(); // remove all files
				return false;
			});

			$('demo-upload').addEvent('click', function() {
				up.start(); // start upload
				return false;
			});
		},
		
		// Edit the following lines, it is your custom event handling
		
		/**
		 * Is called when files were not added, "files" is an array of invalid File classes.
		 * 
		 * This example creates a list of error elements directly in the file list, which
		 * hide on click.
		 */ 
		onSelectFail: function(files) {
			files.each(function(file) {
				new Element('li', {
					'class': 'validation-error',
					html: file.validationErrorMessage || file.validationError,
					title: MooTools.lang.get('FancyUpload', 'removeTitle'),
					events: {
						click: function() {
							this.destroy();
						}
					}
				}).inject(this.list, 'top');
			}, this);
		},
		
		/**
		 * This one was directly in FancyUpload2 before, the event makes it
		 * easier for you, to add your own response handling (you probably want
		 * to send something else than JSON or different items).
		 */
		onFileSuccess: function(file, response) {
			var json = new Hash(JSON.decode(response, true) || {});
			if (json.get('status') == '1') {


				file.element.addClass('file-success');
				file.info.set('html', '<strong>Obrazek został zapisany:</strong> ' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)');

				var div=new Element('div',{'class':'fotka_edycja'});
				var div1=new Element('div',{'class':'fotka_activ0'});
				var div2=new Element('div',{'class':'fotka_usun'});
				div2.addEvent('click',function(e) { del_fotka_gal(this,json.get('id_img')); });
				var img_new=new Element('img',{'src':'images/gall/'+id_gall+'/small_'+json.get('id_img')+json.get('type')});

				file.element.getElement('.file-remove').fireEvent('click','',3000);
				img_new.inject(div);
				div2.inject(div);
				div1.inject(div);
				div.inject($('galeria_edycja_fotki').getLast(),'before');





			} else {
				file.element.addClass('file-failed');
				file.info.set('html', '<strong>Pojawił się błąd:</strong> ' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response));
				file.element.getElement('.file-remove').fireEvent('click','',5000);
			}
		},
		
		/**
		 * onFail is called when the Flash movie got bashed by some browser plugin
		 * like Adblock or Flashblock.
		 */
		onFail: function(error) {
			switch (error) {
				case 'hidden': // works after enabling the movie and clicking refresh
					alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).');
					break;
				case 'blocked': // This no *full* fail, it works after the user clicks the button
					alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).');
					break;
				case 'empty': // Oh oh, wrong path
					alert('A required file was not found, please be patient and we fix this.');
					break;
				case 'flash': // no flash 9+ :(
					alert('To enable the embedded uploader, install the latest Adobe Flash plugin.')
			}
		}
		
	});
	


}
function del_fotka_gal(obj,id)
{
	var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
			obj.getParent().destroy();
		}
	}).send('action=del_fotka_gal&id_foto='+id);


}
function add_new_gall(obj)
{
	var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
			obj.getParent().setStyle('display','none');
			obj.getPrevious().value='podaj nazwę';
			var tr=new Element('tr');
			tr.inject(obj.getParent().getParent().getElement('table'));
			tr.set('html',txt);



			
		}
	}).send('action=add_new_gal&name='+obj.getPrevious().value);

}
function sort_order_zamow(im,name)
{
	var src=$(im).get('src');
	var sort=$('sort_order_zamow');
	if(src.contains('_up.png')) {
		$(im).set('src','images/icons/arrow_down.png');
		sort.value=name+' ';
	}
	else
	{
		$(im).set('src','images/icons/arrow_up.png');
		sort.value=name+' desc';

	}
	sort.form.submit();

}
var ck_edit;
function edit_art(id_art)
{
	var action='add_art';
	if(id_art) action='mod_art&id_art='+id_art;
	window.CKEDITOR_BASEPATH='http://logicnet.pl/public/pup/ckeditor/';
	var req3 = new Request({method: 'get', url: 'ckeditor/ckeditor.js', evalScripts:true, onSuccess: function(txt){ 
	var req1 = new Request({method: 'get', url: 'ckeditor/lang/pl.js', evalScripts:true, onSuccess: function(txt){ 
	var req = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){

	
	var txtt=txt.split('####');
	if(action=='add_art') id_art=txtt[1];
	if(action=='add_art') { $('panel_content').store('del',txtt[1]); }

			$('panel_content').set('html',txtt[0]);
			CKEDITOR.config.enterMode=CKEDITOR.ENTER_BR;
			CKEDITOR.plugins.registered['save']=
			{
				init : function( editor )
				{
					var command = editor.addCommand( 'save',
					{
						modes : { wysiwyg:1, source:1 },
						exec : function( editor ) {
							var ttt=editor.getData();
							ttt=escape(ttt);
							new Request({method: 'post', url: 'modules/page_modules/Artykuly.php'}).send('action=save_content&id_art='+id_art+'&value='+ttt);
						}
					});
					editor.ui.addButton( 'Save',{label : 'Zapisz',command : 'save'});
				}
			}

			if(ck_edit) ck_edit.destroy();
			ck_edit=CKEDITOR.appendTo( 'ck_editor',{'filebrowserBrowseUrl' : 'ckeditor/imanager/imanager.php','skin':'v2'   } );
			ck_edit.setData($('ck_editor_txt').get('html'));


			if($$('.fotka').length>0)  {
				$$('.fotka').each(function(f) { 
					var del=new Element('img',{'src':'images/icons/delete.png','title':'Usuń zdjęcie','style':'cursor:pointer;position:absolute;right:5px;top:5px;'});
					del.addEvent('click',function() { remove_fotka(f,f.get('alt')); } );
					del.inject(f);
				} );
			}



			
		}
	}).send('action='+action);
	}
	}).send();
	}
	}).send();


}
function remove_fotka(div,id)
{

var req = new Request({method: 'get', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
	
	div.destroy();	
	} 
	}).send('action=remove_fotka&id='+id);

}


function put_img(src,id)
{
	var f=new Element('div',{'class':'fotka','alt':id});
	f.inject($('fotosy'));

	var aa=new Element('img').set('src',src);
	aa.inject(f);
	var del=new Element('img',{'src':'images/icons/delete.png','title':'Usuń zdjęcie','style':'cursor:pointer;position:absolute;right:5px;top:5px;'});
	del.addEvent('click',function() { remove_fotka(f,f.get('alt')); } );
	del.inject(f);

}

function close_art()
{
	var id_art=$('panel_content').retrieve('del');
	if(id_art)
	{	
		var req = new Request({method: 'get', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
			show_panel(1);
		}
		}).send('action=del_art&id_art='+id_art);

	}
	else show_panel(1);

}
function save_art_db(id_art,col,val)
{
	
		var req = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){

		
		$('panel_content').eliminate('del');
		if(!$('zapisano')) 
		{
		var td=$$('.art_tab').getParent();
		var div=new Element('div',{'id':'zapisano','style':'margin-left:10px;width:80px;height:20px;background-color:#ff0000;float:left;','text':'Zapisano'});
		var divs=td.getChildren().getLast();
//		alert(divs);
		var a=divs[divs.length-1];
		div.inject(a,'before');

		div.addEvent('koniec',function() { this.destroy();})
		div.fireEvent('koniec','',1500);
		}
		}
		}).send('action=save_art_db&id_art='+id_art+'&name='+col+'&value='+val);
}

function logout()
{
		var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true,onSuccess:function(){
			document.location='index.html'; 
		
		}}).send('action=logout');
	
}
function init_galerie()
{
if($$('.galeria_player').length)
	{
		var gal_move=0;
		$$('.galeria_player').each(function(gall) {

		var over=gall.getElement('.galeria_overflow]');
		var ile=over.getElements('img').length;


		over.getElement('div').set('morph',{onComplete:function(){gal_move=0;},onStart:function(){gal_move=1;},'transition':'back:out','duration':'300'});



		gall.getElement('.galeria_next]').addEvent('click',function() {
			if(gal_move) return;
			var left=over.getElement('div').getStyle('left').replace('px','');

			if(left>0 && left<141 )
				over.getElement('div').morph({'left':[left+'px','0px']});
			else if(left > -((ile-2)*141)) 
			{
//			if(left <-1400) alert(left+' '+ile);
				over.getElement('div').morph({'left':[left+'px',parseInt(parseInt(left)-141)+'px']});
			}
		});

		gall.getElement('.galeria_prev]').addEvent('click',function() {
		
			if(gal_move) return;
		var left=over.getElement('div').getStyle('left').replace('px','');
		if(left>=0) return;
			over.getElement('div').morph({'left':[left+'px',parseInt(parseInt(left)+141)+'px']});
		});
	});
	}
}
function add_ankieta()
{
if($('nowa_ankieta')) $('nowa_ankieta').destroy();
var cord=$('panel_content').getSize();
var div=new Element('div',{'id':'nowa_ankieta','style':'left:'+(cord.x-420)+'px;'  });
div.inject($('panel_content'),'top');
var spa=new Element('span',{'text':'Pytanie'});
var pyt=new Element('input',{'type':'text','id':'pytanie','style':'width:90%'});
var odp=new Element('input',{'type':'button','value':'Dodaj odpowiedź','style':'margin-top:10px;margin-left:150px;'});
odp.addEvent('click',function() {     
	new Element('input',{'style':'width:340px;margin-top:5px;'}).inject(odps);
	var a=new Element('input',{'type':'button','value':'usuń','style':'margin-left:2px;margin-top:5px;width:38px;'}).addEvent('click',function(){ this.getPrevious().destroy(); this.destroy(); }).inject(odps);
});
var end=new Element('input',{'type':'button','value':'Stwórz Ankiete','style':'margin-left:150px;'});
var odps=new Element('div',{'id':'odpowiedzi','style':'height:220px;overflow:auto;overflow-x:hidden;width:400px;'});
spa.inject(div);
pyt.inject(div);
odp.inject(div);
odps.inject(div);
end.inject(div);
end.addEvent('click',function(){ stworz_ankieta();});

}

function stworz_ankieta()
{

var str='';
$('odpowiedzi').getElements('input:nth-child(2n-1)').each(function(a){

	str=str+a.value+'###';
});
var myRequest = new Request({method: 'post', url: 'modules/page_modules/Ankiety.php',onSuccess:function() {

show_panel(5);
//if($('nowa_anieta')) $('nowa_ankieta').destroy();

}}).send('action=add_ankieta&pyt='+$('pytanie').value+'&odps='+str);

}
function edit_ankieta(img,id)
{
if($('edit_'+id)) $('edit_'+id).destroy();
else
{
var myRequest = new Request({method: 'post', url: 'modules/page_modules/Ankiety.php',onSuccess:function(txt) {

	new Element('tr',{'id':'edit_'+id}).inject(img.getParent().getParent(),'after').set('html',txt);

}}).send('action=edit_ankieta&id='+id);
}

}

function del_odp_ankieta(img,id)
{
if(confirm('Napewno chcesz usunąć tą odpowiedź'))
{
var myRequest = new Request({method: 'post', url: 'modules/page_modules/Ankiety.php',onSuccess:function(txt) {

	img.getParent().getParent().destroy();

}}).send('action=del_odp&id='+id);
}

}

function edit_odp_ankieta(img,id)
{
	var td=img.getParent().getPrevious();
	var txt=td.get('text');
		td.set('text','');
	var inp=new Element('input',{'value':txt})
	inp.addEvent('change',function(){   
		var req = new Request({method: 'post', url: 'modules/page_modules/Ankiety.php',onSuccess:function(txt) {
		td.set('text',inp.value);
		}}).send('action=edit_odp&id='+id+'&odp='+inp.value);

	});
	inp.inject(td);
}
function add_odp_ankieta(img,id)
{
	var odp=prompt('Podaj odpowiedź');

	new Request({method: 'post', url: 'modules/page_modules/Ankiety.php',onSuccess:function(txt) {

		var table=img.getParent().getParent().getParent();
		var tr=new Element('tr').inject(table);
		tr.set('html',txt);

	}}).send('action=add_odp&id='+id+'&odp='+odp);

	
}

function del_ulubiony_art(img,id)
{
if(confirm('Napewno chcesz usunąć ten artykuł z ulubionych?'))
{
var myRequest = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php',onSuccess:function(txt) {

	img.getParent().getParent().destroy();

}}).send('action=del_ulubiony_art&id='+id);
}

}


function wyniki_wyszukiwania_offset(off)
{
	var topp=$('szukaj_div').getElement('div').getStyle('top');
	var forms=$('szukaj_div').getElements('form');
	var i=0;
	if(topp=='0px') i=0; else i=1; 
	forms[i].offset.value=off;
	forms[i].submit(); 
}
function polec_artykul(img,id)
{

	var email=prompt('Podaj mail');
	var myRequest = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php',onSuccess:function(txt) {


	}}).send('action=polec_artykul&email='+email+'&id='+id);

		
}
function set_lang_art(id_art,lang,div)
{
	var req = new Request({method: 'post', url: 'modules/page_modules/Artykuly.php', evalScripts:true, onSuccess: function(txt){
	//	$('panel_content').set('html',txt);
		div.getParent().getElements('div').each(function(a) {  
			a.setStyle('border','0px none');
		});
		div.setStyle('border','1px solid #ff0000');
		var tt=txt.split('####');
		$('art_form').tytul.value=tt[0];
		$('art_form').zajawka.value=tt[1];
//		edit_iframe.CKEDITOR.setData(tt[2]);
		ck_edit.setData(tt[2]);
//alert(edit_iframe.document.getElementById('cke_contents_ck_content').getElementByTag('iframe'));
//		edit_iframe.document.getElementById('cke_contents_ck_content').getElementByTag('iframe').document.body.innerHTML=tt[2];
		}
	}).send('action=set_lang_art&id_art='+id_art+'&art_lang='+lang);

}


function edit_komentarz_panel(obj,id)
{
	var td=obj.getParent().getPrevious();

	var tmp=td.get('text');
	td.set('text','');
	var inp=new Element('textarea',{'text':tmp,'style':'width:300px;height:150px'}).inject(td);
	var inp2=new Element('input',{'type':'button','value':'Zapisz'}).inject(td);
	inp.focus();
	inp2.addEvent('click',function(){
	
		new Request({url:'modules/page_modules/Pup.php',method:'post',onSuccess:function(txt) {
		
			td.set('text',inp.value);
		}}).send('action=mod_komentarz&id='+id+'&content='+inp.value);
	
	});


}
function go_page_panel(id,offset)
{
	var sort=$('panel_sort')?$('panel_sort').value:0;
	$('panel_content').set('html','<div id="panel_loading"> </div>');
	var req = new Request({method: 'post', url: 'modules/page_modules/Pup.php', evalScripts:true, onSuccess: function(txt){
		
		$('panel_content').set('html',txt);
		}
	}).send('action=show_panel&what_panel='+id+'&offset='+offset+'&sort='+sort);
}

function pasek_info()
{
var tresc=$('pasek_info_tresc');
tresc.setStyle('position','absolute');
var spans=$('pasek_info_tresc').getElements('.info');	
var span=spans[0];	
if(!span) return;
var ww=parseInt(span.getSize().x);


tresc.set('morph',{transition:'linear',duration:ww*20,
	onComplete:function(){  tresc.setStyle('left','0px');span.destroy();pasek_info(); },
	onStart:function(){ span.clone().inject(tresc);}
});

tresc.addEvent('mouseenter',function(e) {  this.setStyle('cursor','-moz-grabbing');this.get('morph').pause(); });
tresc.addEvent('mouseleave',function(e) {  this.setStyle('cursor','pointer');this.get('morph').resume(); });


//alert('pasek jazda '+ww);
//tresc.morph({'margin-left':[0,-ww]});
//tresc.setStyle('left','0px');
tresc.morph({'left':[0,-ww]});


}

