/***********************************************************************/
/* Billboard Control
/***********************************************************************/
animationSpeed = 700;
fadeSpeed = 700;
newsPanelExpanded = true;

numberOfThumbs = 32;
var gallery01Array = [
"",
"<b>Stacey Allaster</b>, EMBA '00, Chairman & CEO, Sony Ericsson Women's Tennis Association Tour", 
"<b>Michael Copeland</b>, MBA '99, COO Canadian Football League",
"<b>George Cope</b>, HBA '84, President and CEO, BCE Inc and Bell Canada",
"<b>Kevin O'Leary</b>, MBA '80, Partner NorthCoast Capital, Star of CBC's popular Dragon's Den",
"<b>Sarah Morgenstern</b>, MBA '93, Publisher & Co- Founder, Savvymom.ca", //5
"<b>Michael Hill</b>, HBA '89, Managing Director, Deutsche Bank",
"<b>Judith Adams</b>, MBA '86, VP & Global Partner, Invesco Trimark",
"<b>Teri Currie</b>, EMBA '98, Executive VP, Human Resources, TD Bank",
"<b>John McNain</b>, HBA '93, VP Strategy and Marketing, Capital One",
"<b>Michael McCain</b>, HBA '79, President and CEO, Maple Leaf Foods", //10
"<b>Christine Magee</b>, HBA '82, President and Co-Founder, Sleep Country Canada",
"<b>Hugh MacDiarmid</b>, HBA '74, President and CEO, Atomic Energy of Canada",
"<b>David Cornhill</b>, MBA '80, Chairman and CEO, AltaGas Income Trust",
"<b>Paul Sabourin</b>, MBA '80, Chairman & Chief Investment Officer, Polar Securities",
"<b>Pierre Morrissette</b>, MBA '72, President, CEO, Co-Founder, Pelmorex-The Weather Network", //15
"<b>Larry Rosen</b>, MBA/LLB '82, Chairman and CEO, Harry Rosen Inc.",
"<b>Paul Hill</b>, MBA '69, President and CEO, Harvard Developments Inc",
"<b>Andy Chisholm</b>, MBA '85, Managing Director, Investment Banking, Goldman Sachs ",
"<b>Jeff Orr</b>, HBA '81, President and CEO, Power Financial Corporation",
"<b>Rod White</b>, HBA '74, Associate Dean, Faculty Development & Research Associate, Ivey", //20
"<b>Arkadi Kuhlmann</b>, HBA '71, MBA '72, Chairman and CEO, ING Direct US",
"<b>Tim Hockey</b>, EMBA '97, President and CEO, TD Canada Trust",
"<b>Kevin O'Brien</b>, HBA '93, VP Strategy & Planning, Aeroplan & Chair, IAA",
"<b>Michael Kanovsky</b>, MBA '73, President, Sky Energy Corp.",
"<b>Luke Sklar</b>, HBA '78, Partner, Sklar Wilton and Associates", //25
"<b>Jay Bertram</b>, HBA '83, President, TBWA/Canada",
"<b>Will Meijer</b>, HBA '96, Vice President - Ontario, Molson Coors Canada",
"Ivey has more alumni on Canada's Top 40 under 40 than any other  business school.",
"<b>Kelly Duffin</b>, EMBA '02, President and CEO, Canadian Hearing Society",
"<b>Laurie Campbell</b>, MBA '89, Managing Director, Bank of America",  //30
"<b>Randy Jang</b>, MBA '77, President AE Systems Limited",
"<b>Brian Moore</b>, HBA '78, Director of Golf Operation, Niagara Parks Commission",
"<b>Seonag Macrae</b>",
"<b>Gilles Ouellette</b>",
"<b>Lisa Colnett</b>",
"<b>John McNain</b>, HBA '93, VP Strategy and Marketing, Capital One",
"<b>Don Mcdougall</b>",
"<b>Don Woodley</b>",
"<b>Sylvia Chrominska</b>",
"<b>Scott Beattie</b>",
"<b>Arkad Kuhlman</b>, HBA '71, MBA '72, Chairman and CEO, ING Direct US",
"<b>Kelly Duffin</b>, EMBA '02, President and CEO, Canadian Hearing Society"
];

$(document).ready(function()
{
	insertGalleryThumbs("panelGallery01");
	
	/* Initial Object Fade */
	hidePanelItems();
	hideSubPanels();
	$(".bgImageFade").fadeTo(0, 0.0);
	$(".newsBGImageFade").fadeTo(0, 0.6);
	$(".panelTab").fadeTo(0, 0.8);
	$('#billboard #learnMore').hide();
	$('#billboard #learnMore').fadeIn(fadeSpeed);

	/* Hide/Show Items */
	function hidePanelItems(){
		$('.PanelSubMenuFade, .panelContent, .subPanelContainer').fadeTo(fadeSpeed, 0.0);	}

	function showPanelItems(panel){
		$('#'+panel+' .PanelSubMenuFade').fadeTo(fadeSpeed, 0.8);
		$('#'+panel+' .panelContent').fadeTo(fadeSpeed, 1.0);
		$('#'+panel+' .panelContent .defaultPage').css("display","inline");				
		$('#'+panel+' .panelContent .defaultPage').fadeTo(fadeSpeed, 1.0);		
	}
	
	/* newsPanel Expand/Collapse */
	$("#newsPanel #expandCollapse").click(function()
	{			
		if(newsPanelExpanded){
			$("#newsPanel").animate({
					left: "-=165px"
				},animationSpeed);
			$(this).toggleClass("collapsed");
			newsPanelExpanded = !newsPanelExpanded;
		}
		else{
			hidePanelItems();
			$("#newsPanel").animate({
					left: "+=165px"
				},animationSpeed);
			$(".billboardPanel").each(function(){
				if($(this).width() > 50)
				{
					$(this).animate({
						width: '-=822'
					},{queue:true, duration:animationSpeed} );
				}
			});
			$(this).toggleClass("collapsed");				
			newsPanelExpanded = !newsPanelExpanded;	
			selectTab($('#billboardpanel01 .panelTab'));
			$('#billboardpanel01 .panelTab').addClass("firstPanel");
			$('#billboard #learnMore').fadeIn(fadeSpeed);
			showLearnMore();
		}
	});

	/* Panel Behavior */
	$(".billboardPanel .unselected").hover(function()
	{
		if( $(this).attr("src").toString().lastIndexOf("Off.gif") > 0 && ($(this).hasClass("unselected"))  )
			$(this).attr("src", $(this).attr("src").toString().slice(0, $(this).attr("src").toString().lastIndexOf("Off.gif"))+"On.gif");
	},function(){
		if( $(this).attr("src").toString().lastIndexOf("On.gif") > 0 && ($(this).hasClass("unselected")) )
			$(this).attr("src", $(this).attr("src").toString().slice(0, $(this).attr("src").toString().lastIndexOf("On.gif"))+"Off.gif");
	});
	
	$(".billboardPanel .panelTab").click(function()
	{	
		if( $(this).attr("class").match("unselected") || $(this).attr("class").match("firstPanel") )
		{
			hideSubPanels();
			$(this).removeClass("firstPanel")
			hideLearnMore();
			$(".bgImageFade").fadeTo(fadeSpeed, 0.0);				
			selectTab($(this));
			togglePane($(this));
		}
		else
		{
			hideSubPanels();
			$(".bgImageFade").fadeTo(fadeSpeed, 0.0);						
			$(this).siblings(".panelContent").children(".defaultPage").css("display","inline");
			$(this).siblings(".panelContent").children(".defaultPage").fadeTo(fadeSpeed, 1.0);
		}
	});
	function selectTab(tab)
	{
		$(".billboardPanel .panelTab").each(function()
		{
			$(this).addClass("unselected");
			if( $(this).attr("src").toString().lastIndexOf("On.gif") > 0 )
				$(this).attr("src", $(this).attr("src").toString().slice(0, $(this).attr("src").toString().lastIndexOf("On.gif"))+"Off.gif");
		});
		$(tab).removeClass("unselected");
		if( $(tab).attr("src").toString().lastIndexOf("O") > 0 )
			$(tab).attr("src", $(tab).attr("src").toString().slice(0, $(tab).attr("src").toString().lastIndexOf("O"))+"On.gif");
		$(".listTitle").css("color","#fff");
	}
	function togglePane(panel){
		if(newsPanelExpanded) $("#newsPanel #expandCollapse").click();
		hidePanelItems();
		$(".billboardPanel").each(function(){
			if( ($(this).offset().left <= $(panel).offset().left) && ($(this).width() <= 36) ){
				$(this).animate({
					width: '+=822'
				},{queue:true, duration:animationSpeed});}
			else if( ($(this).offset().left > $(panel).offset().left) && ($(this).width() > 821 ) ){
				$(this).animate({
					width: '-=822'
				},{queue:true, duration:animationSpeed});}
		});
		showPanelItems($(panel).parent().attr("id"));
	}
	
	/* Post Load Variable Settings */
	selectTab($('#billboardpanel01 .panelTab'));

	/* Learn More Click */
	$('#billboard #learnMore').click(function()
	{
		hideLearnMore();
		$("#billboardpanel01 .panelTab").click();
	});
	function hideLearnMore()
	{		$('#billboard #learnMore').fadeOut(fadeSpeed/2, 0.0);	}
	function showLearnMore()
	{		$('#billboard #learnMore').fadeIn(fadeSpeed, 1.0);	}
	
	function hideSubPanels()
	{
		$('.subPanelContainer').css("display","none");
	}
	$(".listTitle").click(function()
	{
		if( ($(this).parent().children("ul").length > 0))
		{
			$(this).parent().parent().parent().siblings(".bgImageFade").fadeTo(fadeSpeed, 0.0);
		}
		else if( $(this).parent().parent().parent("li").length > 0 ) 
		{
			$(this).parent().parent().parent().parent().parent().siblings(".bgImageFade").fadeTo(fadeSpeed, 0.7);
		}
		else
		{
		 	$(".bgImageFade").fadeTo(fadeSpeed, 0.7);	
		}
		hideSubPanels();
	
		$(".listTitle").css("color","#fff");
		$(this).css("color", "#ffc82e");
		$(this).siblings(".subPanelContainer").css("display","block");
		$(this).siblings(".subPanelContainer").fadeTo(fadeSpeed, 1.0);
	});	
	function insertGalleryThumbs(galleryID)
	{
		for(i = 1; i<=numberOfThumbs; i++)
		{
			$("#"+galleryID+" .panelGalleryGrid").append("<img src='http://www.ivey.uwo.ca/images/billboard/gallery01/"+i+".jpg' alt='' />");
			$("#"+galleryID+" .panelGalleryGrid img").fadeTo(0, 0.8);
		}
		$("#"+galleryID+" .panelGalleryView div").append("<img src='http://www.ivey.uwo.ca/images/billboard/gallery01/full/"+1+".jpg' alt='' />");
		$("#"+galleryID+" .panelGalleryView div").append("<p>"+gallery01Array[1]+"</p>");
	}
	
	$(".panelGalleryGrid img").hover(function()
	{  $(this).fadeTo(0, 1.0); }, function(){	$(this).fadeTo(fadeSpeed, 0.7);	});
	$(".panelGalleryGrid img").click(function()
	{
		$("#panelGallery01 .panelGalleryView img").attr("src",$(this).attr("src").slice(0,$(this).attr("src").lastIndexOf('/'))+"/full"+($(this).attr("src").slice($(this).attr("src").lastIndexOf('/'),$(this).attr("src").length)));
		$("#panelGallery01 .panelGalleryView p").html(gallery01Array[parseInt($(this).attr("src").slice( $(this).attr("src").lastIndexOf('/')+1, $(this).attr("src").lastIndexOf('.') ) )]);
	});
	newsFeedCurrentItem = 1;
	function fadeNewsArrows()
	{
		if (newsFeedCurrentItem == 1)
		{
			$("#arrowControl #upArrow").fadeTo(0, 0.2);
		}
		else
			$("#arrowControl #upArrow").fadeTo(0, 1.0);
		
		if (newsFeedCurrentItem == ($("#newsFeed01").children("div").length - 1) )
		{
			$("#arrowControl #downArrow").fadeTo(0, 0.2);
		}
		else
			$("#arrowControl #downArrow").fadeTo(0, 1.0);
	}
	fadeNewsArrows();
	$("#arrowControl #downArrow").click(function()
	{
		if(newsFeedCurrentItem <= ($("#newsFeed01").children("div").length - 2) )
		{
			$("#newsFeed01").animate({
				top: '-=80'
			},{queue:true, duration:300});
			newsFeedCurrentItem++;
			$('body').append($("#newsFeed01").children("div").length);
		}
		fadeNewsArrows();		
	});
	$("#arrowControl #upArrow").click(function()
	{
		if(newsFeedCurrentItem > 1 )
		{
			$("#newsFeed01").animate({
				top: '+=80'
			},{queue:true, duration:300});
			newsFeedCurrentItem--;
		}
		fadeNewsArrows();		
	});
	$(".subPanelContainer .subPanelCopy a.nextMenuItem").click(function()
	{
		if( $(this).parent().parent().attr("class").match("defaultPage") ) 
			$(this).parent().parent().next().children("li").children("div.listTitle:first").click();
		else if( $(this).parent().parent().parent().children("ul").length > 0)
			$(this).parent().parent().parent().children("ul").children("li:first").children(".listTitle").click();
		else if( ($(this).parent().parent().parent().next().length == 0) && ($(this).parent().parent().parent().parent().parent().next().length > 0 ) )
			$(this).parent().parent().parent().parent().parent().next().children(".listTitle").click();
		else if($(this).parent().parent().parent().next().length == 0)
			$(this).parent().parent().parent().parent().parent().parent().next().children(".panelTab").click();
		else
			$(this).parent().parent().parent().next().children(".listTitle").click();			
	});
	var logoCurrentItem = 3;
	$(".panelContent .subPanelContainer .logoPan #logoRight").click(function()
	{
		if (logoCurrentItem < ($(this).siblings(".logoSlider").children().children().length ) )
		{
			$(this).siblings(".logoSlider").children().animate({
						left : '-=166'
					},{queue:true, duration:animationSpeed});
			logoCurrentItem++;
		}
	});
	$(".panelContent .subPanelContainer .logoPan #logoLeft").click(function()
	{
		if (logoCurrentItem > 3)
		{
			$(this).siblings(".logoSlider").children().animate({
						left : '+=166'
					},{queue:true, duration:animationSpeed});
			logoCurrentItem--;
		}
	});
});

