/*
Written by Pankaj L Ahire
Uses Mootools

DO NOT MODIFY IF YOU DO NOT KNOW WHAT YOU'RE DOING.
Contct Pankaj at pankajahire [at] gmail [dot] com

*/


var glbt = {
	
	setupAnimation:
	function()
	{
		glbt.abubble();
		
		var timer = 0;
		var menuItems = $$('#nav li');
		var glbtColors = ['#FF0000','#FFA500','#FFCF00','#008000','#0000FF','#4B0082'];
		
		var toggled = $$('.toggler');
		var togcontent = $$('.togcontent');
		
		
		
		var glbtaccordion = new Accordion(toggled,togcontent);
		
		
		toggled.each(function(el,i)
					 {
						 
						 el.setStyle('background-color',glbtColors[i]);
						 el.addEvent(
							 'mouseover',
							 function()
							 {
								 this.fireEvent('click');
								 glbt.showAnImage(i);
								 
							 }
						 );
					 },
					 this);
								  
		
		
		menuItems.each(function(el,i)
					   {
							
							el.addEvent
							(
							 'mouseenter',
							 function()
							 {
								 var myfx = new Fx.Morph(this,
														 {duration: 'short',
														 transition: Fx.Transitions.Sine.easeOut}
														 );
								
								myfx.start(
									{
										'background-color': ['#CCCCCC', glbtColors[i%6]]
									}
									);
							 }
							 );
							
							el.addEvent
							(
							 'mouseleave',
							 function()
							 {
								 var myfx = new Fx.Morph(this,
														 {duration: 'short',
														 transition: Fx.Transitions.Sine.easeOut}
														 );
								 myfx.start(
									{
										'background-color': [glbtColors[i%6], '#CCCCCC'],
										'z-index' : '5'
									}
									);
							 }
							 );
					   },
					   this);
	},
	
	showAnImage:
	function(i)
	{
		var imgCollection = $$('#mImages img');
		i = i%imgCollection.length;
		
		var count = 0;
		while(count < imgCollection.length)
		{
			if(count == i)
			{
				imgCollection[count].setStyle('display','inline');
			}
			else
			{
				imgCollection[count].setStyle('display','none');
			}
			count++;
		}
	},
	
	abubble:
	function() 
	{
		var myPages = $$('.page');
		var myBubbles = $$('.bubble');
		
		var histVideo = $('#histBub');
		var histCancel = $('#histCncl');
		
		myBubbles.setStyle('opacity', 0);
		$('bubbleWrap').setStyle('visibility','visible');
	
		myPages.each(
					 function(el, i) 
					 {
						el.set('morph', {link : 'cancel'});
		
						el.addEvents({
							'mouseenter': 
							function() 
							{	
								myBubbles[i].morph({'opacity' : 1, 'margin-top' : '-15px'});
								if(i == 3)
								{
									histCancel.addEvent('click',function(){ myBubbles[i].morph({'opacity' : 0, 'margin-top' : 0})});
								}
							
							},
							
							'mouseleave' : 
							function() 
							{
								if(i == 3)
								{
								}
								else
								{
									myBubbles[i].morph({'opacity' : 0, 'margin-top' : 0});
								}
							}	
									});
						
					}
				  );
		
	}
				
	
};
					   
																					  

window.addEvent('domready', glbt.setupAnimation);


