var bodyobj, ibar, menus = [];

/// -> LiveScience 
menus.push({title:"LiveScience",
			img:"livescience_logo.gif",
			desc:"Groundbreaking developments in health, environment, animals, technology and space",
			lnk:"http://www.livescience.com",
			lnk_name:"LiveScience" });
/// -> Space 
menus.push({title:"SPACE.com",
			img:"space.com_logo.gif",
			desc:"Space science, astronomy and exploration",
			lnk:"http://www.space.com",
			lnk_name:"Space" });
/// -> Newsarama 
menus.push({title:"Newsarama",
			img:"newsarama_logo.gif",
			desc:"Previews, reviews and commentary of comic books and genre entertainment including movies and TV shows",
			lnk:"http://www.newsarama.com",
			lnk_name:"Newsarama" });
/// -> TopTenReviews
menus.push({title:"TopTenREVIEWS",
			img:"ttr_logo.gif",
			desc:"Expert Product Reviews. We Do the Research So You Don't Have To",
			lnk:"http://www.toptenreviews.com",
			lnk_name:"TopTenREVIEWS" });



var imenu = Class.create({
	initialize: function() {
		bodyobj = document.getElementsByTagName("body").item(0);
		new Insertion.Top(bodyobj, new Element('div', { 'id': 'ibar' }));
		
		try{	
			var dl = new Element('dl').insert('<dt><a href="http://www.techmedianetwork.com/" class="none" name=""><img src="http://images.livescience.com/common/template_images/ibar/ibar_tmn_logo.gif" alt="TechMediaNetwork" width="95" height="24"></a></dt>');
			$('ibar').insert(new Element('div', { 'class': 'wrapper' }).insert(dl));
			
			menus.each(function(a, index) { 
				var str = '<a href="javascript:ibar.act('+index+')"><img src="http://images.livescience.com/common/template_images/ibar/blue_arrow.gif"></a>';
				str += '<a href="'+ a.lnk +'" name="&lid=Bug_'+ a.lnk_name +'">'+ a.title +'</a>';
				
				var m = new Element('dt',{ 'id': 'inav_'+index }).update(str);
				dl.insert(m);
			
				str = '<div><a href="'+ a.lnk +'"><img src="http://images.livescience.com/common/template_images/ibar/'+ a.img +'" alt="'+ a.title +'"></a>';
				str += '<p>'+ a.desc +'</p>';
				str += '<a href="'+ a.lnk +'">Go to Site</a></div>';
				
				var d = new Element('dd',{ 'id': 'idrop_'+index, 'style':'left:'+(m.positionedOffset()[0]-15)+'px; top:0px; display:none;' }).insert(str);
				dl.insert(d);
				
			});
			Event.observe(window, 'resize', function(){
				if(self.innerHeight)
					var ow = 0;
				else
					var ow = (document.body.offsetWidth - $('inav_0').parentNode.parentNode.getDimensions().width) / 2;
					menus.each(function(a, index){ 
					$('idrop_'+index).style.left = $('inav_'+index).viewportOffset()[0]+ow+"px";
				});
			});
		} catch(err) {
			alert(err)
			$('ibar').remove();
		}
		
	},
	act: function(n) {
		if (typeof dropmenuobj != "undefined") ibar.hide(dropmenuobj);
		dropmenuobj = $('idrop_'+n);
		//new Effect.SlideDown(dropmenuobj,{duration:0.75});
		dropmenuobj.style.display = 'block';
		var l = $('inav_'+n).positionedOffset()[0];
		var w = l + dropmenuobj.getDimensions().width;
		Event.observe(bodyobj, 'mousemove', function(e){
			if(e.pageX > w || e.pageX < l || e.pageY > 160) ibar.hide(dropmenuobj);
		});
	},
	hide: function() {
		//new Effect.SlideUp(dropmenuobj,{duration:0.25});	
		dropmenuobj.style.display = 'none';
		Event.stopObserving(bodyobj, 'mousemove');
	}
});

Event.observe(window, 'load', function(){ ibar = new imenu });
