 preLoad();
 var $newsid;
 var $newtid;
 var slideTime = randomFromTo(5000, 6000); // 5-6 seconds
 var timer = setTimeout(function(){ tick(); }, slideTime);
 var stop = false;
 
 function tick()
 {
 	if (!stop)
 	{
	 	var old = $('.screen .on');
	 	$(old).fadeOut(1000, function() 
	 	{
	 		next();
	 		update();
	 		var newImg = $('.screen .on');
	 		$(newImg).fadeOut(0);
	 		$(newImg).fadeIn(1000);
	 		
	 		slideTime = randomFromTo(5000, 6000); // 4-7 seconds
		 	timer = setTimeout(function(){ tick(); }, slideTime);
	 	});
 	}
 }

 $(document).ready(function() {
 
	//setMainPicturesSize()
 	ieBandaids();
 	protectImages();
	initNavigation();	
	
	$('.prev,.next,.slide,.thumb').click(function() {
		
		// stop the Slide Show if userinput
		//clearTimeout(timer);
		stop = true;
								   
		switch( $(this).attr('class') )
		{
			case 'prev':
				prev();
				break;
			case 'next':
				slide();
				break;
			case 'slide':
				slide();
				//slide();
				break;
			case 'thumb': // falls through for both cases
			case 'thumb portrait':
				
				if ( $(this).hasClass('on') ) {/* do nothing */} else {
			
					$id = $(this).attr('id');
					$id = $id.substring(1,3);
					$id = parseInt($id);
					
					$newsid = $id;
					$newtid = $id;
				}
				break;
		}
		
		update();
										   
	});// click ends here
	
	$('a#loc').click(function() {
							  
			$('.slide').parent('li').removeClass('on');
			$('#s'+23).parent('li').addClass('on');
			
			$('.thumb').removeClass('on');
			$('#t'+23).addClass('on');
			
			$('.thumbs ul').css('margin-left','-1344px');
			
	  });
	
}); //doc ready ends here 

// modified, should work better now
function preloadImages(images) {
    if (document.images) {
        var imageObj;
        for(i=0; i<images.length; i++) {
        	imageObj = new Image();
            imageObj.src=images[i];
        }
    }
}

// not needed anymore
preloadImages([
	"imgs/slide-spinner.gif",
	"imgs/thumb-spinner.gif",
	"imgs/logo.png",
	"imgs/html-bg.png",
	"imgs/prev.png",
	"imgs/next.png",
	"imgs/portafolio/1.JPG"
]);

