// JavaScript Document
var supercurObj = null;
$.extend({
  parseJSON: function (json) {
	  	var jsonObj;
			try { jsonObj = eval("("+json+")"); } 
			catch(e) { jsonObj = null; }
		return jsonObj;
	}
});
var globalcX = 0;
var globalcY = 0;

$(document).ready(function () {
 var nn6=document.getElementById&&!document.all;
var topelement = nn6 ? "HTML" : "BODY";
topelement = "HTML";
var header = 1;
			setTimeout(function(){changeHeader()},4000)
			function changeHeader(){
				var headers = new Array("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cultura<div>Emprendedora</div>","un emprendedor<div>no conoce límites</div>","un emprendedor<div>siempre tiene una meta</div>");
				var myhead = header %3;
				var msg = headers[myhead];
				header++;
				//$(getObj("headerMiddle2")).fadeOut("slow",
				$(getObj("headerMiddle2")).hide("drop", { direction:"down"},"slow",
											   function(){
												   getObj("headerMiddle2").innerHTML = msg;
												   //$(getObj("headerMiddle2")).fadeIn("slow",
													$(getObj("headerMiddle2")).show("drop", { direction:"up"},"slow",
																				  function(){
																					   setTimeout(function(){changeHeader()},4000)
																				  });
												   		}
												);
			}
//Binding para que se desaparezcan automaticamente las appearing boxes
	$(document.body).bind("mousemove",function(e){
		globalcX = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) 						   
		globalcY = e.clientY + (document.documentElement.scrollTop ?document.documentElement.scrollTop : document.body.scrollTop);})
	
	$("body").bind("click", function(e){
		//alert(1)
	  var fobj       = nn6 ? e.target : event.srcElement;
	  tempId = fobj.getAttribute('id');
	  while (fobj != null && fobj.tagName != topelement && !$(fobj).hasClass("appearingBoxTitle") && !$(fobj).hasClass("appearingBox")&& !$(fobj).hasClass("appearingBoxTitle2") && !$(fobj).hasClass("appearingBox2")&& !$(fobj).hasClass("ui-datepicker")&& !$(fobj).hasClass("calendar"))
		fobj = nn6 ? fobj.parentNode : fobj.parentElement;
	
	  if (!$(fobj).hasClass("appearingBoxTitle") && !$(fobj).hasClass("appearingBox")&&!$(fobj).hasClass("appearingBoxTitle2") && !$(fobj).hasClass("appearingBox2")&& !$(fobj).hasClass("ui-datepicker")&& !$(fobj).hasClass("calendar"))
	  {
		  //alert(2)
		  	//$(".appearingBox:visible, .appearingBox2:visible").stop(true,true).fadeOut('slow');
			if(supercurObj)
				$(supercurObj).stop(true,true).fadeOut('slow');
			  	//$(".appearingBox2:visible").stop(true,true).hide('slow');
				//hideContentBox();//in splash.js

	  }
	  //alert(3)
		});
//binding para aparecer los appearing boxes
	$(".appearingBoxTitle").bind("click", function(e){
		  var fobj       = nn6 ? e.target : event.srcElement;
		  while (fobj.tagName != topelement && !$(fobj).hasClass("appearingBoxTitle") && !$(fobj).hasClass("appearingBoxTitle2") )
			fobj = nn6 ? fobj.parentNode : fobj.parentElement;
		  var target = fobj.getAttribute("target");
		  var targetWidth = fobj.getAttribute("targetWidth");
		  targetWidth = targetWidth?targetWidth:180;
		  var cX = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) 
		  var cY = e.clientY + (document.documentElement.scrollTop ?document.documentElement.scrollTop : document.body.scrollTop);
		  
		 //$(".appearingBox").fadeOut('slow');
		  //$(".appearingBox2").hide('slow');
		  if(supercurObj)
				$(supercurObj).stop(true,true).fadeOut('slow');
		  if(getObj("real"+target)!=null)
		 document.body.removeChild(getObj("real"+target))
		  if(getObj("real"+target)==null)
		  	showBox(cX,cY,"right",target,targetWidth,false);
		$("#real"+target).stop(true,true);
		  if( getObj("real"+target).style.display == "none" )
		  {
			  $("#real"+target).fadeIn('slow');
		  }
		  else
		 	 $("#real"+target).fadeOut('slow');
		  //alert(target);
		});
//binding para aparecer los appearing boxes, este difiere al appearingBoxTitle en que no se crea una copia del 'target', si no que este se reposiciona el original nadamas.
	$(".appearingBoxTitle2").bind("click", function(e){
		  var fobj  = nn6 ? e.target : event.srcElement;
		  while (fobj.tagName != topelement && !$(fobj).hasClass("appearingBoxTitle") && !$(fobj).hasClass("appearingBoxTitle2") )
			fobj = nn6 ? fobj.parentNode : fobj.parentElement;
		  var target = fobj.getAttribute("target");
		  var targetWidth = fobj.getAttribute("targetWidth");
		  targetWidth = targetWidth?targetWidth:180;
		  var cX = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) 
		  var cY = e.clientY + (document.documentElement.scrollTop ?document.documentElement.scrollTop : document.body.scrollTop);
		 //$(".appearingBox").fadeOut('slow');
		  //$(".appearingBox2").hide('slow');
		  if(supercurObj)
				$(supercurObj).stop(true,true).fadeOut('slow');
		  //if(getObj("real"+target)!=null)
		  //   document.body.removeChild(getObj("real"+target))
		  //if(getObj(target).style.display=='none')
		  	//showBox(cX,cY,"right",target,targetWidth,true);
		$(getObj(target)).stop(true,true);
		  if( getObj(target).style.display == "none" )
		  {
			  //alert(getObj(target).style.left+' '+getObj(target).style.top);
			 // getObj(target).style.left= '0px'
			  //getObj(target).style.top= '0px'
			  // getObj(target).style.display = "block"
			  $(getObj(target)).fadeIn('slow');
			  supercurObj= getObj(target);
		  }
		  else
		  {
		 	 $(getObj(target)).fadeOut('slow');
		  }
		  //alert(target);
		});
});

function showBox(x,y,leftOrRight,id,targetWidth,useOriginalTarget)
{
if(useOriginalTarget)
{div = getObj(id)}
else
{var div = document.createElement("div");}
 
 div.style.position = "absolute"
 div.style.display = 'none';
 targetWidth
 if(leftOrRight=="left")
	 div.style.left = x+'px';
 else
	 div.style.left = (x-targetWidth)+'px';
 div.style.top = y+'px';
 supercurObj = div;//global
 if(useOriginalTarget)
 {
	 
 	return 0;
 }
 div.style.fontSize = '11px'
 div.style.color = '#7b7b7b'
 div.style.width = targetWidth+"px";
 div.style.backgroundColor = "#e6e6cf";
 div.className = 'appearingBox';
 div.setAttribute('id','real'+id);
 div.style.padding = '0px 5px 5px 5px';//t r b l
 var helpingDiv = document.createElement("div");
 helpingDiv.style.width = "100%";
 helpingDiv.style.height = '18px';
  helpingDiv.style.backgroundColor = "#e6e6cf";
  helpingDiv.style.float = "none"
 helpingDiv.innerHTML = "<table cellpadding='0' cellspacing='0' align='right' width='100%'><td align='right' ><span class='a' onclick='$(\"#real"+id+"\").fadeOut(\"slow\");hideContentBox();'><img src='../media/images/close.png'  vspace='1' alt='X' /></span></td></table>";

 div.appendChild(helpingDiv);

 var helpingDiv2 = document.createElement("div");
 helpingDiv2.style.width = "100%";
 helpingDiv2.setAttribute('id','inner'+id);
 //helpingDiv2.style.backgroundColor = '#d1d1af';
 helpingDiv2.style.backgroundColor = '#ffffff';
 helpingDiv2.innerHTML = getObj(id).innerHTML;
 div.appendChild(helpingDiv2);
 document.body.appendChild(div)
}
function getObj(objId) {
	
	return typeof objId == "string" ? document.getElementById(objId):objId;	
}
function trim(STRING){
STRING = lTrim(STRING);
return rTrim(STRING);
}

function rTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}


function lTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}

function emptySearch(input)
{
	if(input.getAttribute("empty")=="true"||input.getAttribute("empty")==true)
		input.value = "";		
}
function refillSearch(input,html)
{
	//Si el campo de está vació, ponerle el texto de búsqueda de nuevo
	if(trim(input.value)=="")
	{
		input.setAttribute("empty","true");
		input.value = html;
	}else
		input.setAttribute("empty","false");
}
function getTotalWidth() {
	if(window.innerWidth) {
		return document.body.offsetWidth;
		return window.innerWidth + (window.scrollMaxX?window.scrollMaxX:0);
	} else {
		return document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth ? document.body.parentNode.clientWidth:document.body.parentNode.scrollWidth;
	}	
}
function getTotalHeight() {
	if(window.innerHeight) {
		return document.body.offsetHeight;
		return window.innerHeight + (window.scrollMaxY?window.scrollMaxY:0);
	} else {
		return document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight ? document.body.parentNode.clientHeight:document.body.parentNode.scrollHeight;
	}	
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
	scrOfY = window.pageYOffset;
	scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	//DOM compliant
	scrOfY = document.body.scrollTop;
	scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	//IE6 standards compliant mode
	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

var hiding = false;
function showIG(img){
	var bgColor = "black";	
	var	splashContainer = document.body;	
	var fOpacity = 0;
	var aOpacity = "alpha(opacity=0)";
	var splash = document.createElement("div");
	var innerSplash = document.createElement("div");
	splash.style.position = "absolute";
	splash.style.backgroundColor = bgColor;
	splash.style.left = "0px";
	splash.style.top = "0px";
	splash.id = 'tempSplash';
	splash.style.textAlign = 'center';
	
	splash.style.width = getTotalWidth()+"px";
	splash.style.height = getTotalHeight()+"px";
	splash.style.MozOpacity = 0;
	splash.style.opacity = fOpacity;
	splash.style.filter = aOpacity;
	splash.style.zIndex = "100";
	innerSplash.style.position = "absolute";
	//alert(splash.style.left+' - '+splash.style.position+' - '+splash.style.top+' - '+splash.style.width+' - '+splash.style.height+' - '+2223)
	var scrollArr = getScrollXY();
	//splash.style.paddingTop = (scrollArr[1]*1+100)+'px';//
	var img2 = new Image();
	img2.src = img.src;
	img2.style.position = "absolute";
	img2.style.top = (scrollArr[1]*1+100)+'px';//
	img2.style.left= (getTotalWidth()/2-img2.width/2)+'px';//
	img2.style.zIndex = "101";
	img2.align='center';
	img2.id = 'tempImage'
	img2.style.MozOpacity = 0;
	img2.style.opacity = fOpacity;
	img2.style.filter = aOpacity;
	
	//innerSplash.style.left = (getTotalWidth()-(getWindowWidth()/2))+"px";
	//innerSplash.style.top = (getTotalHeight()-(getWindowHeight()/2))+"px";
	//innerSplash.style.zIndex = "101";
	//innerSplash.innerHTML = content;
	
	document.body.appendChild(splash);
	document.body.appendChild(img2);
	
	
	
	
	
	$(splash).fadeTo("slow", 0.66,function(){$(splash).click ( function(){ hideSplash();} );});
	$(img2).fadeTo("slow", 1,function(){$(img2).click   ( function(){ hideSplash();} );});
	//$(img2).fadeTo("slow", 1);
	//splashContainer.appendChild(innerSplash);
	//innerSplash.style.left = (getTotalWidth()-(getWindowWidth()/2)-(innerSplash.offsetWidth/2))+"px";
	//innerSplash.style.top = (getTotalHeight()-(getWindowHeight()/2)-(innerSplash.offsetHeight/2))+"px";	
}
function showSplash(html)
{
	$('select').css({visibility: 'hidden'});
	
	var bgColor = "black";	
	var	splashContainer = document.body;	
	var fOpacity = 0;
	var aOpacity = "alpha(opacity=0)";
	var splash = document.createElement("div");
	var innerSplash = document.createElement("div");
	splash.className = "appearingBoxTitle";
	innerSplash.className = "appearingBoxTitle";
	
	splash.style.position = "absolute";
	splash.style.backgroundColor = bgColor;
	splash.style.left = "0px";
	splash.style.top = "0px";
	splash.id = 'tempSplash';
	splash.style.textAlign = 'center';

	//splash.style.width = getTotalWidth()+"px";
	//splash.style.height = getTotalHeight()+"px";
	splash.style.width = "100%";
	splash.style.height = "1500px";

	splash.style.MozOpacity = 0;
	splash.style.opacity = fOpacity;
	splash.style.filter = aOpacity;
	splash.style.zIndex = "100";
	innerSplash.style.position = "absolute";
	var scrollArr = getScrollXY();
	//splash.style.paddingTop = (scrollArr[1]*1+100)+'px';//
	var table = document.createElement('table');
	var img2 = document.createElement('div');
	img2.className = "appearingBoxTitle";
	img2.innerHTML = html;
	//img2.style.width = getTotalWidth()+"px";
	img2.style.width = "100%";
	img2.style.position = "absolute";
	//img2.style.top = (scrollArr[1]*1)+'px';//
	img2.style.top = '0px';//
	//alert(getTotalWidth())
	//alert(img2.width)
	img2.style.left= 0;// (getTotalWidth()/2-img2.width/2)+'px';//
	img2.style.zIndex = "101";
	img2.align='center';
	img2.id = 'tempImage'
	img2.style.MozOpacity = 0;
	img2.style.opacity = fOpacity;
	img2.style.filter = aOpacity;
	//innerSplash.style.left = (getTotalWidth()-(getWindowWidth()/2))+"px";
	//innerSplash.style.top = (getTotalHeight()-(getWindowHeight()/2))+"px";
	//innerSplash.style.zIndex = "101";
	//innerSplash.innerHTML = content;
	//table.appendChild(img2)
	document.body.appendChild(img2);
	splashContainer.appendChild(splash);
	
	
	
	$(splash).fadeTo("slow", 0.66,function(){});
	$(img2).fadeTo("slow", 1,function(){});
	//$(img2).fadeTo("slow", 1);
	//splashContainer.appendChild(innerSplash);
	//innerSplash.style.left = (getTotalWidth()-(getWindowWidth()/2)-(innerSplash.offsetWidth/2))+"px";
	//innerSplash.style.top = (getTotalHeight()-(getWindowHeight()/2)-(innerSplash.offsetHeight/2))+"px";	
}
function alert2(html,accept,callback){
	$('select').css({visibility: 'hidden'});
	
	var bgColor = "black";	
	var fOpacity = 0;
	var aOpacity = "alpha(opacity=0)";
	if(getObj('tempImage3'))
		document.body.removeChild(getObj('tempImage3'));
	var scrollArr = getScrollXY();
	var img2 = document.createElement('div');
	img2.className = "appearingBoxTitle alert2 moreCornered";
	if(accept==null || accept=="")
		accept = '';
	else
		accept = '<input type="button" class="tempButtonB" value="'+accept+'" onclick="" >';
	
	img2.innerHTML = '<table cellpadding="5"><tr><td height="100" valign="top" id="innertempImage">'+html+'</td></tr><tr><td align="center" id="innertempAccept">'+accept+'</td></tr></table>';
	//img2.style.width = getTotalWidth()+"px";
	img2.style.position = "absolute";
	img2.style.top = (scrollArr[1]*1+100)+'px';//

	//img2.style.left= (getTotalWidth()/2-img2.width/2)+'px';//

	img2.style.zIndex = "101";
	img2.align='center';
	img2.id = 'tempImage3'
	img2.style.MozOpacity = 0;
	img2.style.opacity = fOpacity;
	img2.style.filter = aOpacity;

	document.body.appendChild(img2);
	if(!callback)
		callback = function(){hideSplash2();};
		
		setTimeout(function(){$('.tempButtonB').bind('click',function(){callback()})},10);
	
	$(img2).fadeTo("slow", 1,function(){});
	
}
function hideSplash(){
	$('select').css({visibility: 'visible'});
	if(hiding)
		return 0;
	hiding = true;
	var splash = getObj('tempSplash');
	var img2  = getObj('tempImage');
	$(splash).stop(true,true);
	if(img2)
	$(img2).stop(true,true);
	//$(splash).click ( function(){} );
	//$(img2).click (function(){} );
	if(splash)
	$(splash).fadeTo("slow", 0,function(){document.body.removeChild(splash);hiding =false;});
	if(img2)
	$(img2).fadeTo("slow", 0,function(){document.body.removeChild(img2);hiding =false;});
	
}
function hideSplash2(){
	$('select').css({visibility: 'visible'});
	var img2  = getObj('tempImage3');
	if(img2)
		$(img2).stop(true,true);
	//$(splash).click ( function(){} );
	//$(img2).click (function(){} );
	if(img2)
	$(img2).fadeTo("slow", 0,function(){document.body.removeChild(img2);});
	
}
									
	function hoverMenuManager(target){
		this.name = null;
		this.container = null;
		this.width = null;
		this.height = null;	
		this.elements = null;
		this.timer = null;
		this.menus = null;
		this.containers = null;
		this.init = function(){											
			this.menus = new Array();
			this.containers = new Array();
		}
		this.addMenu = function(elements){
			var container = document.getElementById(elements.container);
			if(container==null)
				return 0;
			var floatdivouter = document.createElement("div");
			var floatdiv = document.createElement("div");
			
			floatdivouter.style.position = "absolute";
			floatdivouter.style.zIndex = "50";
			floatdiv.className = "menufloat";
			$(floatdiv).css({opacity:.9})
			floatdiv.innerHTML = elements.html;
			floatdiv.style.display = "none";
			floatdiv.style.zIndex = "50";
			floatdivouter.appendChild(floatdiv);
			container.appendChild(floatdivouter);
			var imhere = this;
			$(container).bind("mouseout",function(){
					imhere.timer = setTimeout(function(){imhere.hide()},200)						  
				   //imhere.hide()
			   })
			$(container).bind("mouseover",function(){
				if(imhere.timer){
					   window.clearTimeout(imhere.timer);
				}
				
				$('select').css({visibility: 'hidden'});
				
					for(var i=0; i< imhere.menus.length ; i++){
						if(imhere.menus[i] != this)
						imhere.menus[i].style.display = "none";
						}
					floatdiv.style.display = "block";
					
			   })

			
			this.menus.push(floatdiv);
			this.containers.push(container);
		}
		this.hide = function(){
			for(var i=0; i< this.menus.length ; i++){
				this.menus[i].style.display = "none";
			}
			$('select').css({visibility: 'visible'});
		}
	}
	var generalTooltip = null;
	function makeMultiSelect(selectablesId,selectedId,realId,callback){
		//selectablesId - lista de opciones disponible
		//selectedId - lista de opciones seleccionadas
		//realId - la lista verdadera que se va a enviar
		
		getObj(selectablesId).ondblclick = function(){
			moveSelected(selectablesId,selectedId,realId)
			if(callback)
				callback();
		}
		getObj(selectablesId+'add').onclick = function(){
			moveSelected(selectablesId,selectedId,realId)
			if(callback)
				callback();
		}
		getObj(selectedId).ondblclick = function(){
			removeSelected(selectablesId,selectedId,realId)
			if(callback)
				callback();
		}
		getObj(selectablesId+'remove').onclick = function(){
			removeSelected(selectablesId,selectedId,realId)
			if(callback)
				callback();
		}
		getObj(selectablesId+'addall').onclick = function(){
			selectAll(selectablesId,selectedId,realId);
			if(callback)
				callback();
		}
		getObj(selectablesId+'removeall').onclick = function(){
			removeAll(selectablesId,selectedId,realId);
			if(callback)
				callback();
		}
	}
	function sortList(name) 
	{ 
		var lb = document.getElementById(name); 
		arrTexts = new Array(); 
		arrValues = new Array(); 
		arrOldTexts = new Array(); 
		for(i=0; i<lb.length; i++) 
		{ 
			arrTexts[i] = lb.options[i].text; 
			arrValues[i] = lb.options[i].value; 
			arrOldTexts[i] = lb.options[i].text; 
		} 
		arrTexts.sort(); 
		for(i=0; i<lb.length; i++) 
		{ 
			lb.options[i].text = arrTexts[i]; 
			for(j=0; j<lb.length; j++) 
			{ 
				if (arrTexts[i] == arrOldTexts[j]) 
				{ 
					lb.options[i].value = arrValues[j]; 
					j = lb.length; 
				} 
			} 
		} 
	}
	
	function moveSelected(selectablesId,selectedId,realId)
	{
		var source = getObj(selectablesId);
		var i = source.selectedIndex;
		if(i<0)
			return 0;
			var newOptionElement = document.createElement("option"); 
			var newOptionElement2 = document.createElement("option"); 
			var sourceValue = source.options[i].value;
			newOptionElement.setAttribute("value", sourceValue); 
			newOptionElement.innerHTML = source.options[i].innerHTML; 
			newOptionElement2.setAttribute("value", sourceValue); 
			newOptionElement2.innerHTML = source.options[i].innerHTML; 
			getObj(selectedId).appendChild(newOptionElement); 
			newOptionElement2.selected = true;
			getObj(realId).appendChild(newOptionElement2); 
			//source.setAttribute("size",source.options.length);
			source.removeChild(source.options[i]);
	}
	function removeSelected(selectablesId,selectedId,realId)
	{
		var source = getObj(selectablesId);
		var destiny = getObj(selectedId);
		var real = getObj(realId);
		var i = destiny.selectedIndex;
		if(i<0)
			return 0;
		var newOptionElement = document.createElement("option"); 
		var destinyValue = destiny.options[i].value;
		newOptionElement.setAttribute("value", destinyValue); 
		newOptionElement.innerHTML = destiny.options[i].innerHTML; 
		source.appendChild(newOptionElement); 
		//source.setAttribute("size",source.options.length);
		destiny.removeChild(destiny.options[i]);
		real.removeChild(real.options[i]);
		sortList(selectablesId)
	}
	function selectAll(selectablesId,selectedId,realId){
		var source = getObj(selectablesId);
		var destiny = getObj(selectedId);
		var real = getObj(realId);
		while(source.options[0]!=null&&source.options[0].innerHTML != "")
		{
			i=0;
			var newOptionElement = document.createElement("option"); 
			var newOptionElement2 = document.createElement("option"); 
			var sourceValue = source.options[i].value;
			newOptionElement.setAttribute("value", sourceValue); 
			newOptionElement.innerHTML = source.options[i].innerHTML; 
			newOptionElement2.setAttribute("value", sourceValue); 
			newOptionElement2.innerHTML = source.options[i].innerHTML; 
			getObj(selectedId).appendChild(newOptionElement); 
			newOptionElement2.selected = true;
			getObj(realId).appendChild(newOptionElement2); 
			//source.setAttribute("size",source.options.length);
			source.removeChild(source.options[i]);
		}
		
		sortList(selectedId)
		sortList(realId)
	}
	function removeAll(selectablesId,selectedId,realId){
		var source = getObj(selectablesId);
		var destiny = getObj(selectedId);
		var real = getObj(realId);
		while(destiny.options[0]!=null&&destiny.options[0].innerHTML != "")
		{
			i=0;
			var newOptionElement = document.createElement("option"); 
			var destinyValue = destiny.options[i].value;
			newOptionElement.setAttribute("value", destinyValue); 
			newOptionElement.innerHTML = destiny.options[i].innerHTML; 
			source.appendChild(newOptionElement); 
			destiny.removeChild(destiny.options[i]);
			real.removeChild(real.options[i]);
		}
		sortList(selectablesId)
	}
	var curAccordion = 0;
                    function showAccordion(number)
					{
						if(number==curAccordion)
							return 0;
						$(getObj("accordiontitle"+curAccordion)).removeClass("letterOrange").addClass("letterGray");
						$(getObj("accordiontitle"+number)).removeClass("letterGray").addClass("letterOrange");
						
						$(getObj("accordion"+curAccordion)).stop().animate({height:"0px"},1000);
						$(getObj("accordion"+number)).stop(true,true).animate({height:"340px"},1000);
						curAccordion = number;
					}
var currentContent = 0;
var currentSubContent = 0;
var currentContentTemp = 0;

var changingContent = false;
function loadContent(content,subContent){
	currentContentTemp = currentContent;
	if(content==currentContent&&subContent==currentSubContent)	
		return 0;
	if(changingContent)
		return 0;
	changingContent = true;
	var speed = 700;
	var speed2 = 300;
	var speed3 = 500;
	var bigFont = "14px";
	var smallFont = "12px";
	var i=0;
	
	
	if(content==currentContent){//just change subsection
		//reset previous balls,
		$(getObj("subtitle"+currentContent+"-"+currentSubContent)).stop(true,true).animate({paddingTop:"10px",fontSize:smallFont},speed3);
		$(getObj("ball"+currentContent+"-"+currentSubContent)).stop(true,true).animate({marginTop:"0px"},speed3);
		
		//continue with current balls
		//$(getObj("ball"+content+"-"+subContent)).stop(true,true).animate({marginTop:"10px"},200).effect("bounce", { times:3 }, 300);
		$(getObj("ball"+content+"-"+subContent)).stop(true,true).animate({marginTop:"10px"},speed3);
		$(getObj("subtitle"+content+"-"+subContent)).stop(true,true).animate({paddingTop:"20px",fontSize:bigFont},speed3);
		
		var directions2 = subContent > currentSubContent ? "right":"left";
		var directions = subContent > currentSubContent ? "left":"right";	
		getObj("subcontent"+currentContent+"-"+currentSubContent).style.overflow = "hidden";
		getObj("subcontent"+currentContent+"-"+subContent).style.overflow = "hidden";		
		
		$(getObj("subcontent"+currentContent+"-"+currentSubContent)).stop(true,true).hide("slide", { direction:directions}, speed2,function(){																													
			$(getObj("subcontent"+currentContent+"-"+subContent)).stop(true,true).show("slide", { direction: directions2 }, speed2,function(){
																				getObj("subcontent"+currentContent+"-"+currentSubContent).style.overflow = "auto";
																				getObj("subcontent"+currentContent+"-"+subContent).style.overflow = "auto";
																				//correjir error en fuentes en ie
																				getObj("subcontent"+currentContent+"-"+subContent).style.position = "absolute";		
																				changingContent = false;
																				setTimeout(function(){getObj("subcontent"+currentContent+"-"+subContent).style.position = "relative";		},10);
																																			});
																																	 })
	}else{
		//save original html before puff cause table resizing ain't working
		var originalContent = getObj("content"+currentContent).innerHTML;
		
		//reset previous balls, of previous content
		if(getObj("subtitle"+currentContent+"-"+currentSubContent)!=null)
			$(getObj("subtitle"+currentContent+"-"+currentSubContent)).stop(true,true).css({paddingTop:"10px",fontSize:smallFont});
		if(getObj("ball"+currentContent+"-"+currentSubContent)!=null)
			$(getObj("ball"+currentContent+"-"+currentSubContent)).stop(true,true).css({marginTop:"0px"});
		var i=0;
		while(getObj("subtitle"+content+"-"+i)!=null){
			getObj("subtitle"+content+"-"+(i)).style.fontSize = smallFont;
			getObj("subtitle"+content+"-"+(i)).style.paddingTop = "10px";
			if(getObj("ball"+content+"-"+(i))!=null)
				$(getObj("ball"+content+"-"+(i))).css({marginTop:"0px"});
			i++;
		}
		getObj("subcontent"+currentContent+"-"+currentSubContent).style.overflow = "hidden";
		getObj("subcontent"+content+"-"+subContent).style.overflow = "hidden";
		//show subsection 0
		var i=0;
		while(getObj("subcontent"+content+"-"+i)!=null){
			$(getObj("subcontent"+content+"-"+(i++))).stop(true,true).hide();
		}
		
		getObj("subcontent"+content+"-"+subContent).style.visibility = "visible";//show target subcontent and hide its siblings
		$(getObj("subcontent"+content+"-"+subContent)).stop(true,true).show();
		//hide current content
		//$(getObj("content"+currentContent)).effect("explode", { pieces: 16 }, 2000)
		getObj("content"+currentContent).style.backgroundColor = "white";
		getObj("content"+content).style.backgroundColor = "white";
		$(getObj("content"+currentContent)).hide("puff", {}, speed,function(){
																			
							getObj("content"+currentContent).style.backgroundColor = "";
							//by the time timeout execute, currentContent = content
							setTimeout(function(){getObj("content"+currentContent).style.backgroundColor = ""},2*speed/3);
							getObj("content"+content).style.backgroundColor = "white";
							$(getObj("content"+content)).show("puff", {}, speed,function(){getObj("content"+content).style.backgroundColor = "";
																				getObj("subcontent"+currentContent+"-"+currentSubContent).style.overflow = "auto";
																				getObj("subcontent"+content+"-"+subContent).style.overflow = "auto";
																				
																				getObj("subcontent"+content+"-"+subContent).style.position = "absolute";		
																				$(".subContainer").css({position:"absolute"});
																				setTimeout(function(){getObj("subcontent"+content+"-"+subContent).style.position = "relative";	//restore original content cause puff ain't resizing tables back

																				getObj("content"+currentContentTemp).innerHTML = originalContent;
																				getObj("content"+currentContentTemp).style.display = "none";	},10);
																				
																				
																				$(".subContainer").css({position:"relative"});
																				if(getObj("subtitle"+content+"-"+subContent)!=null)
																					$(getObj("subtitle"+content+"-"+subContent)).stop(true,true).animate({paddingTop:"20px",fontSize:bigFont},speed3,function(){if(getObj("ball"+content+"-"+subContent)!=null){changingContent = false;/*last thing done*/}});
																				else
																					changingContent = false;
																				if(getObj("ball"+content+"-"+subContent)!=null){
																			//$(getObj("ball"+content+"-"+subContent)).stop(true,true).animate({marginTop:"10px"} ,200).effect("bounce", { times:3 }, 300,function(){changingContent = false;});
																				$(getObj("ball"+content+"-"+subContent)).stop(true,true).animate({marginTop:"10px"},speed3,function(){changingContent = false;});
																				}
																				$("#content"+content+" img").css({width:"",height:""})
																				//getObj("content"+content).style.position = "relative";
																								  })																			
																			})
		//$(getObj("content"+content)).show("puff", {}, speed);
	}
	currentContent=content;
	currentSubContent=subContent;
}
function showFooter(){
	$(getObj("floatingFooter")).stop(true,true).css({display:"block",opacity:0.0}).animate({opacity:0.8},700);
}
function hideFooter(){
	$(getObj("floatingFooter")).stop(true,true).animate({opacity:0},700,function(){getObj("floatingFooter").style.display = "none"});
}
