var width = window.innerWidth;
var photorollWidth = 0;
var adjustedWindow = width-569;   
var height = 500;


function imagehandling(){
	setTimeout("reveal()", 500);
   	if(typeof(window.innerWidth) == 'number'){
		width = window.innerWidth;
		adjustedWindow = width-569;
	} else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )){
		width = document.documentElement.clientWidth;
		adjustedWindow = width-569;
	}
   
	
	$('#photoroll .box:first-child').load(function(){
		if($(this).height()<500){
			height = 500;
		} else {
			height = $(this).height();
		}
	});           
	$('#window').css({width: adjustedWindow+'px', height: height+26+'px'});
	window.onresize = function(){
		if(typeof(window.innerWidth) == 'number'){
			width = window.innerWidth;
			adjustedWindow = width-569;
		} else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )){
			width = document.documentElement.clientWidth;
			adjustedWindow = width-569;
		}
		if($('#window').hasClass('withtext')){
			adjustedWindow = width-305;
		} else {
			adjustedWindow = width;
		}
		$('#window, .jspContainer').css({width: adjustedWindow+'px', height: height+26+'px'});
		//$('.jspContainer').css('width', adjustedWindow+'px');  

	}
	$('#photoroll .box').each(function(){ 
		var current = $(this).find('img');
		current.attr('onload','javascript:reveal();');
		var oPhotoHeight = current.height();
		var oPhotoWidth = current.width();
		var aPhotoWidth = (oPhotoWidth/height)*oPhotoHeight;   
		current.css({height: '500px', width: aPhotoWidth});
		photorollWidth = photorollWidth + aPhotoWidth + 6;
		$('#photoroll').css({width: photorollWidth+'px',height: '500px'});
		$('#photoroll').parent('#window').jScrollPane({
			autoReinitialise: true,
			horizontalDragMinWidth: '50',
			horizontalDragMaxWidth: '50'
		});
		 
	});
	
	if(!$.browser.msie){	
		$('.jspContainer').live('mousemove', function(){
				setTimeout(function(){$(window).trigger('scroll');}, 10);
	    });
	}

	//reveal();
}
    
function reveal(){ 
	$('#loading').hide();
	$("#photoroll img").fadeIn();
}

