// load the additional stylesheet //
new Element('link', {'rel': 'stylesheet', 'media': 'screen', 'type': 'text/css', 'href':'homemenu/homemenu.css' }).inject(document.head);

// link data for the menu //
var LinkData = {};

LinkData.future_students = 	[
                           	 {href:'http://www.capital.edu/148/', title:'APPLY'}, 
                           	 {href:'http://www.capital.edu/68/', title:'ACADEMICS'}, 
                           	 {href:'http://www.capital.edu/future_students/why-capital.html', title:'WHY CAPITAL'}
                            ];
LinkData.parents = 			[
                   			 {href:'http://www.capital.edu/6761/', title:'PARENTS NETWORK'}, 
                   			 {href:'http://www.capital.edu/3043/', title:'HEALTH CLINIC'}, 
                   			 {href:'http://www.capital.edu/24427/', title:'ADMISSIONS'}
                   			];
LinkData.alumni = 			[
                  			 {href:'http://www.capital.edu/289/', title:'GIVE BACK'}, 
                  			 {href:'http://www.capital.edu/69/', title:'ARTS & ENTERTAINMENT'}, 
                  			 {href:'http://www.capital.edu/23705/', title:'ALUMNI COMMUNITY'}
                  			];
LinkData.students = 		[
                    		 {href:'https://webmail.capital.edu/', title:'WEBMAIL'}, 
                    		 {href:'http://inside.capital.edu', title:'INSIDE.CAPITAL.EDU'}, 
                    		 {href:'http://www.capital.edu/20632/', title:'DAILY SHEET'}, 
                    		 {href:'http://www.capital.edu/87/?filter-by=1167', title:'EVENTS'}
                    		];
LinkData.faculty = 			[
                   			 {href:'http://inside.capital.edu', title:'INSIDE.CAPITAL.EDU'}, 
                   			 {href:'http://blackboard.capital.edu/', title:'BLACKBOARD'}, 
                   			 {href:'http://www.capital.edu/faculty.html', title:'ALL RESOURCES'}, 
                   			 {href:'http://www.capital.edu/20632/', title:'DAILY SHEET'}
                   			];



/**
 * Homepage Menu controller class
 */
var HomepageMenu = new Class(
{
	initialize: function(canvas)
	{
		this.canvas = canvas;
		this.canvas.getElements('a').each(function(el){new MenuItem(el);});
	}
});

/**
 * Represents a single menu row.
 */
var MenuItem = new Class(
{
	
	initialize: function(button)
	{
		this.button = button;
		var coords = this.button.getCoordinates();
		
		this.top = coords.top;
		this.left = (Browser.Engine.trident && (Browser.Engine.version < 5)) ? 178:188;           //button.getParent().getSize().x;
		this.height = 220;
		this.offset = 190 + 25;
		this.cls = button.getProperty('class').replace('-shader', '').replace('-', '_');
		

		// is this hack'y or what? //
		if (this.cls == 'faculty' || this.cls == 'parents') { this.height = 240; }
		
		// create a wrapper around the button //
		this.canvas = new Element('div',{'class':'homemenu-item'});
		this.canvas.wraps(this.button);
		
		// create a rollover hotspot corner thingy //
		var hotspot = new Element('div', {style:'position:absolute;height:9px;left:10px;background-color:transparent;', html:'&nbsp;'});
		hotspot.setStyles({'width':coords.width, 'top':coords.height});
		this.canvas.grab(hotspot);
		
		// create the block part of the menu //
		this.block = new Element('div',{'class':'homemenu-block', html:'&nbsp;'});
		this.block.setStyles({'height': this.height, 'left':this.left, 'position':'absolute'});
		this.block.setStyle('background-image', 'url(homemenu/' + this.cls + '_block.png)');
		this.addHTML();
		this.canvas.grab(this.block);
		
		this.img = new Element('div',{'class':'homemenu-img'});
		this.img.setStyles({'height': this.height, 'left':this.left, 'position':'absolute'});
		this.img.setStyle('background-image', 'url(homemenu/' + this.cls + '_img.png)');
		this.canvas.grab(this.img);
		
		this.canvas.addEvent('mouseleave', this.hide.bind(this));
		this.button.addEvent('mouseenter', this.show.bind(this));
		
		this.button.store('cls', this.button.getProperty('class'));

	},
	
	addHTML: function()
	{
		var links = new Element('div', {'class':'the-links ' + this.cls + '_links'});
		links.setStyle('opacity', 0);
		links.set('tween',{duration: 400, transition:Fx.Transitions.Cubic.EaseIn});
		
		var a = new Element('a',{'class':'homemenu-link1', href:this.button.getProperty('href'), title:this.button.getProperty('title'), text:'GET STARTED'});
		links.grab(a);
		
		LinkData[this.cls].each( (function(link)
		{
			new Element('a', {title:link.title, href:link.href, html:'&#187; ' + link.title}).inject(this);
		}).bind(links));
		
		this.block.empty();
		this.block.grab(links);
	},
	
	hide: function()
	{
		this.block.set('morph', {duration:200, transition:Fx.Transitions.Cubic.easeIn});
		this.img.set('morph', {duration:200, transition:Fx.Transitions.Cubic.easeOut});	
		
		this.block.getFirst().tween('opacity', 0);
		
		this.block.morph({'width':0, 'opacity':1});
		this.img.morph({'width': 0, 'opacity':1});
		
		this.button.setProperty('class', this.button.retrieve('cls'));
	},
	
	show: function()
	{
		this.block.set('morph', {duration:200, transition:Fx.Transitions.Cubic.easeOut});
		this.img.set('morph', {duration:300, transition:Fx.Transitions.Cubic.easeIn});	
		
		this.block.setStyle('opacity', 1);
		this.img.setStyle('opacity', 1);
		
		this.block.morph({'width':this.offset});
		this.img.morph({'width': this.offset + (360 - 25)});
		
		this.block.getFirst().tween('opacity', 1); //delay(400, this.block.getFirst(), ['opacity', 1]);
		
		this.button.setProperty('class', this.button.retrieve('cls').replace('-shader', ''));
	}
});

/**
 * hook everything up on when the DOM is ready
 */
window.addEvent('domready', function()
{
	// hack'y IE thing //
	$try($$('td.column3.home, td.column3.home div').setStyle('position','static'));
	
	// grab the side buttons //
	var el = $(document.body).getElement('div.main-links');
	
	// hook up the js menu code //
	new HomepageMenu(el);
	
	// flash //
	var swf = new Swiff('flash/home.swf' + (Browser.Engine.trident? '?rand=' + new Date().getTime() : ''),
	{
		id:'VideoPlayer',
		width:562,
		height:496,
		params:{quality:'high',salign:'lt',scale:'default', bgcolor:'#FFFFFF',loop:'false', align:'left', wmode:'window',allowScriptAccess:'always'},
		vars:{},
		callBacks:{}
	}); 
	
	this.swfzone = $(document.body).getElement('td.column3');
	this.swfzone.empty();
	this.swfzone.adopt(swf);
	
});