//Bu Önemli
function AttachEventHScrollerDiv(obj, eventName, eventHandler) {
  if( obj ) {
     if(eventName.substring(0, 2) == 'on') {
 	    eventName = eventName.substring(2,eventName.length);
	 }
     if(obj.attachEvent){
        obj.attachEvent('on'+ eventName, eventHandler);
     } 
     else 
     if( obj.addEventListener){
        obj.addEventListener(eventName, eventHandler, false);  
     }
  }
};

function HScrollerDiv( id , delay , width , count , tempstyle , toolbar , showover , mouseoverstop ) {
  this.delay = delay;
  this.idno = id;
  this.genislik = width;
  this.totalitem = count;
  this.tempstyle = tempstyle;
  this.toolbar = toolbar;
  this.showover = showover;
  this.mouseoverstop = mouseoverstop;
  this.mover = 0;
  this.scrolling = 0;
  var scrollerdivinstance=this;
  AttachEventHScrollerDiv( window , 'onload' ,function() {scrollerdivinstance.initialize() } );
}


HScrollerDiv.prototype.AnimateHeaderShow = function() {
  var scrollerdivinstance=this;
  this.headeropacity = 70;
  this.header.style.opacity = this.headeropacity / 100;
  this.header.style.filter = 'alpha(opacity=' + this.headeropacity + ')';
  this.timeheaderid = null;
  this.text.style.visibility="visible";
}
HScrollerDiv.prototype.AnimateHeaderHide = function() {
  var scrollerdivinstance=this;
  this.headeropacity = 0;
  this.header.style.opacity = this.headeropacity / 100;
  this.header.style.filter = 'alpha(opacity=' + this.headeropacity + ')';
  this.timeheaderid = null;
  this.text.style.visibility="hidden";
  this.header.style.visibility="hidden";
}
HScrollerDiv.prototype.mouseover = function() {
   this.mover = 1;
   if( this.toolbar == 0 )
      return;
   if( this.showover == 1 )
      return;
   var scrollerdivinstance=this;
   if( this.timeheaderid != null )
     clearTimeout( this.timeheaderid );
   this.header.style.visibility="visible";	 
   this.timeheaderid = setTimeout( function(){scrollerdivinstance.AnimateHeaderShow()}, 0 );   
}
HScrollerDiv.prototype.mouseout = function() {
   var scrollerdivinstance=this;
   this.mover = 0;
   if( this.mouseoverstop == 1 && this.mover == 0 && this.scrolling == 0 ) {
	  if( this.timeid != null ) clearTimeout(this.timeid );
      this.timeid = setTimeout( function(){scrollerdivinstance.Animate()}, this.delay );
   }

   if( this.toolbar == 0 ) return;
   if( this.showover == 1 ) return;
   
   if( this.timeheaderid != null )
      clearTimeout( this.timeheaderid );
   this.timeheaderid = setTimeout( function(){scrollerdivinstance.AnimateHeaderHide()}, 2000 );   
}
HScrollerDiv.prototype.initialize = function() {
  var scrollerdivinstance=this;
  this.curindex = 0;
  this.headeropacity = 0;
  this.frame = document.getElementById(this.idno+"_frame");
  this.maindiv = document.getElementById(this.idno);
  this.header = document.getElementById(this.idno+"_header");
  this.text = document.getElementById(this.idno+"_text");
  this.texttitle = document.getElementById(this.idno+"_texttitle");
  if( this.texttitle != null ) {
	 this.texttitle.innerHTML = document.getElementById(this.idno+"_itemtitle1").value;  
  }
  if( this.toolbar == 1 ) {
      if( this.showover == 1 ) {	  
		 this.header.style.visibility="visible";
	     this.text.style.visibility="visible";
         this.headeropacity = 70;
         this.header.style.opacity = this.headeropacity / 100;
         this.header.style.filter = 'alpha(opacity=' + this.headeropacity + ')';
	  }
  }
  AttachEventHScrollerDiv( this.frame , 'onmouseover' ,function() {scrollerdivinstance.mouseover() } );
  AttachEventHScrollerDiv( this.frame , 'onmouseout' ,function() {scrollerdivinstance.mouseout() } );
  
  btn = document.getElementById(this.idno+"_navbutton1");
  btn.className = "slideshow_"+this.tempstyle+"_numberselect";
  for( sayac = 1; sayac <= this.totalitem ; sayac++ ) {
	  btn = document.getElementById(this.idno+"_navbutton"+sayac);
	  if( btn != null ) {
		 btn["indebtn"] = sayac;
		 AttachEventHScrollerDiv( btn , 'onclick' ,function(event) {scrollerdivinstance.onclickbutton(event); } ); 
	  }
  }
  this.header.style.top = "-40px";
  this.text.style.top = "-80px";
  this.timeid = setTimeout( function(){scrollerdivinstance.Animate()}, this.delay );
}

HScrollerDiv.prototype.onclickbutton = function( e ) {
	var scrollerdivinstance=this;
    targget = null;
	if(!e) e = window.event;
	if (e.target) 
	   targget = e.target;
	else 
	if(e.srcElement) 
	  targget = e.srcElement;
	if (targget.nodeType == 3) // defeat Safari bug
		targget = targget.parentNode;

    if( targget != null ) {
	   if( this.timeid != null ) {
	      clearTimeout( this.timeid );
		  this.timeid = null;
	   }
	   btn = document.getElementById(this.idno+"_navbutton"+(this.curindex+1));
	   btn.className = "slideshow_"+this.tempstyle+"_number";
	   this.curindex=(targget["indebtn"] - 1); 
	   if( this.curindex >= this.totalitem )
	      this.curindex = 0;
	 
       if( this.texttitle != null ) {
	      this.texttitle.innerHTML = document.getElementById(this.idno+"_itemtitle"+(this.curindex+1)).value;  
       }
	   btn = document.getElementById(this.idno+"_navbutton"+(this.curindex+1));
	   btn.className = "slideshow_"+this.tempstyle+"_numberselect";
	   this.maindiv.scrollLeft = ( this.curindex * this.genislik ); 
	   this.timeid = setTimeout( function(){scrollerdivinstance.Animate()}, this.delay );  
	}
}

HScrollerDiv.prototype.Animate = function() {
  this.timeid = null;
  this.sayac = 0;
  this.adim = 1;
  var scrollerdivinstance=this;
  if( this.mouseoverstop == 1 && this.mover == 1 ) {
	 return; 
  }
  this.scrolling = 1;
  this.timeid = setTimeout( function(){scrollerdivinstance.AnimateLoop()}, 0 );
}

HScrollerDiv.prototype.AnimateLoop = function() {
  var scrollerdivinstance=this;	
  this.adim += .7;
  
  if( this.sayac < this.genislik ) {
     this.maindiv.scrollLeft += this.adim;	 
	 this.sayac += this.adim;
     this.timeid = setTimeout( function(){scrollerdivinstance.AnimateLoop()}, 0 );
  }
  else {
	 btn = document.getElementById(this.idno+"_navbutton"+(this.curindex+1));
	 btn.className = "slideshow_"+this.tempstyle+"_number";
	 this.curindex++; 
	 if( this.curindex >= this.totalitem )
	    this.curindex = 0;
	 
     if( this.texttitle != null ) {
	    this.texttitle.innerHTML = document.getElementById(this.idno+"_itemtitle"+(this.curindex+1)).value;  
     }
	 btn = document.getElementById(this.idno+"_navbutton"+(this.curindex+1));
	 btn.className = "slideshow_"+this.tempstyle+"_numberselect";
	 
 	 this.maindiv.scrollLeft = ( this.curindex * this.genislik ); 
	 this.scrolling = 0;
     if( this.mouseoverstop == 1 && this.mover == 1 )
	    return; 
	 this.timeid = setTimeout( function(){scrollerdivinstance.Animate()}, this.delay );  
	 
  }
}




