jQuery(document).ready(function($){
//if(!$('body.ie6').length){
	
	
	//target=_blank for rel=external links
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});


	//truncate event description
	$('.eventDescription .postContent').truncate({max_length: 800});
	
	
	
		//featured event carousel (only activates when there is more than 4 featured events)
		if($('.featuredCarousel.multi .container:visible').length){
			$('.featuredCarousel.multi').append('<div class="navigation"><a id="carouselPrevious"><span>Previous</span></a><a id="carouselNext"><span>Next</span></a></div>');
			$('.featuredCarousel.multi .container').carousel('#carouselPrevious', '#carouselNext');
		}
		
		//if the title gets too big, then add a scroll js pane, otherwise, keep make it auto-height
		if($('.featuredCarousel').length){
			var fcHeightLimit = $('.featuredCarousel .eventTitle').height();
			$('.featuredCarousel .eventTitle').css("height","auto").each(function(){
				var fcTitleHeight  = $(this).height();
				if(fcHeightLimit <= fcTitleHeight){
					$(this).css("height",fcHeightLimit).jScrollPane();
				}
			});
		}
		
		//center the featured shows if there is less than 4
		if($('.featuredCarousel .container:visible').length){
			if($('.featuredCarousel .container:visible .carouselCart').children().size() < 4){
				var featuredWidth = 0;
				var cartWidth = $('.featuredCarousel .container:visible .carouselCart').width();
				
				$('.featuredCarousel .container:visible .carouselCart .eventFeatured').each(function() {
					featuredWidth += $(this).width();
				});
				
				var cartCenter = ((cartWidth - featuredWidth ) / 2) - 40;
				$('.featuredCarousel .container:visible .carouselCart').addClass('centered');
				$('.featuredCarousel .container:visible .cartFirst').css('margin-left', cartCenter+'px');
				//alert('featuredWidth:'+featuredWidth+' cartCenter:'+cartCenter);
			}
		}
	
	
	
	
	//scroll panes
	//$('.featuredCarousel .eventTitle').jScrollPane();
	$('.eventsList.type4 .mainInfo .holder').jScrollPane();
	
	
	
	//pretty photo plugin for lightbox
	// http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation/
	$("a[rel^='prettyPhoto'], .videoLink a, .mapLink, a.video").prettyPhoto({
		theme: 'facebook' // light_rounded / dark_rounded / light_square / dark_square / facebook 
	});



	//poster animation	
    $('.postersWidget').cycle({
		timeout:6000
	});

	if($('.eventListing .moreInfoPanel').length){
		alert($('.eventListing .moreInfoPanel').length);
		
		function closeOtherMoreInfoPanels(){
			$('.moreInfoPanel:visible').hide('slide');		
		}
		//the 'more info' toggle link
		$('.eventListing .eventLink').click(function(){
			
			if(!$(this).parents('.eventListing').find('.moreInfoPanel:visible').length){
				closeOtherMoreInfoPanels();
			}
			$(this).parents('.eventListing').find('.moreInfoPanel').toggle('slide');
			return false;
		});
		//the close link
		$('.moreInfoPanel .close a').click(function(){
			$(this).parents('.moreInfoPanel').hide();
			return false;
		});
	}
	
	
	
	
	if($('.eventsList.type4 .event .eventInfo').length){
		//alert($('.event .eventInfo').length);
		
		function closeOtherEventInfoPanels4(){
			$('.eventInfo:visible').hide('slide');	
		}
		//the 'more info' toggle link
		$('.event .eventLink').click(function(){
			
			if(!$(this).parents('.event').find('.eventInfo:visible').length){
				closeOtherEventInfoPanels4();
			}
			$(this).parents('.event').find('.eventInfo').toggle('slide');
			return false;
		});
		//the close link
		$('.eventInfo .close a').click(function(){
			$(this).parents('.eventInfo').hide();
			return false;
		});
	}
	
	
	if($('.eventsList.type5 .event .eventInfo').length){
		//alert($('.event .eventInfo').length);
		
		function closeOtherEventInfoPanels5(){
			$('.eventBig:visible').hide('slide');
			$('.condensedHeader .title').removeClass('opaque');	
			//change the 'less' button to a 'more' button
			$('.condensedHeader .moreLink a').removeClass('less').find('span').html('More');

		}
		//the 'more info' toggle link
		$('.event .eventLink').click(function(){
			
			if(!$(this).parents('.event').find('.eventBig:visible').length){
				//panel is closed, so close others and open this one
				closeOtherEventInfoPanels5();
				$(this).parents('.event').find('.eventBig').show('slide');
				//make the condensed title opaque
				$(this).parents('.event').find('.condensedHeader .title').addClass('opaque');
				//change the more button to a 'less' button
				$(this).parents('.event').find('.condensedHeader .moreLink a').addClass('less').find('span').html('Less');
			}else{
				//the panel is open, so close it 
				$(this).parents('.event').find('.eventBig').hide('slide');
				//and remove the opaque class from the condensed title
				$(this).parents('.event').find('.condensedHeader .title').removeClass('opaque');
				//change the 'less' button to a 'more' button
				$(this).parents('.event').find('.condensedHeader .moreLink a').removeClass('less').find('span').html('More');
			}

			
			

			return false;
		});
	
	}
	
	//if news widget has no posts, we placed a div.hideWidget  - use this to traverse back and hide it
	$('.hideWidget').parent('li').hide();

//end ie6 check
//}else{ //end featured carousel chek for ie6
//alert('ie6 here');	
//}	
});




