// JavaScript Document

function ocultar_swf(){
		$('#radio').css({visibility:'hidden'});
	}
function mostrar_swf(){
		$('#radio').css({visibility:'visible'});
	}


function ver_mas(){
	ocultar_swf();
}

/********************** *******************************/


function reloadimg(){
		$.ajax({ 
		  type: "POST", 
		  url: "loadimg.php", 
		  data: "an=240&al=150&mode=2", 
		  success: function(txt){ 
			$('#big_img').html(txt);
		  } 
		});
}

function add_view_img(){
	$('.gal_div_clear').addClass('gal_div_img');
	$('.gal_div_clear').addClass('show_img');
	$('.gal_div_clear').removeClass('gal_div_clear');
	$('#gal_cont_imgs').append('<div class="gal_div_clear"></div>');

	$.ajax({ 
	  type: "POST", 
	  url: "loadimg.php", 
	  data: "an=100&al=95&mode=1", 
	  success: function(txt){ 
		$('.show_img').html(txt);
		$('.show_img').removeClass('show_img');
		var w = $('#gal_cont_imgs').width();
		$('#gal_cont_imgs').css({width: (w+106)+'px'});
		$('#gal_cont_imgs').animate({left: '-=103'}, 500);
	  } 
	});
	
}
	
function ocultar_foto(){
	$('#fndlayer').fadeTo(500,0,function(){ $('#fndlayer').css({display : "none"}); });
	$('#layer').fadeTo(500,0,function(){ $('#layer').css({display : "none"}); mostrar_swf(); });	
}

/************************** **************************************************************************************************/
// from : http://www.dynamicdrive.com/dynamicindex4/lightbox
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

/************************** **************************************************************************************************/
function show_full_img(img, mode){
	ocultar_swf();
	
	$('#fndlayer').css({opacity : "0"});
	$('#fndlayer').css({display : "block"});
	$('#fndlayer').fadeTo(500,.8);
	
	$('#layer').css({opacity : "0"});
	$('#layer').css({display : "block"});
	var __left = ($(window).width() / 2) - ($('#layer').width() / 2);
	$('#layer').css({left : __left+"px"});
	var __top = getPageScroll();
	$('#layer').css({top : (__top[1]+50)+"px"});
				
		$.ajax({ 
		  type: "POST", 
		  url: "loadfullimg.php", 
		  data: "img="+img, 
		  success: function(txt){ 
				$('#layer').html(txt);
				$('#layer').fadeTo(500,1,function(){
					if(($.browser.msie)){ var add_w = 30; al_img += 15; }
					else{ var add_w = 0;}
					if(an_img < 250){
						an_img = 250;
					}
					al_img += 90;
					al_img += 100;
					an_img += add_w;
									
					al_old = al_img;
					an_old = an_img;
					
					$('#div_foto_ppal_cargada').animate({width: an_img},'slow',function(){
						$('#div_foto_ppal_cargada').animate({height: al_img},'slow',function(){
							$('#foto_ppal_cargada').fadeIn('slow');
							$('#div_flechas_cargada').show();
						});
					});
				});
		  } 
		}); 
}

function load_next_prev(img){
	$.ajax({ 
	  type: "POST", 
	  url: "loadnextprev.php", 
	  data: "p_w="+an_img+"&p_h="+al_img+"&img="+img, 
	  success: function(txt){ 
			$('#layer').html(txt);
			if(($.browser.msie)){ var add_w = 30; al_img += 15;}
			else{ var add_w = 0;}
			if(an_img < 250){
				an_img = 250;
			}
			al_img += 90;
			al_img += 100;
			an_img += add_w;
			
			if(an_img == an_old) v_w = 1;
			else if(((an_img - an_old) > 0 ? an_img - an_old : an_old - an_img ) <= 30 ) v_w = 'fast';
			else v_w = 'slow';

			if(al_img == al_old) v_h = 1;
			else if(((al_img - al_old) > 0 ? al_img - al_old : al_old - al_img ) <= 30 ) v_h = 'fast';
			else v_h = 'slow';
			
			al_old = al_img; an_old = an_img;

			$('#div_foto_ppal_cargada').animate({width: an_img},v_w,function(){
				$('#div_foto_ppal_cargada').animate({height: al_img},v_h,function(){
					$('#foto_ppal_cargada').fadeIn('slow');
					$('#div_flechas_cargada').show();
				});
			});
	  } 
	}); 
}

function ver_prev(){
	if(indice_img_actual <= 0) indice_img_actual = _total;
	else indice_img_actual--;

	$('#foto_ppal_cargada').css({visibility:'hidden'});
	$('#div_flechas_cargada').css({visibility:'hidden'});
	
	load_next_prev(list_img[indice_img_actual]);
}

function ver_sigu(){
	if(indice_img_actual >= _total) indice_img_actual = 0;
	else indice_img_actual++;
	$('#foto_ppal_cargada').css({visibility:'hidden'});
	$('#div_flechas_cargada').css({visibility:'hidden'});
	
	load_next_prev(list_img[indice_img_actual]);
}

/*
function add_foto_show(){
	$('#add_img_div_out').slideToggle('slow');
}
*/
function add_foto_show(){
	if( $('#add_img_div_out').css('display') == 'none' ){
		$('.unico').hide();
			$('#add_img_div_out').slideDown('slow',function(){
		});
	}else{
		$('#add_img_div_out').slideUp('slow',function(){
			$('.unico').show();
		});
	}
}

function validar_foto_new(el){
	var val_foto1 = /\w+\.jpg$/;
	var val_foto2 = /\w+\.gif$/;
	var val_foto3 = /\w+\.png$/;
	var val_foto4 = /\w+\.JPG$/;
	var val_foto5 = /\w+\.GIF$/;
	var val_foto6 = /\w+\.PNG$/;
	var val_foto7 = /\w+\.jpeg$/;
	var val_foto8 = /\w+\.JPEG$/;
	
	if(val_foto1.test(el.imagen.value) || val_foto2.test(el.imagen.value) || val_foto3.test(el.imagen.value) || val_foto4.test(el.imagen.value) || val_foto5.test(el.imagen.value) || val_foto6.test(el.imagen.value) || val_foto7.test(el.imagen.value) || val_foto8.test(el.imagen.value)){
		if( $.trim(el.imagen.value) != '' && $.trim(el.descripcion.value) != '')
			return true;
	}else{
		alert('Las fotos deben ser .JPG, .JPEG, .GIF o .PNG');
	}
	return false;	
}
