function slideImageTo(number){
	if(number < 0){
		$("div[class='mask']")[0].style.left = ($("div.image").length-1) * -853 + 'px';
	}	else if($("div.image").length > number){
		$("div[class='mask']")[0].style.left = -number * 853 + 'px';
	}	else	{
		$("div[class='mask']")[0].style.left = '0px';
	}
	
}
function jumpToAnchor(){
	//images
	var hash = (window.location.hash+'').substr(1,(window.location.hash+'').length-1);
	if(!hash || hash.length == 0){
		//alert('no hash');
		return;
	}
	$("div[class='image']").each(function(index,img){
		if(img.getAttribute('hash') == hash){
			slideImageTo(index)
		}
		//img.removeAttribute('id');
		//window.location.hash = '#';
	});
}

function rearrangeCards(){
	var hash = (window.location.hash+'').substr(1,(window.location.hash+'').length-1);
	if(!hash || hash.length == 0){
		//alert('no hash');
		return;
	}
	
	$("#"+hash+"").insertAfter($('dl.heading'));
	//$("div[id='"+hash+"'][class='card']").insertAfter($('dl.heading'));
	
}

function insertJumpers(){
	if($("div.caption ul.navigation").length > 1){
		$("div.caption ul.navigation").each(function(index,ul){
			$(this).append('<li><a href="javascript:slideImageTo('+(index-1)+')">&lt;</a></li>');
			//$(this).append('<li><a href="javascript:slideImageTo('+(index+1)+')">&gt;</a></li>');
		});
	}
}

function hideNextImageWhenCurrentImageIsTooLarge(){
	var images = $("div.mask img");
	if(images.length > 0){
		//images.style.display = 'none';
	}
	if(images.length > 1 && images[0].width){
		var images = $("div.mask img");
		/*if(images.length > 1 && images[0].width < 659){
			images[1].style.left = '756px';
		}	else	{
			images[1].style.left = (97 + images[0].width) + 'px';
		}*/
		images[1].style.left = (120 + images[0].width) + 'px';
	}	else	{
		window.setTimeout("hideNextImageWhenCurrentImageIsTooLarge()",200);
	}
}

function countCompletedImages()  {
   var theImagesCompleted = 0;
   var theImagesIncomplete = document.images.length
   for(var theIndex = 0; theIndex < document.images.length; theIndex++)  {
      //return maximum if browser does not support attribute
      //and update screen size
      //this applies to safari 1.3 for example
      if(document.images[theIndex].complete == undefined)   {
         return document.images.length;
      }  
      if(document.images[theIndex].complete == true)   {
         theImagesCompleted++;
      }
   }
   return theImagesCompleted;
   //return theImagesCompleted;
}

function hideImagesUntilTheyAreLoaded(){
	if(countCompletedImages() < document.images.length){
		window.setTimeout("hideImagesUntilTheyAreLoaded();",200);
	}	else	{
		window.setTimeout('showImages();',400);
	}
}

function showImages(){
	//hideNextImageWhenCurrentImageIsTooLarge();
	$('img').each(function(index,img){
		//img.style.display = 'block';
		img.style.opacity = 1;
	})
}

/*
$(document).ready(function() {
	
	$('img').each(function(index,img){
		//img.style.display = 'none';
		img.style.opacity = 0.01;
	})
	
	hideImagesUntilTheyAreLoaded();
	//jumpToAnchor();
	//insertJumpers();
	//rearrangeCards();
	
});
*/
/*$(function(){
	hideNextImageWhenCurrentImageIsTooLarge();
});*/


