function showMovies(id){
	var arrPageSizes = _getPageDimensions();
	pageWidth = arrPageSizes[0];
	pageHeight = arrPageSizes[1];
	if(pageWidth < 1100) pageWidth = 1100;
	$('#post-overlay')
		.unbind()
		.css({
			width: pageWidth,
			height: pageHeight					   
		})
		.bind('click', function(){movieClose()});
	$('#post-overlay div').css({
		width: pageWidth,
		height: pageHeight	
	});
	$('#post-overlay').fadeIn();
	
	$('#movieFrame').attr('src','movies.php?id='+id);
	$('#moviesPost').show();
}

function movieClose(){
	$('#moviesPost').fadeOut();
	$('#post-overlay')
		.unbind('click')
		.fadeOut();
	$('#movieFrame').attr('src','/blank.html');
	
}

function openGallery(){
	var arrPageSizes = _getPageDimensions();
	pageWidth = arrPageSizes[0];
	pageHeight = arrPageSizes[1];
	if(pageWidth < 1100) pageWidth = 1100;
	$('#post-overlay')
		.unbind()
		.css({
			width: pageWidth,
			height: pageHeight					   
		})
		.bind('click', function(){closeGallery()});
	$('#post-overlay div').css({
		width: pageWidth,
		height: pageHeight					   
	});
	$('#post-overlay').fadeIn('slow');
	
	$('#imagesPost').fadeIn('slow');
	$('#galleryList div:first h4 a').click();
}

function closeGallery(){
	$('#imagesPost').fadeOut('slow');
	$('#post-overlay')
		.unbind('click')
		.fadeOut('slow');
}









function showGallery(id, lnk){
	$('#galleryList h4 a').removeClass('current');
	$(lnk).addClass('current');
	$('#galleryList ul').hide();
	$(id).fadeIn();
	startGallery(id);
}

imageArray = [];
activeImage = 0;
function startGallery(id){
	imageArray.length = 0;
	activeImage = 0;
	imageList = $('li a', id).get();
	
	$('li a', id).click(function(){
		/* se desactiva y activa el boton current */
		$(this).parent().siblings().children().removeClass('current');
		$(this).addClass('current');
		
		var $prev = $(this).parent().prev().children();
		var $next = $(this).parent().next().children();
		
		/* se muestra proceso de loading */
		$('#gallery-loading').show();
		/* se oculta la imagen previa */
		$('#gallery-nav').hide();
		$('#gallery-image').hide();
		
		/* se obtiene la imagen a mostrar */
		src = $(this).attr('href');
		/* se define la accion al cargar la imagen */
		objImagePreloader = new Image();
		objImagePreloader.onload = function(){
			/* se asigna la imagen */
			$('#gallery-image').attr('src',src);
			/* se oculta proceso de loading */
			$('#gallery-loading').hide();
			/* se hace la animación del contenedor */
			_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
			/* se limpia el onload */
			objImagePreloader.onload=function(){};
			/* se muestra la navegación interna */
			$('#gallery-nav').show();
			$('#gallery-nav-btnPrev,#gallery-nav-btnNext')
			    .css({ 'background' : 'transparent url(/images/lightbox-blank.gif) no-repeat' })
				.unbind();
			$('#gallery-nav-btnPrev')
				.hover(
					function(){
						$(this).css({ 'background' : 'url(/images/btn-prev.gif) left 85% no-repeat' });
					},
					function(){
						$(this).css({ 'background' : 'transparent url(/images/lightbox-blank.gif) no-repeat' })
					}
				)
				.bind('click', function(){
					$prev.click();
					return false;
				});
			$('#gallery-nav-btnNext')
				.hover(
					function(){
						$(this).css({ 'background' : 'url(/images/btn-next.gif) right 85% no-repeat' });
					},
					function(){
						$(this).css({ 'background' : 'transparent url(/images/lightbox-blank.gif) no-repeat' })
					}
				)
				.bind('click', function(){
					$next.click();
					return false;
				});			
						
		}
		/* se carga la imagen */
		objImagePreloader.src = src;
		return false;
	});
	
	for(i=0;i<imageList.length;i++){
		thisImage = new Image();
		thisImage.src = $(imageList[i]).attr('href');
		imageArray.push(thisImage);	
	}
	
	$('li:first a', id).click();
}



function _resize_container_image_box(intImageWidth,intImageHeight) {
	// Get current width and height
	var intCurrentWidth = $('#image-box').width();
	var intCurrentHeight = $('#image-box').height();
	// Get the width and height of the selected image plus the padding
	var intWidth = (intImageWidth); // Plus the image´s width and the left and right padding value
	var intHeight = (intImageHeight); // Plus the image´s height and the left and right padding value
	// Diferences
	var intDiffW = intCurrentWidth - intWidth;
	var intDiffH = intCurrentHeight - intHeight;
	// Get the new x, y
	var intTop = ((402 - intImageHeight) / 2) + 12;
	var intLeft = ((526 - intImageWidth) / 2) + 12;
	// Perfomance the effect
	$('#image-box').animate({ width: intWidth, height: intHeight, left: intLeft, top: intTop},400,function() { $('#gallery-image').fadeIn(); });
	if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
		if ( $.browser.msie ) {
			___pause(250);
		} else {
			___pause(100);	
		}
	}
	//$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
};

function ___pause(ms) {
	var date = new Date(); 
	curDate = null;
	do { var curDate = new Date(); }
	while ( curDate - date < ms);
 };




function _getPageDimensions() {
	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){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	var pageWidth, pageHeight
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

