
/*
  Tobb tartalom egy keretbe valo egymas melletti megjelenitesere es ha nem fer ki, ezeknek gorgeteser szolgal
  Az objektum az sComponent objektumbol van szarmaztatva 
*/

function sContentSlide(v){
  sComponent.call(this); 
  
  var _this = this;  /* a korbe hivast teszi lehetove olyan esetben, ha egy belso eljaras belsejeben az ot korbevevo objektumra szeretnenk hivatkkozni */
  
  this.path = v ? v : ""; /* nincs hasznalatban, helyesebben az erteke ujabban egy ures string (egy elozo verzio maradeka) */
  
  this._contents = new Array(); /* a megjelenitesre szant tartalmakat tarolo tomb */
  this._contentIndex = 0; /* az aktualis (a latjato) tartalom indexe a this._contents egy kulcsa */
  this._cintentLeft = 0;  /* A kedves IE miatt muszj kiszamolnunk a kovetkezo div poziciojat 
    Egeszsegesebbes egyszerubb lenne a display: inline-block es a keretnek a white-space: nowrap; csakhogy a valaha gyartott legroszabbul sikerult bongeszoje ezt nem ismerven, 
    helytelenul display: inline; specifikaciot kerne, ami viszont csak o benne menne, mert hatasara nem lehet meretezni tobbi bongeszobe a teget (es ez igy is van helyen hiszen ez a szabvany);
    
    Ezert a roszabb koztes position: absolute; left: [this._cintentLeft]px va'tozat
  */
  
  this.container = new sComponent("relative"); // az egymas meletti tartalmakat tartalmazo keret
  this.container.setPos(6, 155);
  this.container.setOverflow("hidden");
  
  this.contContainer = new sComponent("absolute");
  this.container.add(this.contContainer);
  
  this.add(this.container);
  
  /* a jobbra illetve balra mutati nyilak a tartalmak gorgetesere */
  
  var lb = new sImage( this.path+"selement/style/leftarrow.png");
  var rb = new sImage( this.path+"selement/style/rightarrow.png");
  
  lb.setPos(55, 130);
  rb.setRight(30);
  rb.setTop(24);
  
  this.add(lb);
  this.add(rb);
  
  this._contwidth = 0;
  this._contheight = 0;
  
  this.setBoxSize = function(w, h)
  {
    this._contwidth = w;
    this._contheight = h;
  }
  
  var sE = new sEffects(this.container); //ez az objektum egy meghatarozott tegen hajt vegre kulombozo effekteket
  
  var _scroll = true;
  
  lb.addEvent("click", function(){
    //ha meg nem ertunk a scrollterulet vegere
    if (_scroll){
      _scroll = false;
      if ( (_this.container.getScrollLeft() + _this.container.getWidth() ) < _this.container.getElement().scrollWidth ){
        var w = _this.contContainer.getChildren()[_this._contentIndex].getElement().offsetWidth+15;
        sE.clearAnimation(); //toroljuk az elozo effectsort
        _this._contentIndex++;
        sE.addEffect({type: "slr", n: w, step: 5}); //letrehozzuk az uj scroll animaciot az uj szelesseggel
        sE.addEffect({type: "func", func: function( ){ _scroll = true; } });
        sE.play(); // lejatszuk ezt az animaciot
      }else{ // ha elfogyott a croll, akkor keszitunk egy uj animaciot, ami gyorsan az elejere gorgeti a trtalmakat tartalmazo keretet
        var w = _this.container.getScrollLeft()+5;
        sE.clearAnimation();
        _this._contentIndex = 0;
        sE.addEffect({type: "slr", n: w, step: -40});
        sE.addEffect({type: "func", func: function( ){ _scroll = true; } });
        sE.play();
      }
    }
  } );
  
  // ugyan az mint az elozo ezemeny csak a masik gombra
  
  rb.addEvent("click", function(){
    if (_scroll){
      _scroll = false;
      if (_this.container.getScrollLeft() > 0){
        var w = _this.contContainer.getChildren()[_this._contentIndex].getElement().offsetWidth+15;
        sE.clearAnimation();
        _this._contentIndex--;
        sE.addEffect({type: "slr", n: w, step: -5});
        sE.addEffect({type: "func", func: function( ){ _scroll = true; } });
        sE.play();
        
      }else{
        var w = _this.container.getElement().scrollWidth+5;
        sE.clearAnimation();
        _this._contentIndex = _this.contContainer.getChildren().length-1;
        sE.addEffect({type: "slr", n: w, step: 40});
        sE.addEffect({type: "func", func: function( ){ _scroll = true; } });
        sE.play();
      }
    }
  });
  
  // hozza ad egy fajlban tarolt tratalmat a scrollterulethoz
  
  this.addcontent = function(uri){
    var cont = new sComponent;
    cont.setSize(this._contwidth, this._contheight);
    simpleLoader(uri, "", "POST", cont.getId(), true);
    cont.setLeft(this._contents.length*(cont.getWidth()+20) );
    this.contContainer.add(cont);
    var l = this._contents.length;
    cont.addEvent("click", function(){
      
    } );
    
    this._contents[this._contents.length] = uri;
  }
  
  // hozza ad egy divben letrehozott tartalmat a scrollterulethez
  this._addcontent = function(id){
    var cont = new sComponent;
    cont.setSize(this._contwidth, this._contheight);
    cont.getElement().appendChild(document.getElementById(id));
    cont.setLeft(this._contents.length*(cont.getWidth()+20) );
    this.contContainer.add(cont);
    var l = this._contents.length;
    cont.addEvent("click", function(){
      
    } );
    
    this._contents[this._contents.length] = 1;
  }
  
}

_mp = sExtend(sContentSlide, sComponent, "sContentSlide");

_mp.setWidth = function(v){
  this._element.style.width = v+"px";
  this._width = v;
  this.container.setWidth( v-(2* this.container.getLeft() - 100) );
}
