// JavaScript Document

var page_image_controller = 0;

$(window).load(function() {
	if (page_images.length > 1) show_image(page_images[0]);
});


function show_image(image_src) {
	var old_image = $('#image img[src!=""]');
	var new_image = $('#image img[src=""]');

	new_image[0].onload = function() {
		new_image.css('z-index', '2');
		old_image.css('z-index', '1');
		old_image.fadeOut(2000, function() { old_image.attr('src', ''); });
		new_image.fadeIn(3200);
		$('#image').css({height: ($('#image img').height()+30)+'px'});
	}
	new_image.attr('src', image_src);

	setTimeout(function() {
		page_image_controller = (page_image_controller >= (page_images.length - 1))? 0 : page_image_controller + 1;
		show_image(page_images[page_image_controller]);
	}, 6500);
}


$(document).ready(function() {
	var tamanyo = TamVentana();
	
	var anchoMax=tamanyo[0]-275;
	
	if (anchoMax<1500)
		$('#image').find('.hidden').css({width: anchoMax+'px'});
	else
		$('#image').find('.hidden').css({width: '1500px'});
		
	$('#image').css({height: ($('#image').find('.hidden').height()+30)+'px'});
		
	var posX=(tamanyo[0]/2)-(($('#image').find('.hidden').width()+215)/2);
	var posY=30;

	$('#page').css({left: posX+'px', top: posY+'px'});
	
	
	
	$(window).bind('resize', function() {
		var tamanyo = TamVentana();

		var anchoMax=tamanyo[0]-275;
		
		if (anchoMax<1500)
			$('#image').find('.hidden').css({width: anchoMax+'px'});
		else
			$('#image').find('.hidden').css({width: '1500px'});	
		
		$('#image').css({height: ($('#image').find('.hidden').height()+30)+'px'});
			
		var posX=(tamanyo[0]/2)-(($('#image').find('.hidden').width()+215)/2);
		var posY=30;

		$('#page').css({left: posX+'px', top: posY+'px'});
	});
});

function TamVentana() 
{ 
	var tam=[0, 0]; 
	if (typeof window.innerWidth != 'undefined')
		tam=[window.innerWidth,window.innerHeight];
	else 
		if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined'
				&& 	document.documentElement.clientWidth != 0)
			tam=[document.documentElement.clientWidth, document.documentElement.clientHeight];
		else
			tam=[document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
	return tam;
}

