	/*
 Author: Roy Lindauer
 Project: UNR Res Life
 Date: July 2009
 Version: 1.0
*/

$(document).ready(function(){
	/* xhtml valid target=_blank alternative */
	$('.popup').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	/* main menu */
	$('#menu_wrapper').hide();
	$('.menu').hide();
	var menuOpen = false;
	
	$('.mm_link').mouseover(function(){
		$('.mm_link').removeClass('selected');
		$('.menu').hide();
		if (menuOpen == false)
		{
			$('#menu_wrapper').fadeIn('fast');
			menuOpen = true;
		}
		var elem = $(this).attr('rel');
		$(this).addClass('selected');
		$('#'+elem).fadeIn('fast');
	});
	$('#menu_wrapper').bind('mouseleave',function(){
		$(this).fadeOut('fast');
		//$(this).next('.menu').fadeOut('fast');
		$('.mm_link').removeClass('selected');
		menuOpen = false;
	});
	
	$('#main_menu a').mouseleave(function(){
		$('.mm_link').removeClass('selected');
	});
	
	/* Widget */
	$('a[href=' + window.location.hash + ']').addClass('selected');
	
	$('a[rel=ajax]').click(function () {
		//$.scrollTo($('#widget'), {duration:500}); This was moved to after the window open to resolve scroll issues
		var hash = this.href;
		hash = hash.replace(/^.*=/, '');
		
		$('a[rel=ajax]').removeClass('selected');
		$(this).addClass('selected');
		$('#widget_content').hide();
		$('.loading').show();
		
		getPage(hash);

		return false;
	});	
	
	$('.stripeme tr:even').addClass('alt');
	$('.stripeme tr').mouseover(function(){
		$(this).addClass('over');
	});
	$('.stripeme tr').mouseout(function(){
		$(this).removeClass('over');
	});
	
});
		
	function getPage(hash) {
		var data = 'p=' + encodeURIComponent(hash);
		$.ajax({
			url: "loader.asp",	
			type: "GET",		
			data: data,		
			cache: false,
			success: function (html) {	
				$('.loading').hide();
				$('#widget_content').html(html);
				$('#widget_content').slideDown(
					function(){
						$(this).append('<a href="" class="close"></a>');
						$('.close').hide();
						$('.close').fadeIn();
						$('.close').click(function(){
							$('#widget_content').slideUp('slow');
							$('a[rel=ajax]').removeClass('selected');
							$(this).hide();
							return false;
						});
						$.scrollTo($('#widget'), {duration:500});
					}
				);
				
				$('.roll a').hover(function(){
					$(this).find('span:first').show();
				},
				function(){
					$(this).find('span:first').hide();
				});
			}		
		});
	}
	
	function getMenu(hash) {
		var data = 'm=' + encodeURIComponent(hash);
		$.ajax({
			url: "loader.asp",	
			type: "GET",		
			data: data,		
			cache: false,
			success: function (html) {	
				$('.menu').html(html);
			}		
		});
	}