// FUNCTIONS

	actual_pic = 0;
	function next_picture(){
		if(actual_pic < pics_total - 1){
			actual_pic++;
		}else{
			actual_pic = 0;	
		}
		picture = pics[actual_pic];	
		show_pic(actual_pic,"images/user/"+picture);
	}
	
	
	function show_pic(number,image){
		if(document.getElementById("gallery_image").src != image.src){
			$('#picture_wrapper').fadeOut('slow', function() {
				document.getElementById("gallery_image").src = image;	
				//$('#picture_wrapper').fadeIn('slow', function() {});
				load_picture(image);
				actual_pic = number ;
			});
			$('#gallery_text_wrapper').fadeOut('slow', function() {
				document.getElementById("gallery_title").innerHTML = pics_titles[number];
				document.getElementById("gallery_text").innerHTML = pics_texts[number];
				//$('#gallery_text_wrapper').fadeIn('slow', function() {});
			});	
		}
	}
	
	tempimage='';
	function load_picture(img){
			tempimage = new Image ;
			tempimage.src = img;
			timer = setTimeout( 'loading()', 100 ) ;
	}
	
	function loading(){
		if(tempimage.complete ){ 
			//document.getElementById("slide_image").src = 'images/user/' + images_array[actual_image];
			$('#picture_wrapper').fadeIn('slow', function() {});
			$('#gallery_text_wrapper').fadeIn('slow', function() {});
			clearTimeout(timer);
		}else{
			timer = setTimeout( 'loading()', 100 ) ;	
		}
	}
	
	
	// HOME SLIDE SHOW
	actual_image = 0;
	function slide_show(){
			if(actual_image < images_total - 1){
				actual_image = actual_image + 1;;
			}else{
				actual_image = 0;	
			}
			$('#slide_image').fadeOut('slow', function() {
				document.getElementById("slide_image").src = 'images/user/' + images_array[actual_image];
				$('#slide_image').fadeIn('slow', function() {});	
			});
	}
	
	/*function load_picture(picture){
			tempimage = new Image ;
			tempimage.src = "images/user/" + images_array[picture] ;
			timer = setTimeout( 'loading()', 100 ) ;
		}
		function loading(){
			if(tempimage.complete ){ 
				document.getElementById("slide_image").src = 'images/user/' + images_array[actual_image];
				$('#slide_image').animate({opacity: '100'}, 1000, function() {});
				clearTimeout(timer);
			}else{
				timer = setTimeout( 'loading()', 100 ) ;	
			}
		}*/
	
	//Gallery Vars
	moving = 0;
	current_panel = 1;
	function scroll_thumbs(action){
		
		position = parseInt(document.getElementById('thumbs_table').style.marginLeft);
		if(action == 'left' && position != 0 && moving == 0){
			moving = 1;
			movement = 920;	
			$('#thumbs_table').animate({marginLeft: position + (movement) + 'px' } , 800 , function(){moving = 0;});
			current_panel --;
			//BUTTON OPACITY
			document.getElementById("arrow2").style.opacity = 1;
			document.getElementById("arrow2").style.filter = "alpha(opacity=100)";
			if(current_panel == 1){
				document.getElementById("arrow1").style.opacity = 0.5;
				document.getElementById("arrow1").style.filter = "alpha(opacity=50)";
			}
		}else if(action == 'right' && (pics_total / 10) > current_panel && moving == 0){
			moving = 1;
			movement = -920;	
			$('#thumbs_table').animate({marginLeft: position + (movement) + 'px' } , 800 , function(){moving = 0;});
			current_panel ++;
			//BUTTON OPACITY
			document.getElementById("arrow1").style.opacity = 1;
			document.getElementById("arrow1").style.filter = "alpha(opacity=100)";
			if((pics_total / 10) <= current_panel){
				document.getElementById("arrow2").style.opacity = 0.5;
				document.getElementById("arrow2").style.filter = "alpha(opacity=50)";
			}
		}
		
		

	}
