var mScroll
var speedScroll=1
var maxWidth
var objMargin//
var objContainer //container
var objImages//
var mWidth
var cWidth
var iWidth

var xValue = 1

var intLeft, intRight;
var lTime, rTime

var bScrollLeft, bScrollRight

function scroll(){
    if ( bScrollLeft ){
        if ( parseInt( objContainer.style.left) > ( mWidth - cWidth ) ){
        	intLeft = parseInt( objContainer.style.left ) - xValue 
            objContainer.style.left=intLeft + 'px'
        }
    }
    if ( bScrollRight ){
        if ( parseInt( objContainer.style.left) < 0 ){
           intLeft = parseInt( objContainer.style.left ) + xValue 
           objContainer.style.left= intLeft+ 'px'
        }
    }
    top.intLeft = intLeft
}


function leftright(e){
    var x
    
    x3 = mWidth /3
    lMargin = getLeft("objMargin");
    
    if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		x = e.pageX;
	}
	else if (e.clientX || e.clientY) {
		x = e.clientX;
	}

	x = x - lMargin
	if ( x < x3 ){
	   bScrollLeft = false
	   bScrollRight = true
  	   xValue =  parseInt( ( x3 - x ) / x3  * 10 )
	}
	if ( x >  mWidth - x3 ){ 
	   bScrollLeft = true
	   bScrollRight = false
	   
	   xValue =  parseInt( ( x - 2*x3 ) / x3 * 10 )

	}
		
}
function startScroll(){
   myScroll=setInterval('scroll()',speedScroll)
}

function endScroll(){
   // clearInterval(myScroll)
   bScrollLeft = false;
   bScrollRight = false;
}

var arrImages = new Array();


function addItem( caption, src, link ){
    this.caption = caption
    this.src= src
    this.link = link
    this.image = new Image();
    this.image.src = src 
    this.left = 0
    this.width =0
}

function addItems(caption, src, link){
	arrImages[ arrImages.length ] = new addItem( caption, src, link )
}
function imgClick( aLink ){
	createCookie('left', intLeft, 1);
	top.window.location = aLink;
}
function showImages(){

   for( i = 0; i < arrImages.length; i ++ )
   { 
        document.write('<a onclick = \'imgClick("'+ arrImages[i].link +'")\' target="_self" style="cursor:pointer">',
        '<img space="0" hspace="0" vspace="0" border="0" style="top:0;"',
        ' src="' + arrImages[i].src + '" alt="'+arrImages[i].caption+'" height="100" align="absmiddle" onmouseout="" onmouseover="" onclick="endScroll()"></a>')
   }
}


function init(){
   bScrollLeft = false
   bScrollRight = false 
   objMargin = getElement('objMargin');
   mWidth = objMargin.offsetWidth; 
   
   objContainer = getElement('objContainer');
   intLeft = readCookie( "left" )
   objContainer.style.left = intLeft + "px";
   cWidth = objContainer.offsetWidth;
   objContainer.onmousemove = function(e){
       leftright(e);
   }
   objContainer.onmouseout=function(e){
       endScroll();
   }
   objImages = getElement('objImages');
   iWidth = objImages.offsetWidth;
   startScroll() 
}

window.onload=init



