
var id_curr=0;
var id_prev=0;
var id_next=1;
var stop = 0;
var objImagePreloader = new Image();
var gal_delay = 4000;



function changeImage(id) {
	
	
	if (iTimer) {
		clearTimeout(iTimer);
		iTimer = 0;
	}
	
	
	if(typeof(images_arr[id]) !== 'undefined') {
	
		id_curr=id;
		id_prev=images_arr[id].prev;
		id_next=images_arr[id].next;
		

		objImagePreloader.onload = function() {

			jQuery('#cont_img').css('background-image','url('+images_arr[id].photo+')');


			jQuery('#big_img').animate({ opacity: '0' }, 1000, function(){

				jQuery('#big_img').attr('src',images_arr[id].photo);
					jQuery('#big_img').animate({ opacity: '1' }, 100, function(){
						//jQuery('a.work_box').lightBox();

					});
			});
			objImagePreloader.onload=function(){};
			
			
			if (stop=='0') iTimer = setTimeout("getNext()", gal_delay);
		}
		
	
		objImagePreloader.src = images_arr[id].photo;
		/*jQuery('#pr_main_img').attr('href',images_arr[id].photo_big);
		jQuery('#pr_main_img').attr('title',images_arr[id].title);
		*/
				
		if (id_prev==0&&id_curr==0) jQuery('a.pr-prev').addClass('pr-prev-disabled');
		else jQuery('a.pr-prev').removeClass('pr-prev-disabled');
		
		if (id_next==0) jQuery('a.pr-next').addClass('pr-next-disabled'); 
		else jQuery('a.pr-next').removeClass('pr-next-disabled');
	}
		
	
}

function getPrev(action){
	getImage(id_prev,action);
}

function getNext(action){
	getImage(id_next,action);
}

function getImage(id,action){
	if(action==undefined){action=0;
	}else if (action=='stop'){
		stop=1;
	}
	
	changeImage(id);
	
}

jQuery(document).ready(function(){
	iTimer = setTimeout("getNext()", gal_delay);
});
