window.addEvent( 
	'domready',
	function()
	{
		//var FX = new Fx.Morph( fotosDiv, { duration : 200, transition : Fx.Transitions.Sine.easeOut } );
		var fotosDiv;
		fotosDiv = $( 'fotosDiv' );
        $( 'scroller' ).setStyle( 'width' , ( thumbList.length * 106 ) + 'px' );
        $( 'thumbnails' ).setStyle( 'width', ( thumbList.length * 106 ) + 'px');
		for( var i = 0; i < thumbList.length; i++ )
		{
			div = new Element( 'div', { 'class' : 'containerThumb' } ).inject( $( 'thumbnails' ) );
			new Element( 'img', { 'id':'F_' + i,'src' : thumbList[i],styles:{'cursor':'pointer'},events:{'click':function(){showWallpaperPic(this.id)}} } ).inject( div );
			new Element( 'a', { 'text' : '1024 x 768','href' : 'download.php?foto=' +thumbList[i].replace( "thumb", "1024" ) } ).inject( div );
			new Element( 'a', { 'text' : '800 x 600' ,'href' : 'download.php?foto=' +thumbList[i].replace( "thumb", "800" ) } ).inject( div );
		}
		if( fotosDiv )
		{
		showWallpaperPic( 0 );
		//var scroll = new Scroller( 'container',{ area:100,velocity : 1} );
		//scroll.start();
		}
	}
);

var showWallpaperPic = function( id )
{
	if( isNaN( id ) == true )
	{
		id = id.replace("F_", "").toInt();
	}
	$( 'fotosDiv' ).empty();
	var loadIMG = new Element( 'img', { 'src' : fotoList[ id ] } ).inject( $( 'fotosDiv' ) );
}

scrollStep  =   2;
scrollSpeed = 100;
timerLeft   =   "";
timerRight  =   "";

function scrollDivRight (id)
{
		if (document.getElementById(id).style.left=="")
		{
				document.getElementById(id).style.left=0;
		}
		clearTimeout( timerRight );
		valorInicio=parseInt(document.getElementById(id).style.left);
		if ( (valorInicio-10) > document.getElementById(id).offsetParent.offsetWidth-document.getElementById(id).offsetWidth)
				//alert (document.getElementById("escaparateContenido").offsetWidth);
		{
				document.getElementById(id).style.left=(valorInicio-10)+"px";
		}
		timerRight=setTimeout( "scrollDivRight('" + id + "')", scrollSpeed );

}
function addListener(element, type, expression, bubbling)
{
		bubbling = bubbling || false;
		if(window.addEventListener) // Standard
		{ 
				element.addEventListener(type, expression, bubbling);
				return true;
		}
		else if(window.attachEvent) // IE
		{
				element.attachEvent('on' + type, expression);
				return true;
		}
		else
				return false;
}

function scrollDivLeft (id)
{
		if (document.getElementById(id).style.left=="")
		{
				document.getElementById(id).style.left=0;
		}
		clearTimeout( timerRight );
		valorInicio=parseInt(document.getElementById(id).style.left);
		if ( (valorInicio+10)<0)
				document.getElementById(id).style.left=(valorInicio+10)+"px";
		else
		{
				document.getElementById(id).style.left=0+"px";
		}
		timerRight=setTimeout( "scrollDivLeft('" + id + "')", scrollSpeed );

}
/*function scrollDivRight( id )
  {
  clearTimeout( timerLeft );
  document.getElementById( id ).scrollLeft -= scrollStep;
  timerLeft=setTimeout( "scrollDivRight('" + id + "')", 2 );
  }*/
function toRight( id )
{
		document.getElementById( id ).scrollLeft = document.getElementById( id ).scrollWidth;
}
function stopMe()
{
		clearTimeout( timerRight );
		clearTimeout( timerLeft );
}


