window.addEvent('domready', function() {
	emenuA = new Array();
	current = 2;
	allfotos = 0;
	gallfotos = 0;
	zdjecia = new Array();
	zdjecia2 = new Array();
	var myTimer = '';
	
	$$('.plinks').each(function(el, i) {
		emenuA[el.id] = new Element('img', {'src': el.href});
	});
	
	var galeria = function( fotoid, linki ) {
		var fx = new Fx.Morph($( fotoid ), {duration: 300, transition: Fx.Transitions.Sine.easeOut});
		prodchange = function( img, imgbig, id, user ){
			obraz = emenuA[id];
			if( user )
			{
				myid = id.substr(fotoid.length, id.length);
				current = parseInt(myid) + 1;
				if( current > allfotos ) current = 1;
				myTimer = $clear(myTimer);
				startgaleria();
			}
			if( imgbig )
			{
				
				zz_s = '';
				jj = 0;
				ss_start = 0;
				zdjecia2.each(function(e) {
					var myString = new String( e ); 
					zz = myString.split(',');
					zz_s = zz_s + '["' +zz[1]+ '", "' +zz[2]+ '"], ';
					if( imgbig == zz[1] )
					{
						ss_start = jj;
					}
					
					jj = jj + 1;
				});
				zz_s = zz_s.substr(0, zz_s.length-2);
				
				if(zz_s)
				{
					var link = new Element('a', {'href': imgbig, 'onclick': 'Slimbox.open([' + zz_s + '], ' + ss_start + '); return false;' });	
				}
				else
				{
					var link = new Element('a', {'href': imgbig, 'onclick': 'Slimbox.open(\'' + imgbig + '\'); return false;' });	
				}
				
				/*
				var link = new Element('a', {'href': imgbig, 'onclick': 'return hs.expand(this)' });
				link.addClass('highslide');*/
			}
			
			$$('.' + linki).removeClass('active');
			$(id).addClass('active');
			fx.start({ 'opacity' : 0 }).chain(function(){
				$(fotoid).erase('html');
				if( imgbig )
				{
					link.inject( $(fotoid) );
					obraz.inject( link );
				}
				else
				{
					obraz.inject( $(fotoid) );
				}
				
				fx.start({ 'opacity' : 1 });
			});
		};
	};
	
	galeria( 'foto', 'plinks');
	
	startgaleria = function(){
		/*myTimer = $clear(myTimer);*/
		if( allfotos > 1 )
		{
			var delayed_func = function(){
				/*alert( zdjecia[current][0] );*/
				prodchange( zdjecia[current][0], zdjecia[current][1], 'foto'+current );
				
				current = current + 1;
				if( current > allfotos ) current = 1;
				startgaleria();
			};
			myTimer = delayed_func.delay(3000);					
		}
	};
	
	pushfoto = function( img, imgbig, id ){
		zdjecia[id] = new Array(img, imgbig);
	};
	
	pushallfoto = function( img, imgbig, opis, id ){
		zdjecia2[id] = new Array(img, imgbig, opis);
	};
	

	
});

function mlynu(data){
	alert(data);
}

function blurall() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++){
		links[i].onfocus = blurme;
	}
}

function blurme()
{
	this.blur();
}

//funkcja do wyswietlania popupu
var okno_pop='';
function popup(wi,he,uerel,alignx,aligny,scrol)
{
  // 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', 'menubar=no, toolbar=no, location=no, scrollbars=no, resizable=no, status=no ,scrollbars='+scrol+',height='+he+',width='+wi+',top='+yy+',left='+xx);
}


/*
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';
}
*/