


function showSecciones() {
        var barra = document.getElementById('globalnavs');

        if (barra.style.display == "none") {
            barra.style.display = "block";
        } else {
            barra.style.display = "none";
        }
    }

    function showTab(link,tab) {
        var tab = document.getElementById(tab);
        var link = document.getElementById(link);
        var tab1 = document.getElementById('tab1');
        var link1 = document.getElementById('link1');
        var tab2 = document.getElementById('tab2');
        var link2 = document.getElementById('link2');
        var tab3 = document.getElementById('tab3');
        var link3 = document.getElementById('link3');
        var tab4 = document.getElementById('tab4');
        var link4 = document.getElementById('link4');

        if (tab.style.display == "none") {
            tab1.style.display = "none";
            link1.className = "";
            tab2.style.display = "none";
            link2.className = "";
            tab3.style.display = "none";
            link3.className = "";
            tab4.style.display = "none";
            link4.className = "";
            tab.style.display = "block";
            link.className = "selected";
        }
    }

function showTabs(links,tabs) {
        var tabs = document.getElementById(tabs);
        var links = document.getElementById(links);
        var tabs1 = document.getElementById('tabs1');
        var links1 = document.getElementById('links1');
        var tabs2 = document.getElementById('tabs2');
        var links2 = document.getElementById('links2');
        var tabs3 = document.getElementById('tabs3');
        var links3 = document.getElementById('links3');
        var tabs4 = document.getElementById('tabs4');
        var links4 = document.getElementById('links4');
        var tabs5 = document.getElementById('tabs5');
        var links5 = document.getElementById('links5');
        var tabs6 = document.getElementById('tabs6');
        var links6 = document.getElementById('links6');

        if (tabs.style.display == "none") {
                if(tabs1 != null  && links1 != null  ){
                        tabs1.style.display = "none";
                        links1.className = "";
                }
                if(tabs2 != null  && links2 != null  ){
                        tabs2.style.display = "none";
                        links2.className = "";
                }
                if(tabs3 != null  && links3 != null  ){
                        tabs3.style.display = "none";
                        links3.className = "";
                }
                if(tabs4 != null  && links4 != null  ){
                        tabs4.style.display = "none";
                        links4.className = "";
                }
                if(tabs5 != null  && links5 != null  ){
                        tabs5.style.display = "none";
                        links5.className = "";
                }
                if(tabs6 != null  && links6 != null  ){
                        tabs6.style.display = "none";
                       links6.className = "";
                }
                tabs.style.display = "block";
                links.className = "selected";
         }
        }
  
function showTabx(links,tabs,pos) {
        var tabsx = document.getElementById(tabs+pos);
        var linksx = document.getElementById(links+pos);
        var tabs1 = document.getElementById(tabs+'1');
        var links1 = document.getElementById(links+'1');
        var tabs2 = document.getElementById(tabs+'2');
        var links2 = document.getElementById(links+'2');
        var tabs3 = document.getElementById(tabs+'3');
        var links3 = document.getElementById(links+'3');
        var tabs4 = document.getElementById(tabs+'4');
        var links4 = document.getElementById(links+'4');
        //var tabs5 = document.getElementById(tabs+'5');
        //var links5 = document.getElementById(links+'5');

        //var tabs6 = document.getElementById(tabs+"6");
        //var links6 = document.getElementById(links+"6");
         if (tabsx.style.display == "none") {
                if(tabs1 != null  && links1 != null  ){
                        tabs1.style.display = "none";
                        links1.className = "";
                }
                if(tabs2 != null  && links2 != null  ){
                        tabs2.style.display = "none";
                        links2.className = "";
                }
                if(tabs3 != null  && links3 != null  ){
                        tabs3.style.display = "none";
                        links3.className = "";
                }
                if(tabs4 != null  && links4 != null  ){
                        tabs4.style.display = "none";
                        links4.className = "";
                }
                //if(tabs5 != null  && links5 != null  ){
                //        tabs5.style.display = "none";
                //        links5.className = "";
                //}
                //if(tabs6 != null  && links6 != null  ){
                //        tabs6.style.display = "none";
                //       links6.className = "";
                //}
                tabsx.style.display = "block";
                linksx.className = "selected";
         }

}






// pool_________________________________________________

jQuery.noConflict(); //Para que no se "pisen" con otras librerias (prototype)

  jQuery(document).ready(function () {

		 jQuery(function() {
								
			jQuery('#slideshow').cycle({
				fx:      'scrollHorz',
				timeout:  0,
				prev:    '.poolprev',
				next:    '.poolnext',
				pager:   'ul.poolnav',
				pagerAnchorBuilder: pagerFactory
			});
		
			function pagerFactory(idx, slide) {
				var s = idx > 2 ? ' style="display:none"' : '';
				return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
			};
			
			// protagonistas
			
			jQuery('#prot_slides').cycle({ 
				fx:     'fade', 
				speed:  'fast', 
				timeout: 0, 
				next:   '#prot_siguiente', 
				prev:   '#prot_anterior' 
			});
									
		});

});


// menu _________________________________________________



jQuery(document).ready(function () {	
	
	jQuery('#globalnav li').hover(
		function () {
			//show its submenu
			jQuery('ul', this).slideDown(100);

		}, 
		function () {
			//hide its submenu
			jQuery('ul', this).slideUp(100);			
		}
	);
	
});




// last _________________________________________________

jQuery(document).ready(function () {	
	
	jQuery("#col_mas  ul li:last-child").addClass("last");

	
});





function muestracanales()
{
//alert("paso por aqui");
var lyr = document.getElementById('sidebar');
lyr.innerHTML = document.getElementById('canales').contentWindow.document.body.innerHTML;
lyr.style.display = 'block'; 
}


//function resize_iframe()
//{
//  //find the height of the internal page
//  var the_height=document.getElementById('canales').contentWindow.document.body.scrollHeight;
//
//  //change the height of the iframe
//  document.getElementById('canales').height= the_height;
//}

//moz=document.getElementById&&!document.all;
//mozHeightOffset=20;

//function resize_iframe(){
//document.getElementById("sizeframe").height=100; // required for Moz bug, value can be "", null, or integer
//document.getElementById('canales').height=window.frames["canales"].document.body.scrollHeight+(moz?mozHeightOffset:0);
//} 

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split('/')[1];
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers 

function resize_iframe(frameid){
var currentfr=document.getElementById(frameid);
if (currentfr && !window.opera){
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.contentWindow.document.body.scrollHeight;
//if (currentfr.addEventListener)
//currentfr.addEventListener("load", readjustIframe, false);
//else if (currentfr.attachEvent){
//currentfr.detachEvent("onload", readjustIframe); // Bug fix line
//currentfr.attachEvent("onload", readjustIframe);
//}
}
} 


// --------------------------------

function showVerimage(noticiaid) {
    var ver = document.getElementById('verimage_'+noticiaid);
    ver.style.display = 'inline';
}
function hideVerimage(noticiaid) {
    var ver = document.getElementById('verimage_'+noticiaid);
    ver.style.display = 'none';
}

// sacado de cabecera.CTP--------------------------------

function showSecciones() {
        var barra = document.getElementById('globalheaders');
        if (barra.style.display == "none") {
            barra.style.display = "block";
        } else {
            barra.style.display = "none";
        }
    }

    function menuPop() {
        if ($('menupop').style.display == 'none') {
            $('menupop').style.display = 'block';
        } else {
            $('menupop').style.display = 'none';
        }
    }

    function selectSeccion() {
            }

if (window.addEventListener) {
    window.addEventListener("load", selectSeccion, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", selectSeccion);
} else if (document.getElementById) {
    window.onload=selectSeccion;
}



// CALENDARIO ***************************************************************

/*  Scal - prototype calendar/date picker
 *   - Jamie Grove
 *   - Ian Tyndall
 *
 *  Scal is freely distributable under the terms of an MIT-style license.
 *  For details, see the Scal web site: http://scal.fieldguidetoprogrammers.com
 *
 *--------------------------------------------------------------------------*/
Object.extend(Date.prototype, {
    monthnames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
    daynames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    succ: function(){
        var sd = new Date(this.getFullYear(),this.getMonth(),this.getDate()+1);
        sd.setHours(this.getHours(),this.getMinutes(),this.getSeconds(),this.getMilliseconds());
        return sd;
    },
    firstofmonth: function(){
        return new Date(this.getFullYear(),this.getMonth(),1);
    },
    lastofmonth: function(){
        return new Date(this.getFullYear(),this.getMonth()+1,0);
    },
    formatPadding: true,
    format: function(f){
        if (!this.valueOf()) { return '&nbsp;'; }
        var d = this;
        var formats = {
            'yyyy' : d.getFullYear(),
            'mmmm': this.monthnames[d.getMonth()],
            'mmm':  this.monthnames[d.getMonth()].substr(0, 3),
            'mm':   this.formatPadding ? ((d.getMonth()).succ()).toPaddedString(2) : (d.getMonth()).succ(),
            'dddd': this.daynames[d.getDay()],
            'ddd':  this.daynames[d.getDay()].substr(0, 3),
            'dd':   d.getDate().toPaddedString(2),
            'hh':   h = d.getHours() % 12 ? h : 12,
            'nn':   d.getMinutes(),
            'ss':   d.getSeconds(),
            'a/p':  d.getHours() < 12 ? 'a' : 'p'
        };
        return f.gsub(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/i,
            function(match) { return formats[match[0].toLowerCase()]; });
    }
});

var scal = {};
scal = Class.create();
scal.prototype = {
    initialize: function(element,update) {
        this.element = $(element);
        var type = Try.these(
            function(){ if(!Object.isUndefined(Effect)) { return 'Effect'; }},
            function(){ return 'Element'; }
        );  
        this.options = Object.extend({
          oncalchange: Prototype.emptyFunction,
          daypadding: false,
          titleformat: 'mmmm yyyy',
          updateformat: 'yyyy-mm-dd',
          closebutton: 'X',
          prevbutton: '&laquo;',
          nextbutton: '&raquo;',
          yearnext: '&raquo;&raquo;',
          yearprev: '&laquo;&laquo;',
          openeffect: type == 'Effect' ? Effect.Appear : Element.show,
          closeeffect: type == 'Effect' ? Effect.Fade : Element.hide,
          exactweeks: false,
          dayheadlength: 2,
          weekdaystart: 0,
          planner: false,
          tabular: false
        }, arguments[2] || { });   
        this.table = false;
        this.thead = false;
        this.startdate = this._setStartDate(arguments[2]);
        if(this.options.planner) { this._setupPlanner(this.options.planner); }
        if(this.options.tabular) { 
            this.table = new Element('table',{'class': 'cal_table',border: 0,cellspacing: 0,cellpadding: 0});
            this.thead = new Element('thead');
            this.table.insert(this.thead);
            this.element.insert(this.table);
        }
        this.updateelement = update;
        this._setCurrentDate(this.startdate); 
        this.initDate = new Date(this.currentdate);
        this.controls = this._buildControls();
        this.title.setAttribute('title', this.initDate.format(this.options.titleformat));
        this._updateTitles();
        this[this.table ? 'thead' : 'element'].insert(this.controls);
        this.cal_wrapper = this._buildHead();
        this.cells = [];
        this._buildCal();
    },
/*------------------------------- INTERNAL -------------------------------*/    
    _setStartDate: function() {
	var args = arguments[0];
        var startday = new Date();
        this.options.month = args && args.month && Object.isNumber(args.month) ? args.month - 1 : startday.getMonth();
        this.options.year = args && args.year && Object.isNumber(args.year) ? args.year : startday.getFullYear();
        this.options.day = args && args.day && Object.isNumber(args.day) ? args.day : (this.options.month != startday.getMonth()) ? 1 : startday.getDate();
        startday.setHours(0,0,0,0);
        startday.setDate(this.options.day);
        startday.setMonth(this.options.month);
        startday.setFullYear(this.options.year);
        return startday;
    },
    _emptyCells: function() {
        if(this.cells.size() > 0) { 
            this.cells.invoke('stopObserving'); 
            this.cells.invoke('remove');
            this.cells = [];
        }
    },
    _buildCal: function() {
        this._emptyCells();
        if(!(Object.isUndefined(this.cal_weeks_wrapper) || this.table)) { this.cal_weeks_wrapper.remove(); }
        this.cal_weeks_wrapper = this._buildWrapper();
        if(this.table) {
            this.table.select('tbody tr.weekbox:not(.weekboxname)').invoke('remove');
            this.table.select('tbody.cal_wrapper').invoke('remove');
            this.cal_weeks_wrapper.each(function(row){
                this.cal_wrapper.insert(row);
            }.bind(this));
        } else {
            this.cal_wrapper.insert(this.cal_weeks_wrapper);
        }
        this[this.table ? 'table' : 'element'].insert(this.cal_wrapper);
    },
    _click: function(event,cellIndex) {
        this.element.select('.dayselected').invoke('removeClassName', 'dayselected');
        (event.target.hasClassName('daybox') ? event.target : event.target.up()).addClassName('dayselected');
        this._setCurrentDate(this.dateRange[cellIndex]);
        this._updateExternal();
    },
    _updateExternal: function(){	
        if (Object.isFunction(this.updateelement)){
            this.updateelement(this.currentdate);
        } else {	
            var updateElement = $(this.updateelement);
            updateElement[updateElement.tagName == 'INPUT' ? 'setValue' : 'update'](this.currentdate.format(this.options.updateformat));
        }            
    },    
    _buildHead: function() {
        var cal_wrapper = new Element(this.table ? 'tbody' : 'div',{'class':'cal_wrapper'});
        var weekbox = new Element(this.table ? 'tr' : 'div',{'class':'weekbox weekboxname'});
        Date.prototype.daynames.sortBy(function(s,i){
            i-=this.options.weekdaystart;
            if(i<0){i+=7;}
            return i;
        }.bind(this)).each(function(day,i) {
        var cell = new Element(this.table ? 'td' : 'div',{'class':'cal_day_name_'+ i});
        cell.addClassName('daybox').addClassName('dayboxname').update(day.substr(0,this.options.dayheadlength));
        if(i == 6) { cell.addClassName('endweek'); }
        weekbox.insert(cell);
        }.bind(this));
        return cal_wrapper.insert(weekbox);
    },
    _buildWrapper: function() {
        var firstdaycal = new Date(this.firstofmonth.getFullYear(),this.firstofmonth.getMonth(),this.firstofmonth.getDate());
        var lastdaycal = new Date(this.lastofmonth.getFullYear(),this.lastofmonth.getMonth(),this.lastofmonth.getDate());
		if(this.options.weekdaystart-firstdaycal.getDay() < firstdaycal.getDate()){
        firstdaycal.setDate(firstdaycal.getDate() - firstdaycal.getDay() + this.options.weekdaystart);
        } else {
		firstdaycal.setDate(firstdaycal.getDate() - (firstdaycal.getDay() + 7 - this.options.weekdaystart));
		}
        var dateRange = $A($R(firstdaycal,lastdaycal));
        var cal_weeks_wrapper = this.table ? [] : new Element('div',{'class': 'calweekswrapper'});
        var wk;
        var row;
        var lastday;
        this.dateRange = [];
        this.indicators = []; // holds values to determine if continued checking for custom classes is needed
        var buildWeek = function(day) {
            row.insert(this._buildDay(wk, day));
            lastday = day;
        }.bind(this);       
        dateRange.eachSlice(7, function(slice,i) {
            wk = i;
            row = new Element(this.table ? 'tr' : 'div',{'class':'cal_week_' + wk}).addClassName('weekbox');
            while(slice.length < 7) { 
                slice.push(slice.last().succ());
            }
            slice.map(buildWeek);	
            cal_weeks_wrapper[this.table ? 'push' : 'insert'](row);
        }.bind(this));
        if(!this.options.exactweeks) {
            var toFinish = 42 - this.cells.size(); 
            var wkstoFinish = Math.ceil(toFinish / 7);
            if(wkstoFinish > 0) { toFinish = toFinish / wkstoFinish; }
            $R(1,wkstoFinish).each(function(w){
                wk += 1;
                row = new Element(this.table ? 'tr' : 'div',{'class':'cal_week_' + wk}).addClassName('weekbox'); 
                $R(1,toFinish).each(function(i) {
                    var d = lastday.succ();
                    row.insert(this._buildDay(wk, d));
                    cal_weeks_wrapper[this.table ? 'push' : 'insert'](row);
                    lastday = d;
                }.bind(this));
            }.bind(this));
        }	
        return cal_weeks_wrapper;
    },
    _compareDates: function(date1,date2,type){
        return (this.indicators.indexOf(type) >= 0) ? false : Object.isUndefined(['getMonth','getDate','getFullYear'].find(function(n){ return date1[n]() != date2[n](); }));
    },
    _buildDay: function(week,day){
        this.dateRange.push(day);
        var cellid = 'cal_day_' + week + '_' + day.getDay();
        var cell = new Element(this.table ? 'td' : 'div',{'class':cellid});
        var celldate = new Element('div',{'class':cellid+'_date'}).addClassName('dayboxdate').update(this.options.daypadding ? ((day.getDate()).toPaddedString(2)) : day.getDate());
        var cellvalue = new Element('div',{'class':cellid+'_value'}).addClassName('dayboxvalue');
        if(this.options.planner) { this._updatePlanner(day,cellvalue); }
        cell.insert(celldate).insert(cellvalue).addClassName('daybox').addClassName('daybox'+ day.format('dddd').toLowerCase());
        // if we are on the currently selected date, set the class to dayselected (i.e. highlight it).
        if(this._compareDates(day,this.currentdate,'dayselected')) {
            cell.addClassName('dayselected');
            this.indicators.push('dayselected');
        }
        if(this._compareDates(day,new Date(),'today')) {
            cell.addClassName('today');
            this.indicators.push('today');
        }
        if(day.getDay() == 6) { cell.addClassName('endweek'); }
        // if we are outside the current month set the day style to 'deactivated'
        var cs = day.getMonth() != this.currentdate.getMonth() ? ['dayoutmonth','dayinmonth'] : ['dayinmonth','dayoutmonth'];
        cell.addClassName(cs[0]);
        if(cell.hasClassName(cs[1])) { cell.removeClassName(cs[1]); }
        this.cells.push(cell);
        return cell.observe('click', this._click.bindAsEventListener(this, this.cells.size() - 1));
    },
    _updateTitles: function() {
        var yr = this.currentdate.getFullYear();
        var mnth = this.currentdate.getMonth();
        var titles = {
            calprevmonth: Date.prototype.monthnames[(mnth - 1) == -1 ? 11 : mnth - 1],
            calprevyear: yr - 1,
            calnextyear: yr + 1,
            calnextmonth: Date.prototype.monthnames[(mnth + 1) == 12 ? 0 : mnth + 1]
        };
        this.controls.select('.calcontrol').each(function(ctrl) {
           var title = titles[ctrl.className.split(' ')[0]];
           if(!Object.isUndefined(title)) { ctrl.setAttribute('title',title); }
        });
    },
    _buildControls: function() {
        var hParts = [
            {p: 'calclose', u: this.options.closebutton, f:  this.toggleCalendar.bindAsEventListener(this)},
            {p: 'calprevmonth', u: this.options.prevbutton, f: this._switchCal.bindAsEventListener(this,'monthdown')},
            {p: 'calprevyear', u: this.options.yearprev, f: this._switchCal.bindAsEventListener(this,'yeardown')},
            {p: 'calnextyear', u: this.options.yearnext, f: this._switchCal.bindAsEventListener(this,'yearup')},
            {p: 'calnextmonth', u: this.options.nextbutton, f: this._switchCal.bindAsEventListener(this,'monthup')},
            {p: 'caltitle', u: this.currentdate.format(this.options.titleformat), f: this._switchCal.bindAsEventListener(this,'init')}
        ];
        if(this.table) { hParts = [hParts[1],hParts[2],hParts[5],hParts[3],hParts[4],hParts[0]]; }
        var cal_header = new Element(this.table ? 'tr' : 'div',{'class':'calheader'});
        hParts.each(function(part) {
            var el = new Element(this.table ? 'td' : 'div',{'class': part.p});
            if(part.p == 'caltitle') {
                this.title = el;
                if(this.table) { el.writeAttribute({colspan: 2}); }
                el.update(part.u).observe('click',part.f);
            } else {
                el.addClassName('calcontrol');
                el[typeof(part.u) == 'object' ? 'insert' : 'update'](part.u).observe('click',part.f);
            }
            cal_header.insert(el);
        }.bind(this));
        return cal_header;
    },
    _switchCal: function(){
        if(arguments[1]) {
            var event = arguments[0];
            var direction = arguments[1];
            event.date = this.currentdate;
        } else {
            var direction = arguments[0];
        }			
        var params = {f: 'setTime', p: this.initDate.getTime()};
        var sday = this.currentdate.getDate();
        if(direction != 'init') {
            var d = this.currentdate[direction.include('month') ? 'getMonth' : 'getFullYear']();
            params = {f: direction.include('month') ? 'setMonth' : 'setYear', p: direction.include('up') ? d + 1 : d - 1};
        }
        this.currentdate[params.f](params.p);
        if (this.currentdate.getDate() != sday){
            this.currentdate.setDate(0);
        }
        if(arguments[1]) { this.options.oncalchange(event); }
        this._update();
    }, 
    _update: function() {
        this._setCurrentDate(arguments[0] ? arguments[0] : this.currentdate);
        this.title.update(this.currentdate.format(this.options.titleformat));
        this._buildCal();
        this._updateTitles();
    },
    _setCurrentDate: function(date){
        this.currentdate = new Date(date.getFullYear(),date.getMonth(),date.getDate());
        this.firstofmonth = this.currentdate.firstofmonth();
        this.lastofmonth = this.currentdate.lastofmonth();
    },    
    _getCellIndexByDate: function(d) {
        var findDate = d.getTime();
        var cellIndex = 0;
        this.dateRange.each(function(dt,i) {
            if(dt.getTime() == findDate) {
                cellIndex = i;
                throw $break;
            }
        });
        return cellIndex;
    },
/*------------------------------- PUBLIC -------------------------------*/        
    destroy: function(){
        this._emptyCells();
        if(this.table) { 
            this.table.remove();
        } else {
            this.cal_weeks_wrapper.remove();
        }
		this.controls.descendants().invoke('stopObserving');
        [this.cal_wrapper,this.controls].invoke('remove');
    },
    setCurrentDate: function(direction){
        this[(direction instanceof Date) ? '_update' : '_switchCal'](direction);
        if(!arguments[1]) { this._updateExternal(); }
        return this.currentdate; 
    },
    toggleCalendar: function(){
        this.options[this.element.visible() ? 'closeeffect' : 'openeffect'](this.element);
    },
    getElementByDate: function(d) {
        return this.cells[this._getCellIndexByDate(d)];
    },
    getElementsByWeek: function(week) {
        return this.element.select('.weekbox:nth-of-type(' + (week + 1) + ') .daybox:not(.dayboxname)');
    },
    getSelectedElement: function() {
        return this.element.select('.dayselected')[0];
    },
    getTodaysElement: function() {
        return this.element.select('.today')[0];
    },
    getDateByElement: function(element) {
        return this.dateRange[this.cells.indexOf(element)];
    },
/*------------------------------- PLUG-IN PLACEHOLDERS -------------------------------*/            
    _setupPlanner: Prototype.emptyFunction,
    _updatePlanner: Prototype.emptyFunction,
/*------------------------------- DEPRECATED -------------------------------*/            
    openCalendar: function(){ 
        if(!this.isOpen()){ this.toggleCalendar(); }
    },
    closeCalendar: function(){ 
        if(this.isOpen()){ this.toggleCalendar(); }
    },
    isOpen: function(){ 
        return this.element.visible();
    }
};


/* submenu */



Menu = {

	/* Version of the Menu class */
	Version: "1.3.1",


	/*
	 * CONSTANTS
	 */

	/* Constant for a horizontal menu */
	HORIZONTAL: 1,

	/* Constant for a vertical menu */
	VERTICAL: 2,


	/*
	 * MENU
	 */

	/* Hold the ID of the menu */
	_menuId: null,

	/* Hold the menu UL node */
	_menuNode: null,


	/*
	 * TEMPORARY VARIABLES
	 */

	/* Hold the show timer */
	_showTimeout: null,

	/* Hold the hide timer */
	_hideTimeout: null,

	/* Will hold the link, submenu and level of the active menu node */
	_activeNodes: new Array(),


	/*
	 * OPTIONS
	 */

	/* Orientation of the menu (horizontal or vertical) */
	_orientation: 1,

	/* Time in milliseconds before showing the sub menu */
	_showPause: 0,

	/* Time in milliseconds before hiding the sub menu */
	_hidePause: 1000,

	/* Opacity (0 = transparent, 1 = opaque) */
	_opacity: 1,


	/*
	 * METHODS
	 */

	/**
	 * Sets the time to wait before hiding the sub menu.
	 *
	 * @param	int		secs
	 *
	 * @deprecated Please use the options argument for Menu.init() instead.
	 */
	setHidePause: function(secs)
	{
		Menu._hidePause = secs * 1000;

		/* deprecation warning */
		alert("Deprecated method Menu.setHidePause() used: Please use the options argument for Menu.init().");
	}, // function setHidePause

	/**
	 * Initializes the dynamic menu.
	 *
	 * @param	string	menuId
	 * @param	object	options
	 *
	 * Available options:
	 * - orientation (int; one of: Menu.HORIZONTAL, Menu.VERTICAL)
	 * - showPause (float; in seconds; default: 0.0)
	 * - hidePause (float; in seconds; default: 1.0)
	 * - opacity (float; 0 = transparent, 1 = opaque; default: 1; transparency of the sub menu)
	 *
	 * Example usage:
	 * <script type="text/javascript">
	 *     Menu.init("menu", {"hidePause": 0.5});
	 * </script>
	 *
	 * This method can be called after document load, but it is preferred to be
	 * called directly from your page (HTML <head>, before document load). This
	 * way the menu loads faster and can be interacted with much sooner.
	 */
	init: function(menuId, options)
	{
		/* Save menu ID (fall back to the default ID "menu") */
		Menu._menuId = (typeof menuId == "string") ? menuId : "menu";

		/* Save options */
		if (options)
		{
			/* Orientation */
			if (options.orientation != undefined)
			{
				Menu._orientation = options.orientation;
			}
			/* Show timeout in seconds */
			if (options.showPause != undefined)
			{
				Menu._showPause = options.showPause * 1000;
			}
			/* Hide timeout in seconds */
			if (options.hidePause != undefined)
			{
				Menu._hidePause = options.hidePause * 1000;
			}
			/* Sub menu opacity */
			if (options.opacity != undefined)
			{
				Menu._opacity = options.opacity;
			}
		}

		/* Check if the document is already loaded. Prototype 1.6.0 introduces
		 * the document.loaded boolean, for 1.5*, check if we can retrieve an
		 * element from the DOM (fails when document is not loaded).
		 */
		if (document.loaded === true || $(Menu._menuId))
		{
			Menu._doInit();
		}
		/* This is how it should work (init called before document load) */
		else
		{
			/* Do the actual initialization on document load. The "dom:loaded"
			 * event is preffered, but only available since 1.6.0 (with
			 * document.observe construction). Fall back to the window onload
			 * when not available.
			 */
			if (document.observe)
			{
				document.observe("dom:loaded", Menu._doInit);
			}
			else
			{
				Element.observe(window, "load", Menu._doInit);
			}
		}
	}, // function init

	/**
	 * Initializes the drop down menu.
	 *
	 * Should be called on page load.
	 */
	_doInit: function()
	{
		/* After the DOM is loaded, save the menu node */
		Menu._menuNode = $(Menu._menuId);

		/* Add events to each first level menu node (if any with a submenu). The
		 * Menu._addEvents() method will add events recursively.
		 */
		Menu._addEvents(Menu._menuNode);
	}, // function _doInit

	/**
	 * Recursively attaches events to the menu UL.
	 *
	 * @param	HTMLUListElement	ulElement
	 * @param	int					level
	 */
	_addEvents: function(ulElement, level)
	{
		/* If level argument is not given, */
		if (isNaN(level))
		{
			level = 1;
		}

		/* Find all menu nodes */
		var elements = (Element.select) ? ulElement.select("li") : ulElement.getElementsBySelector("li")
		for (var i = 0; i < elements.length; i++)
		{
			/* Only use the direct descendants (we're using recursion) */
			if (elements[i].parentNode == ulElement)
			{
				/* Check if it has a sub menu (should return 1 or zero nodes) */
				var subMenus = (Element.select) ? elements[i].select("ul") : elements[i].getElementsBySelector("ul");
				if (subMenus.length > 0)
				{
					/* Add expand listener to the node */
					elements[i].observe("mouseover", Menu._showSubMenu.bindAsEventListener(elements[i], level));

					/* Add collapse listener to the node if it's the first level
					 * (because the LI contains all other submenu's, therefore
					 * any other listeners are over kill).
					 */
					if (level == 1)
					{
						elements[i].observe("mouseout", Menu._hideSubMenu.bindAsEventListener(elements[i], level));
					}

					/* Add "submenu" class for this node link */
					var a = (Element.select) ? elements[i].select("a")[0] : elements[i].getElementsBySelector("a")[0];
					a.addClassName("submenu");

					/* Recursion: check if the sub menu has nodes as well */
					Menu._addEvents(subMenus[0], (level + 1));
				}
				/* No sub menu */
				else
				{
					/* Only hide any expanded sub menu when hovering this node */
					elements[i].observe("mouseover", Menu._quickHideSubMenu.bindAsEventListener(elements[i], level));
				}
			}
		}
	}, // function _addEvents

	/**
	 * Shows the sub menu.
	 *
	 * @param	Event	e
	 * @param	int		level
	 */
	_showSubMenu: function(e, level)
	{
		/* Don't bubble up */
		Event.stop(e);

		/* is this the first menu node to be opened (need to check if we should apply the show timeout ) */
		var isFirst = (Menu._activeNodes.length == 0);

		/* Hide previous opened sub menu */
		Menu._quickHideSubMenu(e, level);

		/* Is this the first menu node and do we have a show delay? */
		if (isFirst && Menu._showPause > 0)
		{
			/* Show in x (mili)seconds */
			Menu._showTimeout = window.setTimeout(function() { Menu._doShowSubMenu(this, level); }.bind(this), Menu._showPause);
		}
		else
		{
			Menu._doShowSubMenu(this, level);
		}
	}, // function _showSubMenu

	/**
	 * Shows the sub menu.
	 *
	 * @param	Event	e
	 * @param	int		level
	 */
	_doShowSubMenu: function(node, level)
	{
		/* Clear possible timeout */
		if (Menu._showTimeout)
		{
			window.clearTimeout(Menu._showTimeout);
		}

		/* Get node link and sub menu */
		var a = (Element.select) ? node.select("a")[0] : node.getElementsBySelector("a")[0];
		var subMenu = (Element.select) ? node.select("ul")[0] : node.getElementsBySelector("ul")[0];

		/* Keep hover style as long as opened */
		a.addClassName("menu_open");
		/* Since 1.3, the class is also applied to the parent LI */
		a.parentNode.addClassName("menu_open");

		/* Show sub menu */
		subMenu.style.visibility = "visible";
		subMenu.style.position = "absolute";

		/* Set correct position. (Note: the horizontal/vertical properties only
		 * apply to the first level nodes. All other levels are fixed vertical.
		 */
		/*var pos = (Element.positionedOffset) ? node.positionedOffset() : Position.positionedOffset(node);
		if (level == 1 && Menu._orientation == Menu.HORIZONTAL)
		{
			subMenu.style.left = pos[0] + "px";
			subMenu.style.top = (pos[1] + node.getHeight()) + "px";
		}
		else
		{
			subMenu.style.left = (pos[0] + node.getWidth()) + "px";
			subMenu.style.top = pos[1] + "px";
		}
*/
		/* Apply opacity if not fully opaque. (Apply for sub menu of first level
		 * only, because otherwise opacity would be doubled.)
		 */
		if (level == 1 && Menu._opacity > 0 && Menu._opacity < 1)
		{
			subMenu.setOpacity(Menu._opacity);
		}

		/* Save submenu */
		Menu._activeNodes.push({"level": level, "link": a, "subMenu": subMenu});
	}, // function _doShowSubMenu

	/**
	 * Immediately hides the active menu.
	 *
	 * @param	Event	e
	 * @param	int		level
	 */
	_quickHideSubMenu: function(e, level)
	{
		/* Don't bubble up */
		Event.stop(e);

		/* Clear possible timeout */
		if (Menu._hideTimeout)
		{
			window.clearTimeout(Menu._hideTimeout);
		}

		/* And hide the open menus from the given level up */
		Menu._doHideSubMenusFromLevel(level);
	}, // function _quickHideSubMenu

	/**
	 * Method for hiding all sub menus.
	 *
	 * Triggered onmouseout of first sub menu (level 2).
	 *
	 * @param	Event	e
	 * @param	int		level
	 */
	_hideSubMenu: function(e, level)
	{
		/* Don't bubble up */
		Event.stop(e);

		/* if hiding (lost focus on first level), do not show! */
		if (Menu._showTimeout)
		{
			window.clearTimeout(Menu._showTimeout);
		}

		/* No pause? Don't use the timeout */
		if (Menu._hidePause <= 0)
		{
			/* Hide all sub menus */
			Menu._doHideSubMenusFromLevel(1);
		}
		else
		{
			/* Hide in x (mili)seconds */
			Menu._hideTimeout = window.setTimeout(function() { Menu._doHideSubMenusFromLevel(1); }, Menu._hidePause);
		}
	}, // function _hideSubMenu

	/**
	 * Hides all active sub menus from the given level.
	 *
	 * @param	int		level	(Default: 1)
	 *
	 * @return	boolean
	 */
	_doHideSubMenusFromLevel: function(level)
	{
		/* If level argument is not given, default to 1 */
		if (isNaN(level))
		{
			level = 1;
		}

		/* Remove these sub menus from the array */
		Menu._activeNodes = Menu._activeNodes.findAll(function(node)
		{
			/* Hide all sub menus with a level equal or higher than the given
			 * level, and return false to remove these from the array.
			 */
			if (node.level >= level)
			{
				/* Remove hover style */
				if (node.link)
				{
					node.link.removeClassName("menu_open");
					node.link.parentNode.removeClassName("menu_open");
				}
				/* Hide sub menu */
				if (node.subMenu)
				{
					node.subMenu.style.visibility = "hidden";
				}
				/* Return false to remove node from the array */
				return false;
			}
			/* Return true for the other nodes, keeping them in the array */
			return true;
		});
	} // function _doHideSubMenusFromLevel

}; // class Menu






