var Move =	{
  copy	:   function(e, target)	{
	    var eId      = $(e);
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e+'-copy';

	    for(var i = 0; cLength >= i;  i++)	{
	    if(copyE.childNodes[i].id) {
	    var cNode   = copyE.childNodes[i];
	    var firstId = cNode.id;
	    cNode.id    = firstId+'-copy'; }
	    }
	    $(target).appendChild(copyE);
	    },
  element:  function(e, target, type)	{
	
	    var eId =  $(e);
	    if(type == 'move') {
		
	       $(target).appendChild(eId);
	    }
	    else if(type == 'copy')	{
	       this.copy(e, target);
	    }
	}
};
var maxSize = 830;
createMenu();

 function createMenu(){
	//w - dimensiunea div-ului cu id = meniu_secundar
	var w=0;
	//la dimensiune se aduna width pentru divul cu class="caption"
	var cap = $$('#meniu_secundar .caption');
	for(var i=0; i < cap.length;i++){
		w += cap[i].getWidth()+5;
		if(w>maxSize){
			cap[i].hide();
			cap[i].addClassName('hiddenIt');
			}
		}

	//la dimensiune se aduna width pentru divurile cu class="parent"
	var par = $$('#meniu_secundar .parent');
	for(var i=0; i<par.length;i++){
		w += par[i].getWidth()+10;
		if(w>maxSize){
			par[i].hide();
			par[i].addClassName('hiddenIt');		
		}
	}
	if(w>maxSize){
	//divurile ascunse se adauga in divul cu id="more"
	var hid = $$('#meniu_secundar .hiddenIt');
	var more_div = document.createElement('div');
	var hid_div = document.createElement('div');
		
	hid_div.id = "more_panel";
	var more_a = document.createElement('a');
	var more_em = document.createElement('em');
	more_a.href = "#";
	more_a.title = "mai multe";
		
	more_a.innerHTML = "mai multe";
	more_div.id = 'more';
	more_div.appendChild(more_a);
	more_div.appendChild(more_em);
	
	for(var i=0; i<hid.length; i++){
		
		Move.element(hid[i], hid_div, 'move');
	}	
	more_div.appendChild(hid_div);

	$('meniu_secundar').appendChild(more_div);
	$('more_panel').hide();	
	observeMenu();
	}
 }


	
	function observeMenu(){
  	Event.observe($('more'), 'mouseover', function(){
       var hid = $$('#more .parent');
	 $A(hid).each(Element.show);
       $('more_panel').show();
    	});
	
 	 Event.observe($('more'), 'mouseout', function(){
        var hid = $('#more .parent');
	 $A(hid).each(Element.hide);
	 $('more_panel').hide();
   	 });
}
