$(document).ready(function(){
	
	
	/* Mega DropDown Navigation */	
	$('#menu').removeClass('noJS');//remove the class so JS click replaces CSS hover
	
	$('#menu > li:not(.contact) > a').click(function(){
		$activeParent=$(this).parent('li');
		$('#menu > li.active').not($activeParent).removeClass('active'); //hides others in case 1 second mouseoff hasn't expired
		megamenu($activeParent);
		
		return false;
	});	
		
	function megamenu($obj){
		var hide;
		$obj.addClass('active'); //active class sets display to block
		
		function hideMenus(){
			$obj.removeClass('active'); //hides menu
		}
		
		$obj.hover(function(){
			if(typeof hide!=""){ //checks for existence
				clearTimeout(hide); //user has hovered back over the li, so the timeout is reset
			}
		}, function(){
			hide=setTimeout(hideMenus, 1000); //countdown to hiding list item
		});
	}
	
	/* End DropDown */
	
		   
	/* 365 Images: Switch header thumbnails to image details 
	(function detail365(){
		
		//Add Close Button
		function close($parent){
			$('#closeDetail').addClass('show');
			
			$('#closeDetail').click(function(){
				$parent.removeClass('detail');
				$(this).removeClass('show');
				return false;
			});
			return false;
		}
		
		//Open function: adds classes to show objects and calls the close function
		function open($parent){
				close($parent);
				$parent.addClass('detail');
		}
		
		//Clicking on an image starts everything off
		$('#365images a').click(function(){
			$activeParent=$(this).parent('li');
			
			if($activeParent.hasClass('retrieved')){
				open($activeParent);
			}else{
				href=$(this).attr('href');
				 $.ajax({
					url:href,
					error:function(XMLHttpRequest, textStatus, errorThrown){
						$activeParent.append(document.createElement('div'));//create a new container to hold an error message
						$newDiv=$activeParent.children('div');
						$newDiv.addClass('detail');//give the container the same styles
						$errorMsg=$newDiv.append(document.createElement('h3'));
						$errorMsg.html('Sorry, the story you were looking for could not be found. Please try another.');
						$activeParent.addClass('retrieved').addClass('error');
						open($activeParent);
					},
					success:function(data){
						//parse xml and give each part an html container. Wrap it all in a div.
						newHTML='<div class="detail">'+$(data).find('photo').text();
						newHTML+='<p class="location">'+$(data).find('location').text()+'</p>';
						newHTML+='<h3>'+$(data).find('title').text()+'</h3>';
						newHTML+='<p>'+$(data).find('text').text()+'</p>';
						newHTML+='<p class="readMore">'+$(data).find('readmore').text()+'</p>';
						newHTML+='</div>';
 						$activeParent.append(newHTML); //Place it inside of its parent div
						$newImg=$activeParent.children('div.detail').children('img');//Collage outputs site relative srcs for images, so since ajax changes the location, we have to change it manually to be root relative.
						var regexp = /(\w|[-.])+$/;
						newSrc = regexp.exec($newImg.attr('src')); //RegEx retrieves the filename of the image
						$newImg.attr('src', ('/media/images/global/du365/365Images/' + newSrc[0] ));
						$activeParent.addClass('retrieved');
						open($activeParent); 
					}
				});  
			}
			
			return false;
		});
	})();*/
	/* End 365 Images */
	
	
	/* YouTube Playlist */
	$(function(){
		$("ol.youTubePlaylist").ytplaylist({
			holderId: 'youTubeContainer',
			autoPlay:false,
			playerWidth: 264,
			playerHeight:210
		});
	});
});


