function iGallery(){  
	
	this.IE = document.all?true:false; 
	this.maxW = 0;
	this.maxH = 0;                     
	this.getWindowSize = getWindowSize;
	this.getWindowSize(); 
	this.fx = null;
	
	this.slider = $('imagenav');
	this.figure = $('figure');
   		
	this.slider.onmouseover = startScrollSlider;
	this.slider.onmouseout = stopScrollSlider;
	this.onStageResize = onStageResize 
	 
   
	document.direction = 'rigth';
	document.tm = setTimeout( "autoMove()", 1000 );
	
}    


function getWindowSize(){      	
	if( typeof( window.innerWidth ) == 'number' ) {
   		this.maxW = window.innerWidth;
   	    this.maxH = window.innerHeight;
   	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
   		/* IE 6+ in 'standards compliant mode' */
   	   this.maxW = document.documentElement.clientWidth;
   	   this.maxH = document.documentElement.clientHeight;
   	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   	    /* IE 4 compatible */
   	    this.maxW = document.body.clientWidth;
   	    this.maxH = document.body.clientHeight;
    }
} 

function onStageResize(){  
   this.getWindowSize(); 
   if($('figure').style.visibility != 'hidden' ) this.slider.style.width = this.maxW-520+'px';
   if($('figure').style.visibility == 'hidden' ) this.slider.style.width = '100%';  
   $('thumbrow').style.marginLeft = 0;    
}      


function startScrollSlider(){   
	if(document.slide != undefined) document.slide.cancel()   
	
	var thumbRowWidth = 0;
	var thumbs = $('thumbrow').getElements('img');
	for(var i=0; i<thumbs.length; i++){
		thumbRowWidth += thumbs[i].offsetWidth;
	}   
    $('thumbrow').style.width = thumbRowWidth+'px';

	document.onmousemove = scrolling;      
	document.autoScroll = true;
} 

function stopScrollSlider(){
	document.onmousemove = null;     
	
	if($('figure').style.visibility != 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth; 
	if($('figure').style.visibility == 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth;        
	                          
	document.direction = 'rigth';
	clearTimeout(document.tm)
	document.tm = setTimeout( "autoMove()", 1500 );    
	
} 
 
function autoMove(){  
	
	var thumbRowWidth = 0;
	var thumbs = $('thumbrow').getElements('img');
	for(var i=0; i<thumbs.length; i++){
		thumbRowWidth += thumbs[i].offsetWidth;
	}   
    $('thumbrow').style.width = thumbRowWidth+'px';
	
	if(document.slide != undefined) document.slide.cancel()   
	if($('figure').style.visibility != 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth; 
	if($('figure').style.visibility == 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth;
	
	document.slide = new Fx.Tween($('thumbrow'), {duration: dif*40, wait:false,  transition: Fx.Transitions.linear, onComplete:function(){reDir()}}); 
	if(dif > 0 && document.direction == 'rigth')	document.slide.start('marginLeft', -dif);      
	if(dif > 0 && document.direction == 'left')	document.slide.start('marginLeft', 0);      
	
	
}
  
function reDir(){      
	document.direction = document.direction == 'rigth' ? 'left' : 'rigth'; 
	autoMove()   	
}

function scrolling(e) {    
	if (window.gallery.IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
   
   	var proz = 100/$('imagenav').offsetWidth*(tempX-50);   
	if($('figure').style.visibility != 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth; 
	if($('figure').style.visibility == 'hidden' ) var dif = $('thumbrow').offsetWidth - $('imagenav').offsetWidth;
	
	if(dif > 0){
	  $('thumbrow').style.marginLeft = -dif/100*proz+'px';  
	}
}
