//Gallery
function gallery(pic){

current_pic = pic ;
$('#picWrapper').hide();
$('#Wrapper').fadeOut('slow', function() {});
$('#sideBar').fadeOut('slow', function() {});
$('#pics_container').fadeOut('slow', function() {});
$('#galleryWrapper').fadeIn('slow', function() {
		load_picture(current_pic);});
}

function load_picture(picture){
	tempimage = new Image ;
	tempimage.src = pics_array[current_pic] ;

if(text2_array[current_pic]){document.getElementById("text_line1").innerHTML = text1_array[current_pic];}else{document.getElementById("text_line1").innerHTML ='';}
if(text2_array[current_pic]){document.getElementById("text_line2").innerHTML = text2_array[current_pic];}else{document.getElementById("text_line2").innerHTML ='';}
if(text3_array[current_pic]){document.getElementById("text_line3").innerHTML = text3_array[current_pic];}else{document.getElementById("text_line3").innerHTML ='';}

	timer = setTimeout( 'loading()', 100 ) ;
	if( current_pic == 0){
		document.getElementById("previous").style.opacity = 0.3;
		document.getElementById("previous").style.filter = 'alpha(opacity=30)';
	}else if( current_pic == pics_total-1 ){
		document.getElementById("next").style.opacity = 0.3;
		document.getElementById("next").style.filter = 'alpha(opacity=30)';}
	}
	
	function loading(){
		if(tempimage.complete ){ 
			document.getElementById("picture").src = pics_array[current_pic];
			$('#picWrapper').fadeIn('slow', function() { });
		    center_pic();
			clearTimeout(timer);
		}else{
			timer = setTimeout( 'loading()', 100 ) ;	
		}
	}
	
	function center_pic(){
		pic_height = document.getElementById("picture").offsetHeight;
		pic_width = document.getElementById("picture").offsetWidth;
		document.getElementById("picture").style.marginTop = ((650 - pic_height)/2) + 'px';
		document.getElementById("underText").style.width = pic_width + 'px';
		document.getElementById("closer").style.marginRight = margin_array[current_pic] + 'px';
		}

function next_picture(){if( current_pic == 0 ){document.getElementById("previous").style.opacity = 1;document.getElementById("previous").style.filter = 'alpha(opacity=100)';}if( current_pic < pics_total-1 ){current_pic++;
if( current_pic == pics_total-1){document.getElementById("next").style.opacity = 0.3;document.getElementById("next").style.filter = 'alpha(opacity=30)';}
$('#picWrapper').fadeOut('slow', function() {tempimage = new Image ;tempimage.src = pics_array[current_pic];
if(text1_array[current_pic]){document.getElementById("text_line1").innerHTML = text1_array[current_pic];}else{document.getElementById("text_line1").innerHTML ='';}																							if(text2_array[current_pic]){document.getElementById("text_line2").innerHTML = text2_array[current_pic];}else{document.getElementById("text_line2").innerHTML ='';}if(text3_array[current_pic]){document.getElementById("text_line3").innerHTML = text3_array[current_pic];}else{document.getElementById("text_line3").innerHTML ='';}timer = setTimeout( 'loading()', 100 ) ;});}}

function previous_picture(){if( current_pic == pics_total-1 ){document.getElementById("next").style.opacity = 1;document.getElementById("next").style.filter = 'alpha(opacity=100)';}if( current_pic > 0 ){current_pic--;if( current_pic == 0){document.getElementById("previous").style.opacity = 0.3;document.getElementById("previous").style.filter = 'alpha(opacity=30)';}$('#picWrapper').fadeOut('slow', function() {tempimage = new Image;tempimage.src = pics_array[current_pic] ;  
if(text1_array[current_pic]){document.getElementById("text_line1").innerHTML = text1_array[current_pic];}else{document.getElementById("text_line1").innerHTML ='';}																																																																																																																																					if(text2_array[current_pic]){document.getElementById("text_line2").innerHTML = text2_array[current_pic];}else{document.getElementById("text_line2").innerHTML ='';}if(text3_array[current_pic]){document.getElementById("text_line3").innerHTML = text3_array[current_pic];}else{document.getElementById("text_line3").innerHTML ='';}timer = setTimeout( 'loading()', 100 ) ;});}}function close_gallery(){$('#galleryWrapper').fadeOut('slow', function() { $('#Wrapper').fadeIn('slow', function() {});$('#sideBar').fadeIn('slow', function() {});$('#pics_container').fadeIn('slow', function() {});   document.getElementById("picture").src = '';});}
//Thumbs
moving = 0;
mouseX = 0;
mouseY = 0;
screen_height = document.documentElement.clientHeight;
screen_width = document.documentElement.clientWidth;
move_duration:Number = 0;

function get_screen_size(){
	screen_height = document.documentElement.clientHeight;
	screen_width = document.documentElement.clientWidth;
	init();
	}

function picture(pic_number){
	document.getElementById("pic_number").value = pic_number;
	document.getElementById("send_pic").submit();
	}	

function init_thumbs(){
	pics_width = parseInt(document.getElementById("pics").offsetWidth);
	left = 10;
	limit = 0;
	limit_left = 10;
	limit_right =  screen_width - pics_width ;
	
$(document).mousemove(function (e){
	mouseX = e.pageX;
	mouseY = e.pageY;
	}); 
	
$('#pics_container').mouseover(function start() {
	if( pics_width > screen_width){
		left = parseInt(document.getElementById("pics").style.left);
		if( mouseX > screen_width/2 ){ 
			if(limit != limit_right){
				$('#pics').stop();
				limit = limit_right;
				moving=0;
			}
			limit = limit_right; 
			//move_duration = ( speed * ( -(limit_right - left) ))/( - limit_right );
			move_duration = ( -(limit_right - left) ) * 3;
		}else{ if(limit != limit_left){
			$('#pics').stop();
			limit = limit_left;
			moving=0;
		}
		limit = limit_left;
		//move_duration = ( speed * ( limit_left - left) )/( - limit_right );
		move_duration = ( limit_left - left) * 3;
	}
	if( moving == 0 && ( mouseX > screen_width*0.80 || mouseX < screen_width*0.20 )){	
		moving = 1;
		$('#pics').animate({
		left: limit + 'px'} , move_duration ,'linear', function() {$('#pics').stop();moving = 0;});			
	}else{if( moving == 1){
		moving = 0;
		$('#pics').stop();	
		start();}}}})
	
$('#pics_container').mouseleave(function() {if( moving == 1){moving = 0;$('#pics').stop();}})}

//MENU
function show_contacts(){document.getElementById("contacts").innerHTML = "anaconduto@yahoo.com";document.getElementById("contacts").style.fontWeight = 'bold';}
function hide_contacts(){document.getElementById("contacts").innerHTML = "Contacts";document.getElementById("contacts").style.fontWeight = 'normal';}	

previous_index = 'init';active_submenu = 'none'; function submenu(index){menuLink = "menuLink" + index;menuLink2 = "menuLink" + previous_index;if(previous_index != 'init'){prev = "submenu" + previous_index;document.getElementById(menuLink2).style.fontWeight = 'normal';document.getElementById(menuLink).style.fontWeight = 'normal';document.getElementById(prev).style.display = 'none';}if( index != previous_index){div = "submenu" + index;document.getElementById(menuLink).style.fontWeight = 'bold';document.getElementById(div).style.display = 'block';previous_index = index;}else{previous_index = 'init';	}}function display_submenu(index){
div = "submenu" + index;document.getElementById(div).style.display = 'block';previous_index = index;active_submenu = index;}
function refresh_submenu(){if( active_submenu != 'none' ){div = "submenu" + active_submenu;	if( previous_index ){prev = "submenu" + previous_index;menuLink2 = "menuLink" + previous_index;document.getElementById(prev).style.display = 'none';document.getElementById(menuLink2).style.fontWeight = 'normal';previous_index = active_submenu;}document.getElementById(div).style.display = 'block';}}			
		

