//usa prototype.js 
var $CE = function(tagName, attributes, styles){ //short for create element
      var el = document.createElement(tagName);
      if (attributes)
            $H(attributes).each(function(pair){
                  eval("el." + pair.key + "='" + pair.value + "'");
            });
      if (styles)
            $H(styles).each(function(pair){
                  el.style[pair.key] = pair.value;
            });

      return $(el);
};

Element.addMethods({
	clearChildren: function(element) {
		element = $(element);
		$A(element.childNodes).each(function(e){
			 if(e.innerHTML!="Inicio"){
			  e.parentNode.removeChild(e);
			  return element;
			 }
		});
		return element;
	},
	//method that creates a new element and appends to the current element
	// example: <div id="myDiv">Please</div>
	//          $('myDiv').append('A',{href:'otherpage.html', className:'red'}).update('Continue...');
	//     ==>  <div id="myDiv">Please<a href="otherpage.html" class="red">Continue...</a></div>
	append: function(element, tagName, attributes, styles) {
		element = $(element);
		var newEl = $CE(tagName, attributes, styles);
		element.appendChild(newEl);
		return newEl;//<-- this one returns the new element
	},
	//appends a text node to the element
	// example: <div id="myDiv"><b>hello</b></div>
	//          $('myDiv').appendText(', John');
	//      ==> <div id="myDiv"><b>hello</b>, John</div>
	appendText: function(element, text){
		element = $(element);
		var t = document.createTextNode(text);
		element.appendChild(t);
		return element;
	  }
});


Event.observe(window, 'load', page_loaded, false);
	function page_loaded(evt) {
		//alert(location.href);
	  //Event.observe(document, 'click', item_clicked, false);
	}
	function item_clicked(evt){
		var child = Event.element(evt);
		//alert("estop es :"+$('inicio').previousSiblings());
		if(child.id!="")
		 {var asd=$(child.id).previousSiblings();}
		
		if(child.tagName=="A" && child.protocol!="javascript:" && child.protocol!="mailto:" && child.tagName!="IMG" && child.className!="externo")
		{
			if(child.id!="last"){
		    $('seguimiento').clearChildren();
			if(child.textContent!='Inicio' || child.innerHTML!="Inicio"){
              new Insertion.After('inicio',"/<a href="+child.href+" id="+child.id+">"+child.innerHTML+"</a>");
			}
			if(child.id!=""){
			 if(asd.length>=2){
		       new Insertion.After('inicio',"/<a href="+asd[0].href+" id="+asd[0].id+">"+asd[0].innerHTML+"</a>"); 
			 }
			}
		  var pagina=child.href;
		   $('principal').replace('<div id="principal" style="vertical-align:top;"></div>');
		  var ajax = new Ajax.Updater('principal', pagina, {method:'get', onComplete: function(req){$('principal').innerHTML = req.responseText;}});
			}
		  Event.stop(evt); 
		}
		
	}
function cargar(pagina,idSeg)
{
	location.href=pagina;
}
function cargarRuta(pagina,idSeg)
{			 
 $('seguimiento').clearChildren();
 var sPar=idSeg.split("/");
 new Insertion.After('inicio',"|<a href="+pagina+" id=last>"+sPar[sPar.length-1]+"</a>");
 for(var i=sPar.length-2;i>0;i--)
 {
  new Insertion.After('inicio',"|"+sPar[i-1]+"/a>");//new Insertion.After('inicio',"/<a href="+pagina+">"+idSeg+"</a>");
  i--;
 }
}
