var myWindow = Class.create();
myWindow.prototype = {
   initialize: function() {
    //this.width      = 375;
     this.openHeight = -1;  // velikost okna ko je odprto. preveri po dolzini html code oz. vrednosti vnešene v Open() 
	  this.openWidth  = -1;
	  this.stej       = 0;   // steje loope
	  this.ms         = 10;  // hitrost v milisec..
	  this.vecajZA    = 2;   // veca za X px;
	  this.HTML       = "";
	  this.TIMEOUT    = 0;
	  
	  this.zapri      = -1;  // preveri med zapiranjem za innerHTML
	  
	  /* CHECK WINDOW */
	  this.ret       = -1;
	  this.timer     = -1;
	  
	  this.varOsNarocilo = -1;
	  this.varOsChk      = 0;
	  
	  this.posMemX = 0;
	  this.posMemY = 0;
	  //this.strMember = ""; // spomin za katere skupine spadajo skupaj.. da ve kdaj mora delovati funkcija in kdaj ne
	  /* CHECK WINDOW */
   },
   
   Close: function() {
	 W.ret   = -1;
	 W.stej  = 0;
	 W.zapri = -1;
	 
	 W.varOsNarocilo = -1;
	 W.varOsChk      = 0;
	 clearTimeout(W.timer);
	 $('scrlDown').style.visibility = 'hidden';
   },
   
   genCommand: function(id, posid, w, t, Cls, x, y, bgc, h) {
      return Cls+".Open("+Cls+".HTML, '"+id+"', '"+posid+"', '"+w+"', "+t+", '"+Cls+"', "+x+", "+y+", '"+bgc+"', "+h+");";
   },
   
   Open: function(html, id, posid, w, timeout, cls, x, y, bgc, h) { // if w == -1; width = auto!; else width = w; !
	  if(this.ret == 0 && this.TIMEOUT > 0) {}
	  else if(this.varOsChk == 1) {}
	  else {
	  
	  if(h > -1) this.openHeight = h;
	  this.HTML = html;
	  
	  if((this.TIMEOUT == 0) && (timeout > 0) && (timeout != 'undefined')) {
	     this.TIMEOUT = timeout;
		 //alert(timeout);
	  }
	  var wID   = $(id);
 
     if(posid != 0) {	  
	    var pID   = []; pID = Position.cumulativeOffset($(posid));
       wID.style.top  = (pID[1]+x)+'px';
	    wID.style.left = (pID[0]+y)+'px';
	  }
	  else {
 	    wID.style.top  = x+'px';
	    wID.style.left = y+'px';
	  }
	  	  
	  wID.style.background = bgc;
	  wID.style.color      = '#ffffff';
	  
	  if(w == -1) // dobimo auto dolzino diva
		 this.openWidth  = Element.getDimensions(wID).width;
	  else
		 this.openWidth  = w; // dolzina nastavljena po nasi meri!
	  
	  if(this.zapri == -1) { // start zapri
 	  if(this.openHeight == -1) {
		 wID.style.width = this.openWidth;
		 wID.innerHTML = this.HTML;
		 
		 this.openHeight = Element.getHeight(wID);//this.getDim(id, 'height');  // sirina okna*/
		
		 //alert(this.openHeight);
		 //alert(Element.getStyle(id, 'height'));
								
         wID.innerHTML = "";
		 setTimeout(this.genCommand(id, posid, w, 0, cls, x, y, bgc, h), this.ms);
		 //W.ret = 0; //return 1; // window se odpira
	  }
	  else {
	     var c = (this.stej*this.vecajZA);
	     if(c < this.openHeight) {
			wID.style.height = c+'px';
			wID.style.width  = this.openWidth+'px';
			wID.style.visibility = 'visible';
		    setTimeout(this.genCommand(id, posid, w, 0, cls, x, y, bgc, h), this.ms);
			W.ret = 1; //return 1; // window se odpira
		 }
		 else {
            wID.innerHTML = this.HTML;
			wID.style.width  = this.openWidth+'px';
			wID.style.visibility = 'visible';
			this.zapri = 0;
			this.stej  = 0;
			
			W.ret = 0; // window je odprt
			
			if(this.TIMEOUT > 0) {
				this.timer = setTimeout("W.TIMEOUT=0;"+this.genCommand(id, posid, w, 0, cls, x, y, bgc, h), this.TIMEOUT);
			}
			if(this.varOsNarocilo == 0) { // nastavimo na 0 v sm-f.js checkOrderSend()
			  this.varOsChk = 1;
			}
		 }
		 
		 this.stej++;
	  }
	  } // end zapri
	  else {
	     //alert("zapiram okno");
		 var c = (this.openHeight-(this.stej*this.vecajZA));
		 if(c >= 0) {
		    wID.innerHTML        = "";
		    wID.style.width      = this.openWidth+'px';
		    wID.style.height     = c+'px';
		    wID.style.visibility = 'visible';
			setTimeout(this.genCommand(id, posid, w, 0, cls, x, y, bgc, h), this.ms);
		    this.stej++;
		 }
		 else {
		    wID.style.visibility = 'hidden';
			this.stej  = 0;
			this.zapri = -1;
			// ZAPRTO*/
			W.ret = -1;
		 }
	  }
   }
   }
}

