//main nav - slidein menu
var slidein_menu = function() {
	var mySlidein = new Fx.Slide('main-nav-drawer', {duration: 250}).hide();

	$('main-nav').addEvents({
		'mouseenter': function(e){
			var content_status = $('main-nav-drawer').getStyle('display');
			if (content_status == 'none') $('main-nav-drawer').setStyle('display', 'block');
			e.stop();
			mySlidein.slideIn();
		},
		
		'mouseleave': function(e) {
			e.stop();
			mySlidein.cancel();
			mySlidein.slideOut();
		}		
	});
};

//main nav - dropdown menu
var dropdown_menu = function() {
	if ($('dropdown-menu') != null) {
		$('dropdown-menu').getElements('li.menu-item').each( function(elem){
			var list = elem.getElement('ul.links');
			var myFx = new Fx.Slide(list, {duration: 50}).hide();
			elem.addEvents({
				'mouseenter' : function(){		
					myFx.cancel();
					list.setStyle('display', 'block');
					myFx.slideIn();				
				},
				'mouseleave' : function(){
					list.setStyle('display', 'none');
					myFx.cancel();
					myFx.slideOut();
				}
			});
		});
	}
}

//get the height of window
var get_window_height = function() {
  var windowHeight = 0;
	
  if (typeof(window.innerHeight) == 'number')
    windowHeight = window.innerHeight;
	
  else {
		
    if (document.documentElement && document.documentElement.clientHeight)
      windowHeight = document.documentElement.clientHeight;
		
    else {
      if (document.body && document.body.clientHeight)
        windowHeight = document.body.clientHeight; }; };
				
  return windowHeight;
};

//get the height of main_content
var get_content_height = function() {
	var content_height = $('content').getSize().y;
	
	return content_height;
}


//adjust the content height if needed
var adjust_height = function () {
	var main_content_height = get_content_height();
	var window_height = get_window_height();
	if ($('custom-nav-wrapper') != null) {
		//get the site sub header height
		var custom_nav_height = $('custom-nav-wrapper').getSize().y;
		// real_height = header height + nav border height + nav height + custom nav height + main content height + footer height
		var real_height = 143 + 6 + 46 + custom_nav_height +  main_content_height + 122;
	}else {
		// real_height = header height + nav border height + nav height + main content height + footer height
		var real_height = 143 + 6 + 46 + main_content_height + 122;
	}
	
	if (real_height < window_height) {
		if ($('custom-nav-wrapper') != null) {
			//get the site sub header height
			var custom_nav_height = $('custom-nav-wrapper').getSize().y;
			var new_height = window_height - 143 - 6 - 46 - custom_nav_height - 122;
		}else {
			var new_height = window_height - 143 - 6 - 46 - 122;
		}
		var new_height_px = new_height + 'px';
		$('content').setStyle('height', new_height_px);
	}
}




window.addEvent('domready',function() {
	//slidein_menu(); //01/13/2011 X. Jing - Removed in order to update the main campus menu from the slidein style to the dropdown style
	//dropdown_menu(); //01/13/2011 X. Jing - Added in order to update the main campus menu from the slidein style to the dropdown style
	
	if ($('featured-news-container') != null) {
		/* settings */
		var showDuration = 10000;
		var container = $('featured-news-container');
		var images = container.getElements('img');
		var currentIndex = 0;
		var interval;
		var toc = [];
		var tocWidth = 15;
		var tocActive = 'toc-active';
		var news_info = $$('.news-info');
		
		news_info[0].setStyle('display','block');
		
		/* new: starts the show */
		var start = function() { interval = show.periodical(showDuration); };
		
		/* start fucntion if won't want auto slide
		var start = function() { show(); };
		*/
		var stop = function() { $clear(interval); };
		/* worker */
		var show = function(to) {
			images[currentIndex].fade('out');
			toc[currentIndex].removeClass(tocActive);
			news_info[currentIndex].setStyle('display','none');
			images[currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0))].fade('in');
			toc[currentIndex].addClass(tocActive);
			news_info[currentIndex].setStyle('display','block');
		};
		
		/* new: control: table of contents */
		images.each(function(img,i){
			toc.push(new Element('a',{
				text: i+1,
				href: '#',
				'class': 'toc' + (i == 0 ? ' ' + tocActive : ''),
				events: {
					click: function(e) {
						if(e) e.stop();
						stop();
						show(i);
					}
				},
				styles: {
					left: (550 + (i + 1) * (tocWidth + 10))
				}
			}).inject($('featured-news-handles')));
			if(i > 0) { img.set('opacity',0); }
		});
		
		/* new: control: start/stop on mouseover/mouseout */
		container.addEvents({
			mouseenter: function() { stop(); },
			mouseleave: function() { start(); }
		});
		
		
		/* start once the page is finished loading */
		start();
		
	}
	
	if ($('highlights') != null) {
		var myAccordion = new Accordion($('highlights'), 'div.toggler-handle', 'div.toggler-content', {
			opacity: 'true',
			display: '0',
			trigger: 'click',
			//height: false,
			fixedHeight: '160',
			initialDisplayFx: false,
			onActive: function(toggler, element){
				/* CMS */  toggler.setStyle('background', 'url(/bin/x/o/minus.jpg) no-repeat #FAF6E9'); 
				/* toggler.setStyle('background', 'url(/bin/x/o/minus.jpg) no-repeat #FAF6E9');*/
			},
			onBackground: function(toggler, element){
				/* CMS */ toggler.setStyle('background', 'url(/bin/d/f/plus.jpg) no-repeat #FAF6E9');
				/* toggler.setStyle('background', 'url(/bin/d/f/plus.jpg) no-repeat #FAF6E9'); */
			}
		});
	}
	
	if($('main-content') == null && $('content') != null) {
		adjust_height();
	};
});

