function loadPhoto(el){
	var big = document.getElementById("big_photo");
	if(big){
		big.src = el.src.replace("-small", "");
	}
}
var aPreloadedPhotos=new Array();
var Photos = {
	photos: [],
	cur_photo: 1,
	init: function(photos_array, photo_id, prev_id, next_id, paging_id, current_photos, count_photos, no_hide_paging){
		Photos.photos = photos_array;
		Photos.current_photos 	= document.getElementById(current_photos);
		Photos.count_photos		= document.getElementById(count_photos);
		Photos.photo	= document.getElementById(photo_id);
		Photos.prev		= document.getElementById(prev_id);
		Photos.next		= document.getElementById(next_id);
		Photos.paging	= document.getElementById(paging_id);
		
		Photos.count_photos.innerHTML = photos_array.length;

		//Photos.prev.onclick = "";
		//Photos.next.onclick = "";
		// loader code starting here 
		img = document.createElement('img');
		img.setAttribute('src', '/loading.gif');
		img.src = '/loading.gif';
		img.setAttribute('id', 'loader-image');
		img.setAttribute('width', '220');
		img.setAttribute('height', '220');
		img.style.display = 'none';
		Photos.loader_image = Photos.photo.parentNode.appendChild(img);
		Photos.interval = null;
		document.getElementById('previous').style.visibility='hidden';
		
		if(!no_hide_paging && Photos.photo && Photos.prev && Photos.next && Photos.paging){
			Photos.paging.onmouseover = function(){
				Photos.no_hide = true;
			}
			Photos.paging.onmouseout = function(){
				Photos.no_hide = false;
				Photos.paging.style.display = "";
			}
			Photos.photo.onmouseover = function(){
				Photos.paging.style.display = "";
				if(Photos.timeout){
					clearTimeout(Photos.timeout);
					Photos.timeout = null;
				}
			}
			Photos.photo.onmouseout = function(){
				Photos.timeout = setTimeout(function(){
					if(!Photos.no_hide){
						Photos.paging.style.display = "none";
					}
				}, 700);
			}
			
		}else{
			Photos.paging.style.display = "";
		}
		setTimeout('preloadPhotos()',1000);
	},
	prevPhoto: function(){
		if(Photos.cur_photo > 1){
			Photos.cur_photo--;
			Photos.photo.src = "images/photos/" + Photos.photos[Photos.cur_photo-1];
			Photos.updateImage("images/photos/" + Photos.photos[Photos.cur_photo-1]);
			Photos.current_photos.innerHTML = Photos.cur_photo;
			document.getElementById('next').style.visibility='';
		}  
		if(Photos.cur_photo <= 1){
			
			document.getElementById('previous').style.visibility='hidden';
		}
	},
	nextPhoto: function(){
		if(Photos.cur_photo < Photos.photos.length){
			Photos.cur_photo++;
			Photos.photo.src = "images/photos/" + Photos.photos[Photos.cur_photo-1];
			Photos.updateImage("images/photos/" + Photos.photos[Photos.cur_photo-1]);
			Photos.current_photos.innerHTML = Photos.cur_photo;
			document.getElementById('previous').style.visibility='';
		}
		if(Photos.cur_photo >= Photos.photos.length){
			
			document.getElementById('next').style.visibility='hidden';
		}
	}, updateImage:function (url){
		// following is ff fix, to make him understand that image is new
		Photos.prel_img = document.createElement('img');
		Photos.prel_img.src = url;
		Photos.updateLoader();
	},updateLoader: function(){
		if(Photos.isImageLoaded()){
			Photos.loader_image.style.display = 'none';	
			Photos.photo.style.display = 'block';
			clearInterval(Photos.interval);
			Photos.interval = null;
		}else {
			if(!Photos.interval){
				Photos.interval = setInterval(function(){
					Photos.updateLoader();
				}, 500);
				
				Photos.loader_image.style.display = 'block';
				Photos.photo.style.display = 'none';
			}
			
		}
			
	}, isImageLoaded: function () {
		img =  Photos.prel_img;
	    if (!img.complete) {
	        return false;
	    }
	    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
	        return false;
	    }
	    return true;
	}
}

function preloadPhotos() {
		iLen=Photos.photos.length;
		for (i=0;i<iLen;i++) {
			aPreloadedPhotos[i]=new Image;
			aPreloadedPhotos[i].src="images/photos/"+Photos.photos[i];
		}

}