$(document).ready(function(){
	
	// sizing within events box
	var isCurrentEvent = $('.box_blue .box_inner').next();
	if(isCurrentEvent = $('.box_blue .today')) {
		var parentHeight = $('.box_blue .today').height();
		$('.today .day').css('height', parentHeight + 'px');
	}
	
	// navigation + dropdowns
	$('ul.navigation li.children ul').each(function(){
		var parentWidth = $(this).parent('li').width();
		var linkWidth = 0;
		var maxWidth = 0;
		
		$(this).children('li').each(function() {          
		    if($(this).width() > maxWidth) {  
		        maxWidth = $(this).width(); 
		    }  
		});  
			
		linkWidth = maxWidth;
		
		if(linkWidth > 150){
			$(this).find('li a b').css('width', '150px');		
		} else if(linkWidth > parentWidth){
			$(this).find('li a b').css('width', linkWidth + 'px');
		} else {
			$(this).find('li a b').css('width', parentWidth + 'px');
		}
		return;
	});			
			
	$('ul.navigation li.children').hover(
		function(){
			$(this).addClass('hover');
			if($(this).hasClass('active')) {
				$(this).addClass('is_active');
				$(this).removeClass('active');
			}
			$(this).find('ul').show();
		},
		function(){
			$(this).removeClass('hover');
			if($(this).hasClass('is_active')) {
				$(this).addClass('active');
				$(this).removeClass('is_active');
			}
			$(this).find('ul').hide();
		}
	);
		
	// navigation name levels of li
	$('ul.navigation').each(function() { 
		$(this).children('li').addClass('level_1');
		$('.level_1 ul').each(function() { 
			$(this).children('li').addClass('level_2');
		});
	});
	


	$('.magazine_thumb img').rotateLeft(9);
	
	
	$('.event_details a.button').click(function(){
			$(this).parent('div').next('.description').slideToggle(250);
			return false;
	});
			
			
	// Returns anchor from link string
	var hash = false; 
	checkHash();
	
	function checkHash(){ 
	    if(window.location.hash != hash) { 
	        hash = window.location.hash; 
	        processHash(hash); 
	    }
	}
	
	function processHash(hash){
		var cleanHash = hash.replace("#", "");
	    //alert('.description.' + cleanHash);
		$('.description.' + cleanHash).slideToggle(250);
	}
	
	$('.box_blue.calendar .button').click(function() {
		var hashID = $(this).attr('id');
		processHash('#' + hashID);
	});
			
	/*

	// manage heights of carousel pages
	var maxHeight = 0;  
	  
	function setHeight(item) {  
	
		item = $(item)
		item.each(function() {          
		    		  
		    		  
		    console.info("height:" + $(this).height());

		    if($(this).height() > maxHeight) {  
		        maxHeight = $(this).height(); 
		    }
		   console.info("max height:" + maxHeight);
		});  

		item.css('height', maxHeight + 'px');
	}
	 
	setHeight('.carousel_content .caption .carousel_footer');  
	var carouselTotal = maxHeight + 330;
	
	console.info("final height:" + carouselTotal);

	$('.carousel, .carousel_cycle').css('height', carouselTotal + 'px');
	
	*/
	
	$('.carousel_cycle').cycle({ 
	    fx: 'fade',
	    timeout:  5000,
		pager:  '.carousel_nav',
		cleartype:  true,
	    cleartypeNoBg:  true
	});	
	
});


