var img_width = 1280; // ORIGINAL SIZE, ANCHO
var img_height = 800; // ORIGINAL SIZE, ALTO

$(function(){
	fixBackground(); // FIX ON LOAD
});

window.onresize = function(){
	fixBackground(); // FIX ON RESIZE
	var jash = window.location.hash;
	doRedir(jash);
}

///////////////// REDIM IMG FUNCT ////////////////////////////

function fixBackground() {
	if(img_width == 0 || img_height == 0 ) {
		return;	
	}
	var window_width = getClientWidth();
	var window_height = getClientHeight();
	var new_width = img_width*window_height/img_height;
	var new_height = img_height*window_width/img_width;
		
		//mostrarlog('dimenciones de la foto original: w =' + img_width + ' h =' + img_height);
		//mostrarlog('dimenciones actuales de la ventana: w =' + window_width + ' h =' + window_height);
		//mostrarlog('dimenciones para las clases .background: w =' + new_width + ' h =' + new_height);
		
	if(new_width > window_width) {
		$('.background').css({
			'width':new_width+'px',
			'height':window_height+'px',
			'left':(0-(new_width-window_width)/2)+'px',
			'top':0+'px'
		});
	}
	else {
		$('.background').css({
			'width':window_width+'px',
			'height':new_height+'px',
			'left':0+'px',
			'top':(0-(new_height-window_height)/2)+'px'
		});
	}
	$('.background').css({'display':'block'});
}

///////////////// ANCHO DE PANTALLA ////////////////////////////

function getClientWidth() {
  var x = window.innerWidth ||
          document.documentElement.clientWidth ||
          document.body.clientWidth;
  return x ? x : 0;
}

///////////////// ALTO DE PANTALLA ////////////////////////////

function getClientHeight(){
  var y = window.innerHeight ||
          document.documentElement.clientHeight ||
          document.body.clientHeight;
  return y ? y : 0;
}

///////////////// REDIR ////////////////////////////

function redir(url,timeout){
	setTimeout('doRedir(\''+url+'\')',timeout);
}

function doRedir(url){
	if(url=='#' || url=='') {
	window.location.reload();
	}else {
	window.location = url;
	}
}

///////////////// SIMPLE LOG ////////////////////////////

function mostrarlog(msg) {
if (!$('.log').length) {
$('<div class="log"></div>').appendTo('body');
}
$('.log').append(msg.replace(/^([^:]*):(.*)$/, '<p><b>$1:</b> <span class="$1">$2</span></p>'));
}
