var widthScreen;
var heightScreen;
var ruta;

function url(anchoPantalla,altoPantalla){
	url_aux = anchoPantalla+"x"+altoPantalla;
	if(url_aux!="1024x768"  && url_aux!="1280x800"  && url_aux!="1280x1024"  && url_aux!="1440x900" && url_aux!="1680x1050" && url_aux!="1950x1200" && url_aux!="2048x1536"){
	
		if(anchoPantalla>2500)									url_aux = "XXXXxYYYY";
		else	if(anchoPantalla>=2048)							url_aux = "2048x1536";
		else	if(anchoPantalla>=1950)							url_aux = "1950x1200";
		else	if(anchoPantalla>=1680)							url_aux = "1680x1050";
		else	if(anchoPantalla>=1440)							url_aux = "1440x900";
		else	if(anchoPantalla>=1280 && altoPantalla>800)		url_aux = "1280x1024";
		else	if(anchoPantalla>=1280 && altoPantalla<=800)	url_aux = "1280x800";
		else	if(anchoPantalla>=1024)							url_aux = "1024x768";
			
	}
	return url_aux;
}


function pantalla(){
	widthScreen = $(window).width();
	heightScreen = $(window).height();
}

function esquina(id){
	$("#"+id).corner();
}


//escalaIMG(objeto,100,false,false,false);
//escalaIMG(objeto,false,210,false,false);
//escalaIMG(objeto,false,false,true,false);
//escalaIMG(objeto,false,false,false,true);

function escalaIMG(objeto,ancho,alto,pantalla_x,pantalla_y){
	pantalla();
	
	
	altoPantalla 	= 	screen.height;
	anchoPantalla 	= 	screen.width;

	var ruta = url(anchoPantalla,altoPantalla);
	document.getElementById(objeto).src='../images/fotos/'+ruta+'/'+objeto+'.jpg';
	
	pic = $('#'+objeto); 
	var anchoINI = pic.width();
	var altoINI = pic.height();

	if(pantalla_x)
		ancho = widthScreen;
	else
		if(pantalla_y)
			alto = heightScreen - 68;
	//dimensiones tope
	if(ancho>widthScreen)
		ancho = widthScreen;
	if(alto>heightScreen)
		alto = heightScreen - 68;
	////
	
	if(ancho){	
		var escala = anchoINI/ancho;
		var anchoINI = ancho;
		var altoINI = parseInt(altoINI/escala);
	}
	else	
		if(alto){
			var escala = altoINI/alto;
			var altoINI = alto;
			var anchoINI = parseInt(anchoINI/escala);
	}

	$('#'+objeto).css("width",anchoINI+"px");
	$('#'+objeto).css("height",altoINI+"px");
}


function tab(objeto,active,num){
	for(var i=1;i<=num;i++){
		var idobj = $("#"+objeto+i);
		var idobjcontent = $("#"+objeto+i+"content");
		if(active == i){
			idobj.removeClass();
			idobj.addClass('tabmap_active');
			idobjcontent.fadeTo("slow",1);
		}else{
			idobj.removeClass();
			idobj.addClass('tabmap');
			idobjcontent.hide();
		}
	}
}


function centerDiv(obj,width_div,height_div,less_height){

	var pos = 2 + less_height;
	
	var top_position = Math.ceil((heightScreen/pos) - (height_div/2));
	var left_position = Math.ceil((widthScreen /2) - (width_div/2));
	
	
	//$k(obj).style.display 	= "block";
	$k(obj).style.top 		= top_position+"px";
	$k(obj).style.left 		= left_position+"px";
	$k(obj).style.width 	= width_div+"px";
	$k(obj).style.height 	= height_div+"px";
	
}

function heightMAX(obj){
	$k(obj).style.height = Math.ceil(heightScreen)+"px";
}

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

html: cod html
html: true or false decode
px_width: width postit
px_height: height postit
back: true/false: if the field is the true value is Disables the page, if the field is set to false, the page is enabled
color: background color of the page. Work if it is true back.
opacity: opacity of the bottom of the page. Work if it is true back
less_height: Position is taken as the center window of the page if less_height is zero. less_height takes positive values if the vertical position becomes smaller.

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

function postitWindow(html,decode,px_width,px_height,back,color,opacity,less_height){
	pantalla();
	var contentHTML	;
	if(decode)
		html = base64_decode(html);

	$('#html').html(html);

	var code = $('#contentPostit').html();
	if(back == true){
		if(!color)	color = "black";
		contentHTML = "<div id='opacityHtml' style='position:fixed; width:100%; top:0px; left:0px; background-color:"+color+"; z-index:499; display:none;'>&nbsp;</div>";
	}
	var borderPostitHTML = "<div id='postitBorder' style='position:fixed; background:black; z-index:500; display:none;'>&nbsp;</div>";
	var codeAppend = code + contentHTML + borderPostitHTML;
	$('#contentPostit').html(codeAppend);
	centerDiv('postit',px_width,px_height,less_height);
	$("#contentPostit").fadeTo("slow",1);
	$("#postit").fadeTo("slow",1);
	centerDiv('postitBorder',px_width+20,px_height+20,less_height);
	$("#postitBorder").corner();
	$("#postitBorder").fadeTo("slow",0.4);
	if(opacity){
		heightMAX('opacityHtml');
		$("#opacityHtml").fadeTo("slow",opacity/100);
	}
}

function loadWindow(page,px_width,px_height,back,color,opacity,less_height){
	
	var contentHTML	;

	var code = $('#contentPostit').html();
	if(back == true){
		if(!color)	color = "black";
		if (navigator.appName != "Microsoft Internet Explorer")
			contentHTML = "<div id='opacityHtml' style='position:fixed; width:100%; top:0px; left:0px; background-color:"+color+"; z-index:499; display:none;'>&nbsp;</div>";
		else
			contentHTML = "<div id='opacityHtml' style='position:absolute; width:100%; top:0px; left:0px; background-color:"+color+"; z-index:499; display:none;'>&nbsp;</div>";
	}
	if (navigator.appName != "Microsoft Internet Explorer")
		var borderPostitHTML = "<div id='postitBorder' style='position:fixed; background:black; z-index:500; display:none;'>&nbsp;</div>";
	else
		var borderPostitHTML = "<div id='postitBorder' style='position:absolute; background:black; z-index:500; display:none;'>&nbsp;</div>";
	var codeAppend = code + contentHTML + borderPostitHTML;
	$('#contentPostit').html(codeAppend);
	if (navigator.appName == "Microsoft Internet Explorer")
		$k("postit").style.position="absolute";
	centerDiv('postit',px_width,px_height,less_height);
	$("#contentPostit").fadeTo("slow",1);
	$("#postit").fadeTo("slow",1);
	centerDiv('postitBorder',px_width+20,px_height+20,less_height);
	$("#postitBorder").corner();
	$("#postitBorder").fadeTo("slow",0.4);
	if(opacity){
		heightMAX('opacityHtml');
		$("#opacityHtml").fadeTo("slow",opacity/100);
	}
	
	$('#html').load(page);
}

function postitWindowClose(){
	
	$("#contentPostit").fadeOut("slow");
	$("#postit").fadeOut("slow");
	$("#opacityHtml").fadeOut("slow");
	$("#postitBorder").fadeOut("slow");
}

function postitWindowCloseTime(){
	
	//setTimeout('postitWindowClose()',800);
}


function coment(id,total){
	for(var i=1;i<=total;i++)
		if(id==i)
			$k('cwall-'+id).style.display="block";
		else
			$k('cwall-'+i).style.display="none";
}

function box_animate_height(obj1,obj2,obj3,obj4,px,div_obj){
	$('#'+obj1).animate({'height': '+='+px+'px'}, 'slow');
}

function showDiv(id){
	$k(id).style.display="block";
}
function hideDiv(id){
	$k(id).style.display="none";
}

function $k(id) {
	return (document.getElementById(id));
}
