/*

Name: The MooBar, a customizable, lightweight Javascript network bar

Description: A free Javascript network bar that requires you embed a single Javascript file into your website network or web page to display a toolbar that allows users to quickly jump between different sites or popular content.

Version: 1.0

License: The MooBar by Designmoo is licensed under a Creative Commons Attribution 3.0 United States License. Based on a work at www.designmoo.com. Permissions beyond the scope of this license may be available at http://www.designmoo.com/blog/moobar.

When using the MooBar, please place a link on your site back to Designmoo with the text "Network bar by Designmoo" or something to that effect.

Original URL: http://www.designmoo.com/blog/moobar

*/

var moobar = {
	
	/* Set up the base URL and the name of your network */
	
	base_href : 'http://www.leafar.com.br/pt', // The URL of the main network site (this will be linked to from the logo)
	network_name : 'Grupo Leafar', // The name of the network or website (this will be the alt tag on the logo image)
	
	/* Set up the featured image section */
	
	featured : true, // Turn featured area on/off by setting this to true or false
	featured_name : 'Yahoo!', // Enter the name of the featured area (this will be displayed in the ALT attribute for the image)
	featured_href : 'http://www.yahoo.com', // Enter the URL the featured area will point to
	featured_image : this.base_href+'/moobar/images/moobar-featured.png', // enter the path to the image you'd like to use for your featured area. Recommended size: 350x30
	
	init : function(){ // Initialize the MooBar
	
		_this = moobar;
    
		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = _this.base_href+'/moobar/moobar.css'; // This is the location of the CSS file that will be dynamically added to your page, make sure the CSS is located at http://yoururl.com/moobar/moobar.css for this to work!
		cssNode.media = 'screen';
		headID.appendChild(cssNode);
    
		/* This is where we create the HTML that will be embedded into your website */
		
		var moobarHTML = '\
			<div id="MOO_inner"> \
				<a id="MOO_logo" href="'+_this.base_href+'"><img src="'+_this.base_href+'/moobar/images/moobar-logo.png" alt="'+_this.network_name+'" /></a> \
				<a id="MOO_nav" href="">Atendimento On-line</a>';

		/* If the featured section is turned on, this is the HTML for it */

		var featured_HTML = '\
				<a id="MOO_featured" href="'+_this.featured_href+'"><img src="'+_this.featured_image+'" alt="'+_this.featured_name+'" /></a>';
				
		/* This is where you would edit the websites in the network to be your own sites or popular content */
				
		var moobarHTML2 ='\
				<ul id="MOO_menu" class="hide">\
					<li><a href="http://www.lghost.com.br/chat/livezilla.php" target="_blank">Iniciar Chat</a></li> \
				</ul> \
			</div>';
			
		moobar = document.createElement('div');
		moobar.id = 'moobar';
		
		/* Combine all the HTML to be embedded in your site */
		if(_this.featured){
			moobarFullHTML = moobarHTML+featured_HTML+moobarHTML2;
		} else {
			moobarFullHTML = moobarHTML+moobarHTML2;
		}
				
		document.body.appendChild(moobar);
		
		moobar = document.getElementById('moobar');
		
		/* Inserts MooBar HTML into your site below */		
		moobar.innerHTML = moobarFullHTML;
		
		var MOO_navBtn = document.getElementById('MOO_nav');
		var MOO_menu = document.getElementById('MOO_menu');
		
		/* Set up mouseover navigation effect */
		MOO_navBtn.onmouseover = MOO_menu.onmouseover = function(e){
	
			if(MOO_menu.className.match(/hide/gi)){
				MOO_menu.className = "show";
				MOO_navBtn.className = "open";
			}
			
			return false;
			
		}

		/* Set up mouseout navigation effect */
		MOO_navBtn.onmouseout = MOO_menu.onmouseout = function(e){
			
			if(MOO_menu.className.match(/show/gi)){
				MOO_menu.className = "hide";
				MOO_navBtn.className = "";
			}
			
			return false;
			
		}
	
	}
}


/* addEvent function */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

addEvent(window,'unload',EventCache.flush);
addEvent(window,'load',moobar.init);