/**
 * syxmedia
 * @author alejandro@syxmedia.com.ar
 */


/*
 * galería de fotos thickbox
 */
var iPicActual;
var iMinPic = 1;
var iMaxPic = 0; //(inicialización)
var aPicPreload   = new Array();
var aPicList      = new Array();
var imgSpacer     = new Image();
imgSpacer.src     = 'images/spacer_t.gif';
var timer         = false;
var imageHeight   = parseInt(screen.height * .7) - 69;
if (imageHeight > 720) { imageHeight = 720; }
var imageWidth    = parseInt(imageHeight * (4 / 3));
var galleryHeight = imageHeight + 69;
var galleryWidth  = parseInt((imageHeight * (4 / 3)) + 12);

/*
* inicializaciones
*/
 
$(document).ready(function(){
  //galería de fotos thickbox
  $('.imgNumberIndicator').html('-/-');
  $('#photoGallery div.image img').css({ width: imageWidth+'px', height: imageHeight+'px' })
  $('a.openGallery').attr('href', '#TB_inline?width='+galleryWidth+'&amp;height='+galleryHeight+'&amp;inlineId=photoGalleryContainer');
//  $('#photoGallery div.image img').click(function() {
//    $("#TB_overlay").click();
//  });
  $('#close-button').click(function() {
    $("#TB_overlay").click();
  });  
  $("#TB_overlay").click(function() {
    $('#photoGallery div.image img').attr('src', imgSpacer.src);
  });
  
  //visualización de fotos medianas
  zoomImg(1);
  
  //lupa
	$('#picViewBig').click(function() {
		$('#picMedLink'+iActualPic).click();
	});
  $('#picViewBig, img.medium').mouseover(function()  {
    clearTimeout(lupa_timer);
    $('#picViewBig').show();
  });
  $('#picViewBig, img.medium').mouseout(function()   {
    lupa_timer = setTimeout("hide_lupa()", 250);
  });
});    

function photoGallery_prevImg() {
  if (iPicActual > iMinPic) {
   photoGallery_load(iPicActual-1);
  }
  else {
   photoGallery_load(iMaxPic);  
  }
}
function photoGallery_nextImg() {
  if (iPicActual < iMaxPic) {
    photoGallery_load(iPicActual+1);
  }
  else {
    photoGallery_load(iMinPic);  
  }
}

function photoGallery_load(pic) {
  if (timer) {
    clearInterval(timer);
  }
  iPicActual = pic;
  $('.imgNumberIndicator').html(iPicActual+'/'+iMaxPic);
  $('#photoGallery div.image img').attr('src', imgSpacer.src);
  photoGallery_preloadImages();
  var timer = setInterval('photoGallery_checkImage()', 250);
}

function photoGallery_preloadImages() {
  //actual
  if (!aPicPreload[iPicActual]) {
    aPicPreload[iPicActual]     = new Image();
    aPicPreload[iPicActual].src = aPicList[iPicActual];
  }
        
  //next
  if ((iPicActual < iMaxPic) && !aPicPreload[iPicActual+1]) {
    aPicPreload[iPicActual+1]     = new Image();
    aPicPreload[iPicActual+1].src = aPicList[iPicActual+1];
  }
  
  //prev
  if ((iPicActual > iMinPic) && !aPicPreload[iPicActual-1]) {
    aPicPreload[iPicActual-1]     = new Image();
    aPicPreload[iPicActual-1].src = aPicList[iPicActual-1];
  }
}

function photoGallery_checkImage() {
  if (aPicPreload[iPicActual].complete) {
    clearInterval(timer);
    timer = false;
    photoGallery_showImage();
  }
}

function photoGallery_showImage() {
  $('#photoGallery div.image img').attr('src', aPicPreload[iPicActual].src);
}


/*
 * visualización de fotos medianas
 */
var iActualPic = 0;
var TimerID    = 0;
var lupa_timer = false;
var oImgLoading = new Image();
oImgLoading.src = 'images/thickbox/loading.gif';

function hide_lupa() {
  $('#picViewBig').hide();
}
function zoomImg(iNewPic) {
	if (iNewPic == iActualPic) {
		return;
	}
	$('#picMedium img.medium').hide();
  $('#picMed'+iNewPic).show();
	iActualPic = iNewPic;
}