var banner = Class.create();
banner.prototype = {
  initialize: function(interwal,wybrany) {
    this.iloscslajdow = 5;
	this.wybrany=wybrany;
	this.interwal=interwal;
	this.licznik=-1;
	this.animstate=true;
	this.animcount=-1;
	this.lastclicked=999;
	this.morph=true;
	this.page="page1";
	this.newtimeout=true;
	this.maintimeout=true;
	
	this.timeloop();
	this.eventcatcher();	
  },
  stopAnimation: function(event) {this.animstate=false;},
  startAnimation: function(event) {this.animstate=true;},
  MorphEffect: function(element) {new Effect.Morph(element, {style:'top:0px;', duration:0.1});},
  MorphEffectoff: function(element) {new Effect.Morph(element, {style:'top:5px;', duration:0.2});},
  ramkaoff: function(element) {new Effect.Morph(element, {style:'border: 1px solid #FFFFFF;', duration:0.2});},
  ramkaon: function(element) {
	  var wichphoto=element;
	  wichphoto=wichphoto;
	  wichphoto=wichphoto.charAt(wichphoto.length-1);
	  for (var i=1;i<=this.iloscslajdow;i=i+1)
	{var photo="zdjecie"+i;
	if (wichphoto!=i){this.ramkaoff(photo);}
	}
	new Effect.Morph(element, {style:'border: 1px solid #FFFF66;', duration:0.2});
  },
    showPageN: function(page,licznik) {
    pagename="page"+(licznik+1);
	if(pagename!=page){
	$(page).setOpacity(1);$(pagename).setOpacity(1);
	$(page).style.zIndex=105;
	$(pagename).style.zIndex=106;
	new Effect.Opacity(pagename, {duration:0.4, from:1.0, to:0.0});
	setTimeout("$(pagename).style.zIndex=100;",450);
}
  },
  nextshow: function(page) {
	  
    var interval=this.interwal*4;	
	this.animstate=false;
	
	if (page=="page1" && this.lastclicked!="0"){
	this.ramkaon('zdjecie1');
	this.showPageN(page,this.licznik);
	this.lastclicked=0;
	this.licznik=0;

	}
	if (page=="page2" && this.lastclicked!="1"){
	this.ramkaon('zdjecie2');
	this.showPageN(page,this.licznik);
	this.lastclicked=1;
	this.licznik=1;

	}
	if (page=="page3" && this.lastclicked!="2"){
	this.ramkaon('zdjecie3');
	this.showPageN(page,this.licznik);
	this.lastclicked=2;
	this.licznik=2;

	}
	if (page=="page4" && this.lastclicked!="3"){
	this.ramkaon('zdjecie4');
	this.showPageN(page,this.licznik);
	this.lastclicked=3;
	this.licznik=3;

	}
	if (page=="page5" && this.lastclicked!="4"){
	this.ramkaon('zdjecie5');
	this.showPageN(page,this.licznik);
	this.lastclicked=4;
	this.licznik=4;

	}
	var self=this;
	setTimeout(function(){self.animstate=true;self.lastclicked=999;}, interval); 
	this.maintimeout=setTimeout(function(){self.timeloop();}, this.interwal);
  }, 
    showPage: function(page) {
    clearTimeout(this.newtimeout);
	clearTimeout(this.maintimeout);
	var strona=page;
	var self = this;
	this.newtimeout=setTimeout(function(){self.nextshow(strona);}, 500);
  },
   timeloop: function() {
	   if(this.animstate==true){
		var iloscslajdow=this.iloscslajdow-1;
		

		
		var showpage="page"+this.wybrany;
		var lastclicked=this.animcount;

		var poprzednia=this.animcount-1;

if(this.animcount==-1){
	//pause
	}
if(this.animcount==0){this.showPageN(showpage,this.licznik);
	this.lastclicked=this.wybrany-1;
	this.licznik=(this.wybrany-1);
	var zdjecie="zdjecie"+(this.licznik+1);
	this.ramkaon(zdjecie);
}
if(this.animcount>0){
	var zdjecie="zdjecie"+(this.licznik+1);
	this.ramkaoff(zdjecie);this.showPageN("page0",this.licznik);
	this.licznik=-1;this.animcount=-1;this.lastclicked=999;} else{this.animcount=this.animcount+1;}


		 }
	  var self = this;
	  this.maintimeout=setTimeout(function(){self.timeloop();}, self.interwal);
	},
	zbut1: function(event) {this.MorphEffect('zdjecie1'); this.showPage('page1');},
    zbut1off: function(event) {this.MorphEffectoff('zdjecie1');},
    zbut2: function(event) {this.MorphEffect('zdjecie2');this.showPage('page2');},
    zbut2off: function(event) {this.MorphEffectoff('zdjecie2');},
    zbut3: function(event) {this.MorphEffect('zdjecie3');this.showPage('page3');},
    zbut3off: function(event) {this.MorphEffectoff('zdjecie3');},
    zbut4: function(event) {this.MorphEffect('zdjecie4');this.showPage('page4');},
    zbut4off: function(event) {this.MorphEffectoff('zdjecie4');},
    zbut5: function(event) {this.MorphEffect('zdjecie5');this.showPage('page5');},
    zbut5off: function(event) {this.MorphEffectoff('zdjecie5');},
eventcatcher: function() {  

for (var i=0;i<=this.iloscslajdow;i=i+1){
	var link="link"+i;
	$(link).observe('mouseover',  this.stopAnimation.bind(this));
	$(link).observe('mouseout',  this.startAnimation.bind(this));
	}
	
	if ($('zbut1') != undefined){$('zbut1').observe('mouseover', this.zbut1.bind(this));$('zbut1').observe('mouseout', this.zbut1off.bind(this));}
	if ($('zbut2') != undefined){$('zbut2').observe('mouseover', this.zbut2.bind(this));$('zbut2').observe('mouseout', this.zbut2off.bind(this));}
	if ($('zbut3') != undefined){$('zbut3').observe('mouseover', this.zbut3.bind(this));$('zbut3').observe('mouseout', this.zbut3off.bind(this));}
	if ($('zbut4') != undefined){$('zbut4').observe('mouseover', this.zbut4.bind(this));$('zbut4').observe('mouseout', this.zbut4off.bind(this));}
	if ($('zbut5') != undefined){$('zbut5').observe('mouseover', this.zbut5.bind(this));$('zbut5').observe('mouseout', this.zbut5off.bind(this));}

}
	 
};