jQuery.noConflict();

//menu click handler
jQuery('document').ready(function(){jQuery('ul.menu li').bind('click',menuSelector);});

//general handler for menus with submenus. Handles visual display of selection and the
//showing of the submenu
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu]').bind('select',menuSelect);});
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu]').bind('unselect',menuUnselect);});
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu]').bind('select',showSubMenu);});
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu]').bind('unselect',hideSubMenu);});

//handlers for gallery specific menu operation. Handles visual display of selection and
//switching to show the correct gallery item with the correct dimensions
jQuery('document').ready(function(){jQuery('ul#galleryMenu li').bind('select',menuSelect);});
jQuery('document').ready(function(){jQuery('ul#galleryMenu li').bind('unselect',menuUnselect);});
jQuery('document').ready(function(){jQuery('ul#galleryMenu li').bind('select',displayGalleryItem);});
jQuery('document').ready(function(){jQuery('ul#galleryMenu li').bind('unselect',hideGalleryItem);});

//handles opening and closing the gallery viewer itself
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu=galleryMenu]').bind('select',openGallery);});
jQuery('document').ready(function(){jQuery('ul.menu li[subMenu=galleryMenu]').bind('unselect',closeGallery);});

//handles showing and hiding the interview
jQuery('document').ready(function(){jQuery('li#interview').bind('select',menuSelect);});
jQuery('document').ready(function(){jQuery('li#interview').bind('unselect',menuUnselect);});
jQuery('document').ready(function(){jQuery('li#interview').bind('select',showInterview);});
jQuery('document').ready(function(){jQuery('li#interview').bind('unselect',hideInterview);});


//handlers for gallery navigation
jQuery('document').ready(function(){jQuery('div#galleryViewerPrevious').bind('click',function(){galleryController.showPreviousImage();})});
jQuery('document').ready(function(){jQuery('div#galleryViewerNext').bind('click',function(){galleryController.showNextImage();})});


//now trigger the starting menu item
jQuery('document').ready(function(){jQuery("li[subMenu='mrWhoMenu']").trigger('click');});


function menuSelector()
{
	var newMenu=jQuery(this);
	if(newMenu.attr('selected')) {
		return false;
	}
	
	var currentMenu=jQuery('li[selected]',newMenu.parent());
	if(currentMenu!=null) {
		currentMenu.trigger('unselect');
	}
	newMenu.trigger('select');
}


function menuSelect()
	{jQuery(this).addClass('selectedMenu').attr('selected',true);}


function menuUnselect()
	{jQuery(this).removeClass('selectedMenu').removeAttr('selected');}


function showSubMenu()
	{jQuery('#'+jQuery(this).attr('subMenu')).fadeIn('fast');}


function hideSubMenu()
{
	jQuery('#'+jQuery(this).attr('subMenu')).fadeOut('fast');
	jQuery('#'+jQuery(this).attr('subMenu') + ' li[selected]').trigger('unselect');
}



function displayGalleryItem()
{
	var galleryMenuItem=jQuery(this);	
	galleryController.resize(galleryMenuItem.attr('rotation'));
	galleryController.showImageSet(galleryMenuItem.attr('section'),galleryMenuItem.attr('count'));
}

function hideGalleryItem()
	{galleryController.hideImage();}


function openGallery()
	{galleryController.registerRequest('show',{callback:function(){jQuery('ul#galleryMenu li:first').trigger('click');}});}
	

function closeGallery()
	{galleryController.registerRequest('hide');}


function showInterview()
{
	jQuery('div#interview').css('display','block');
	galleryController.resize('full');
	galleryController.registerRequest('show');
}


function hideInterview()
	{galleryController.registerRequest('hide',{callback:function(){jQuery('div#interview').css('display','none');}});}

