
$(document).ready(function() {
	
	
	//Homepage Ticket Animations
	$(".eventsTickets > li .ticket").hover(
		function () {
			if($.browser.msie){
				$(this).stop().animate({top:'-122px', opacity:1});
			}else{
				$(this).stop().animate({top:'-134px', opacity:1});
			}
		},
		function () {
			$(this).stop().animate({top:'0', opacity:1}, 800, "easeOutBounce");			
		}
	);
	
	//Collapse Areas
	$('.collapse').hide();
	$('.collapseHeader').toggle( function() {
		$(this).next('.collapse').slideDown();
		$(this).css('background', 'url("/presentation/images/arrow_down.jpg") no-repeat 0% 50%');}, function() {
		$(this).next('.collapse').slideUp();
		$(this).css('background', 'url("/presentation/images/arrow_right.jpg") no-repeat 0% 50%');
	});
	
	//Staff Component
	var openBoard = false;
	var openStaff = false;
	
	$('.staffComp .board a.toggle').click( function() {
		
		if(openBoard==false){
			$('.staffComp .board a.toggle').text('show board');
			$('.staffComp .staff a.toggle').text('show staff');
			$('.boardOverlay, .staffOverlay').css('display', 'none');
			openStaff=false;
			openBoard=false;
			
			$('.boardOverlay').css('display', 'block');
			$(this).text('hide board');
			openBoard = true;
		}else{
			$('.staffComp .board a.toggle').text('show board');
			$('.staffComp .staff a.toggle').text('show staff');
			$('.boardOverlay, .staffOverlay').css('display', 'none');
			
			$(this).text('show board');
			openBoard = false;
		}
		return false;
	});
	
	$('.staffComp .staff a.toggle').click( function() {
		
		if(openStaff==false){
			$('.staffComp .board a.toggle').text('show board');
			$('.staffComp .staff a.toggle').text('show staff');
			$('.boardOverlay, .staffOverlay').css('display', 'none');
			openStaff=false;
			openBoard=false;
			
			$('.staffOverlay').css('display', 'block');
			$(this).text('hide staff');
			openStaff = true;
		}else{
			$('.staffComp .board a.toggle').text('show board');
			$('.staffComp .staff a.toggle').text('show staff');
			$('.boardOverlay, .staffOverlay').css('display', 'none');
			
			$(this).text('show staff');
			openStaff = false;
		}
		return false;
	});
	
	//Event Calendar Fix
	if($.browser.mozilla){
		$('.performance-event #content h2').css({marginTop: "91px"});
	}
	
	//Homepage Slider
	$('#captions').cycle({ 
		fx:     'fade', 
		timeout: 10000, 
		next:   '.nextButton', 
		prev:   '.prevButton'
	});
	
	//Homepage Tickets Links
	$(".eventsTickets > li .ticket, .ticketsComp ul li").css('cursor', 'default').click(function(){
		var tLink = $(this).find('h4').attr('title');
		window.location.href = Link;
	});

	//Standard Template Slider
	$('#banner ul').cycle({ 
		fx:     'fade', 
		pager:  '#bannerNav' 
	});
	
	//Testimonials Slider
	$('.testimonials ul').cycle({ 
		fx:     'scrollRight', 
		timeout: 0, 
		next:   '.testimonialsNext', 
		prev:   '.testimonialsPrev'
	});
	
	//Modal Window
	$('a[name=modal]').click(function(){
		var modal_id = $(this).attr('class');
		show_modal(modal_id);
	});

	$('.close').click(function(e){
		close_modal();
		$('.staffComp .board a.toggle').text('show board');
		$('.staffComp .staff a.toggle').text('show staff');
		$('.boardOverlay, .staffOverlay').css('display', 'none');
		openStaff=false;
		openBoard=false;
		e.preventDefault();
		
	});

	function close_modal(){
		$('#mask').fadeOut(500);
		$('.modal').fadeOut(500);
	};

	function show_modal(modal_id){
		$('#mask').css({ 'display' : 'block', opacity : 0});
		$('#mask').fadeTo(500,0.8);
		$('.'+modal_id).css({top: '60px', left:$(window).width()/2}).fadeIn(500);
	};
	
	
	
	
	
	
	
	//Media Carousel
	$('.cItems').jCarouselLite({
		btnNext: '.carNext',
		btnPrev: '.carPrev',
		circular: false
	});
	$('.cItemsTwo').jCarouselLite({
		btnNext: '.carNextTwo',
		btnPrev: '.carPrevTwo',
		circular: false
	});
	$('.cItemsThree').jCarouselLite({
		btnNext: '.carNextThree',
		btnPrev: '.carPrevThree',
		circular: false
	});
	
	$('.carousel').css('height', '275px');
	
	var vidClicked = false;
	var identifier = null;
	var vidInfo = null;
	
	$('.carousel li a').click( function() {
		
		//IE8 Bug Fix
		if($.browser.msie){
			$('.pause').click();
			if(vidClicked == false){
				identifier = $(this).attr('rel');
				vidInfo = $('#'+identifier).find('.vid').html();
				vidClicked = true;
			}else{
				$('#'+identifier).find('.vid').empty().html(vidInfo);
				identifier = $(this).attr('rel');
				vidInfo = $('#'+identifier).find('.vid').html();
			}
		}
		
		
		$('.mediaDetails').hide();
		$('.carousel').css('height', '275px');
		$(this).parents('div').css('height', '100%');
		var detailsID = $(this).attr('rel');
		$('#'+detailsID).fadeIn();
		
		removeActiveWL();
		$(this).find('img').css({opacity: 1});
		$(this).find('img').parents('li').addClass('activeWL');
		
		return false;
	});
	
	var removeActiveWL = function(){
		$('.carousel li a').each(function () {
			$(this).find('img').animate({opacity: 1}, 0);
			$(this).find('img').parents('li').removeClass('activeWL');
		});
	}
	
	removeActiveWL();
	
	$('.carousel li a').hover(function(){
		$('.carousel li a').not(this).stop().animate({opacity: .3}, 700);
	}, function(){
		$('.carousel li a').stop().animate({opacity: 1}, 700);
	});
	
	
	
	
	
        
        //Hover Events To Start and Stop Animation
        $('.bottomRow ul').each(function(){
            $(this).hover(function(){
                $(this).animate({opacity: 1}, 700);
                $('.bottomRow ul').not(this).stop().animate({opacity: .4}, 700);
                $(this).cycle('resume');
            },function(){
                $('.bottomRow ul').delay(250).stop().animate({opacity: 1}, 700);
                $(this).cycle('pause');
            })
        })
	
	
	//Open up specific section if linked to from other page
	var unfiltredCode = window.location.href.substr(window.location.href.lastIndexOf("/"));
	var mediaIdentifier = unfiltredCode.substr(1);
	
	
	function specificMediaOpen(){
		
		//IE8 Bug Fix
		if($.browser.msie){
			$('.pause').click();
			if(vidClicked == false){
				identifier = $('.carousel li a[title="'+mediaIdentifier+'"]').attr('rel');
				vidInfo = $('#'+identifier).find('.vid').html();
				vidClicked = true;
			}else{
				$('#'+identifier).find('.vid').empty().html(vidInfo);
				identifier = $('.carousel li a[title="'+mediaIdentifier+'"]').attr('rel');
				vidInfo = $('#'+identifier).find('.vid').html();
			}
		}
		
		
		$('.carousel').css('height', '275px');
		$('.carousel li a[title="'+mediaIdentifier+'"]').parents('div').css('height', '100%');
		var detailsID = $('.carousel li a[title="'+mediaIdentifier+'"]').attr('rel');
		$('#'+detailsID).fadeIn();
		
		
		//removeActiveWL();
		$('.carousel li a[title="'+mediaIdentifier+'"]').find('img').css({opacity: 1});
		$('.carousel li a[title="'+mediaIdentifier+'"]').find('img').parents('li').addClass('activeWL');
		
		return false;
	};
	
	specificMediaOpen();
	
	
	//Media Slideshow
	var eachSlideShowContainer = $('.carousel').eq(2).children('.mediaDetails');
	
	$(eachSlideShowContainer).each(function(){
		var $this = $(this).find('.slideshow');
		$this.cycle({
			fx: 'scrollHorz',
			pause: true,
			next: '.sliderNavRight',
			prev: '.sliderNavLeft'  
		});
	});
	
	$('.mediaDetails').hover(function(){
		$('.sliderNavLeft, .sliderNavRight').stop().css('opacity', 0).show().animate({opacity: 1}, 750);
	}, function(){
		$('.sliderNavLeft, .sliderNavRight').stop().animate({opacity: 0}, 750).hide();
	});
	

	//Music Player
	 $("#playlist1, #playlist2, #playlist3, #playlist4, #playlist4, #playlist6, #playlist7, #playlist8, #playlist9, #playlist10").playlist(
	 	{
			playerurl: "/presentation/swf/drplayer.swf"
		}
	 );
	 
	//Search Box
	$('#topBar input[type="text"]').css('opacity', .5);
	$('#topBar input[type="text"]').focus(function() {
  		$('#topBar input[type="text"]').animate({opacity:1}, 300);
	});
	$('#topBar input[type="text"]').blur(function() {
  		$('#topBar input[type="text"]').animate({opacity:.5}, 300);
	});
	
	//Expandable Content Block/////////////////////////////
	
	$('.sbExpandableBlock p').eq(1).nextAll('p, ul, ol').hide();
	
	$('.sbExpandableBlock a').live('click', function(e){
		if($('.sbExpandableBlock a').text() == 'Show More'){
			$('.sbExpandableBlock a').html('<img src="/presentation/images/whiteArrowUp.jpg" alt="" width="11" height="7" />Hide');
		}else if($('.sbExpandableBlock a').text() == 'Hide'){
			$('.sbExpandableBlock a').html('<img src="/presentation/images/whiteArrowDown.jpg" alt="" width="11" height="7" />Show More');
		};
		e.preventDefault();
		$('.sbExpandableBlock p').eq(1).nextAll('p, ul, ol').slideToggle('slow');
	});
	
	
	//Press Releases /////////////////////////////
	
	$('.sbgWrap').eq(2).nextAll('div').hide();
	
	$('.showAllsbg').live('click', function(e){
		if($('.showAllsbg').text() == 'show more'){
			$('.showAllsbg').html('<img src="/presentation/images/greenArrowUp.jpg" alt="" />hide');
		}else if($('.showAllsbg').text() == 'hide'){
			$('.showAllsbg').html('<img src="/presentation/images/greenArrowDown.jpg" alt="" />show more');
		};
		e.preventDefault();
		$('.sbgWrap').eq(2).nextAll('div').slideToggle('slow');
	});
	
	
	//LOGO ROTATOR/////////////////////////////
	
	// variables
	var logo = Math.ceil($('.sbImageRotator ul').children('li').length)-1;
	var logoPos = 0;
	
	//Hide all logos but the first
	$('.sbImageRotator ul li').eq(0).nextAll().addClass('sbImageHide');
	
	var changeLogo = function(){
		if(logoPos < logo){
			if($.browser.msie){
				$('.sbImageRotator ul li').eq(logoPos).addClass('sbImageHide');
				logoPos++;
				$('.sbImageRotator ul li').eq(logoPos).removeClass('sbImageHide');
			}else{
				$('.sbImageRotator ul li').eq(logoPos).animate({opacity:.3}, 300,function(){
					$(this).addClass('sbImageHide');
					logoPos++;
					$('.sbImageRotator ul li').eq(logoPos).css({opacity:0}).removeClass('sbImageHide').animate({opacity:1}, 500);
				})
			}
		}else if(logoPos == logo){
			if($.browser.msie){
				$('.sbImageRotator ul li').eq(logoPos).addClass('sbImageHide');
				logoPos = 0;
				$('.sbImageRotator ul li').eq(logoPos).removeClass('sbImageHide');
			}else{
				$('.sbImageRotator ul li').eq(logoPos).animate({opacity:.3}, 300,function(){
					$(this).addClass('sbImageHide');
					logoPos = 0;
					$('.sbImageRotator ul li').eq(logoPos).css({opacity:0}).removeClass('sbImageHide').animate({opacity:1}, 500);
				})
			}
	
		}
				  
	}// end of changeLogo
	
	setInterval(function(){
	  //Logo
	  if(logo > 0){
	  changeLogo();
	  };
	}, 6500);
	
	
	//TEXT TICKER/////////////////////////////
	
	// variables
	var txt = Math.ceil($('.sbTicker ul').children('li').length)-1;
	var txtPos = 0;
	
	//Hide all logos but the first
	$('.sbTicker ul li').eq(0).nextAll().addClass('sbTickerHide');
	
	var changeTxt = function(){
		if(txtPos < txt){
			if($.browser.msie){
				$('.sbTicker ul li').eq(txtPos).addClass('sbTickerHide');
				txtPos++;
				$('.sbTicker ul li').eq(txtPos).removeClass('sbTickerHide');
			}else{
				$('.sbTicker ul li').eq(txtPos).animate({opacity:.3}, 300,function(){
					$(this).addClass('sbTickerHide');
					txtPos++;
					$('.sbTicker ul li').eq(txtPos).css({opacity:0}).removeClass('sbTickerHide').animate({opacity:1}, 500);
				})
			}
		}else if(txtPos == txt){
			if($.browser.msie){
				$('.sbTicker ul li').eq(txtPos).addClass('sbTickerHide');
				txtPos = 0;
				$('.sbTicker ul li').eq(txtPos).removeClass('sbTickerHide');
			}else{
				$('.sbTicker ul li').eq(txtPos).animate({opacity:.3}, 300,function(){
					$(this).addClass('sbTickerHide');
					txtPos = 0;
					$('.sbTicker ul li').eq(txtPos).css({opacity:0}).removeClass('sbTickerHide').animate({opacity:1}, 500);
				})
			}
	
		}
				  
	}// end of changeLogo
	
	setInterval(function(){
	  //txt
	  if(txt > 0){
	  changeTxt();
	  };
	}, 6500);
	
	
	// CSS COMPLIANT EXTERNAL LINK FUNCTION (OPEN NEW POP-UP) 
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			anchor.hideFocus = true;
			if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "alternate" || anchor.getAttribute("href").indexOf(".pdf") > 4)) anchor.target = "_blank";
		}
	}
	
	//Calander Tip
	$('.cal-event-title-month a').hover(function(){
		$(this).next('.details').fadeIn();
	}, function(){
		$(this).next('.details').fadeOut();
	});
	
	
	//Strip Blog Styles
	$('#blogContent span, #blogContent img').removeAttr("style");
	
	
	//Contact Map Switch
	$('.contact-us #banner ul li img').css('cursor', 'pointer').click(function(){	
		$(this).parents('li').html("<iframe width='615' height='296' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=boston+childrens+chorus&amp;sll=40.957896,-72.962635&amp;sspn=0.007956,0.033023&amp;ie=UTF8&amp;hq=childrens+chorus&amp;hnear=Boston,+Suffolk,+Massachusetts&amp;cid=5733464206855096789&amp;ll=42.354865,-71.065836&amp;spn=0.022009,0.036478&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe>").css('cursor', 'pointer');
	})
	
})//end of dom ready
	
