(function($){
	$.fn.shutters = function(total, opts) {
		this.each(function(){
			var $this = $(this);
			
			// store all original attributes
			var elem_id = $(this).attr('id');
			var elem_classes = $(this).attr('class');
			
			var options = $.extend($.fn.shutters.defaults, opts);
			var image = $this.attr('src');
			var h = $this.outerHeight();
			var w = $this.outerWidth();
			$this.replaceWith('<ul class="shutter_plate"></ul>');
			var plate = $('ul.shutter_plate');
			var count = 1;
			var dist = 0;
			var wt;
			plate.attr('id', elem_id).addClass(elem_classes);
			while(count <= total) {
				wt = w/total; 
				platelet = $('<li></li>');
				platelet.css({
					position: 'absolute',
					left: dist,
					top: 0,
					listStyle: 'none',
					display: 'block',
					float: 'left',
					height: h,
					width: wt,
					backgroundImage: 'url('+image+')'
				}).css('background-position', '-'+dist+'px top');
				if(count == 1) platelet.addClass('first');
				if(count == total) platelet.addClass('last');
				platelet = platelet.appendTo(plate);
				platelet.css('opacity', 0);
				dist = dist + wt;
				count++;
			}
		});
		var plate = $('ul.shutter_plate');
		setTimeout(function(){
			$('li', plate).eq(0).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 500);
		setTimeout(function(){
			$('li', plate).eq(1).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 1000);
		setTimeout(function(){
			$('li', plate).eq(2).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 1500);
		setTimeout(function(){
			$('li', plate).eq(3).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 2000);
		setTimeout(function(){
			$('li', plate).eq(4).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 2500);
		setTimeout(function(){
			$('li', plate).eq(5).animate({
				opacity: 1
			}, 'easeOutQuad');
		}, 3000);
	}
	
	$.fn.shutters.defaults = {
		firstShutter: 'first',
		lastShutter: 'last'
	};
	
	/*///////////////////////////////////////////////////////////*/
	
	$(window).load(function(){
		$('#codicil_link').click(function(){
			day = new Date();
			window.open($(this).attr('href'), day.getTime(), 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=300');
			return false;
		});
	
		$('img#plate_image').shutters(6);
	
		palette = 
	 ['#ce292a',
		'#3c686f',
		'#9c9e57',
		'#424366',
		'#6f605d',
		'#c59c1d'];
		
		paletteNoHash = 
	 ['ce292a',
		'3c686f',
		'9c9e57',
		'424366',
		'6f605d',
		'c59c1d'];
			
		css_palette =  
	 ['pal_ruby',
		'pal_teal',
		'pal_olive',
		'pal_lav',
		'pal_taupe',
		'pal_gold'];

		function randSelect(p) {
			var r = Math.floor(Math.random() * p.length);
			return p[r];
		}
		
/*
		platecount = 1;
		platetotal = 6;
		plate = $('#page_home_new #plate_image').replaceWith('<ul id="plate_image"></ul>');
		while(platecount <= platetotal) {
			platelet = $('<li></li>').css({
				'background-color': 'red',
				'opacity': 1
			});
			if(platecount == 1) platelet.addClass('first');
			if(platecount == platetotal) platelet.addClass('last');
			plate.append(platelet);
			platecount++;
		}
*/
		
/*
		plate = $('#page_home_new #plate_image');
		platelets = $('li', plate);
		platelets.css('opacity', 0);
		count = 1;
		widthsofar = 0;
		var animateSlice = function(who){
			if(count <= platelets.size()){
				who.css('background-position', -widthsofar);
				widthsofar = widthsofar + who.outerWidth();
				setTimeout(function(){
					who.animate({
						opacity: 1
					}, 700, 'easeInQuad');
					animateSlice($(who).next());
				}, count * 50);
				count++;
			}
		};
		
		animateSlice(platelets.eq(0)); */
		
		$('a.mp3').each(function(){
		  $obj = $(this);
		  $loc = $(this).attr('href');
		  $player = $('<span class="mp3"></span>').replaceAll($(this));
		  $player.jmp3({
  			filepath: $loc,
  			backcolor: randSelect(paletteNoHash),
  			forecolor: '000000',
  			width: 300,
  			showdownload: "false"
  		});
		});
		
		$('#page_home_new #plate h1').css('opacity', 0);
		$('#page_home_new #plate img').css('opacity', 0).animate({ opacity: 1 }, 500);
		setTimeout(function(){
			$('#page_home_new #plate_image li').fadeOut('slow');
		}, 5000);
		setTimeout(function(){
			$('#page_home_new #plate h1').css({
				opacity: 0,
				display: 'block'
			}).animate({
				opacity: 1,
				top: '11em'
			});
		}, 5800);
		setTimeout(function(){
			$('#page_home_new #plate #welcome_message').css({
			opacity: 0,
			display: 'block'});
			$('#page_home_new #plate #welcome_message').animate({
			opacity:1},'slow');
		}, 6500);
		
/*
		$('#ataglance .event .datetime a').each(function(){
			$(this).css('color', randSelect(palette));
		});
*/
		
		/*///////// MAIN NAV MENU BEHAVIOR /////////*/
		$('.submenu').hide();
		$('#main.menu li.toplevel .navhead').mouseover(function(){
			$('.submenu', $(this).parent('.toplevel')).slideDown();
		});
		
		$('#main.menu li.toplevel').bind('mouseleave', function(){
			$('.submenu', $(this)).slideUp();
		});
		
		/*///////// COLORING THE PRESS QUOTES /////////*/	
/*
		$('#pressboard blockquote').each(function(){
			$(this).addClass(randSelect(css_palette));
		});
*/

		/*///////// COLORING THE CONTRIBUTORS /////////*/	
/*
		$('.contributor').each(function(){
			$(this).css("color", randSelect(palette));
		});
*/
		
		/*///////// COLORING THE BLOGS /////////*/	
/*
		$('#concert_blog .entry').each(function(){
			$(this).addClass(randSelect(css_palette));
		});
*/
		
		/*///////// COLORING THE PERFORMERS /////////*/	
/*
		$('.event').each(function(){
			$(this).addClass(randSelect(css_palette));
		});
*/
		
/* 		$('.biography').newsColumns(); */
		
		/*///////// SPLITTING THE LISTINGS /////////*/
		var evenEvents = $('#evening_concerts_calendar .event:even');
		var oddEvents = $('#evening_concerts_calendar .event:odd');
		
		$('#evening_concerts_calendar .event').remove();
		$('#evening_concerts_calendar ul').remove();
		$('#evening_concerts_calendar').append('<ul class="even"></ul>\n<ul class="odd"></ul>');
		
		$('#evening_concerts_calendar ul.even').append(evenEvents);
		$('#evening_concerts_calendar ul.odd').append(oddEvents);
		
		/*///////// SPLITTING THE COMMENTS /////////*/
		$('.comments').each(function(){
			var evenComments = $('.comment:even', $(this));
			var oddComments = $('.comment:odd', $(this));
			
			$('.comment', $(this)).remove();
			$('ul', $(this)).remove()
			$(this).append('<ul class="even"></ul>\n<ul class="odd"></ul>');
			$('ul.even', $(this)).append(evenComments);
			$('ul.odd', $(this)).append(oddComments);
			
			$('h4', $(this)).append(" ("+(evenComments.size() + oddComments.size())+"): ");
		});
		
		/*///////// ANIMATING THE EVENT PROGRAMS /////////*/		
		$('#evening_concerts_calendar .program').drawer({
			trigger: '.program_switch',
			speed: ['normal', 'normal'],
			easing: ['easeOutQuad', 'easeInQuad']
		});
		
		$('#afternoon_concerts_calendar .event').each(function(){
			if($('.biography', $(this)).size() > 0) $('.description', this).after('<div class="biography_switch">View Artist Biography</div>');
			if($('.program', $(this)).size() > 0) $('.description', this).after('<div class="program_switch">View Program</div>');
		});
		
		$('#childrens_concert .event').each(function(){
			if($('.biography', $(this)).size() > 0) $('.description', this).after('<div class="biography_switch">View Artist Biography</div>');
			if($('.program', $(this)).size() > 0) $('.description', this).after('<div class="program_switch">View Program</div>');
		});
		
		$('#annual_benefit_concert .event').each(function(){
			if($('.biography', $(this)).size() > 0) $('.description', this).after('<div class="biography_switch">View Artist Biography</div>');
			if($('.program', $(this)).size() > 0) $('.description', this).after('<div class="program_switch">View Program</div>');
		});
		
		/* Changing default scrollTo value */
		$.fn.drawer.defaults.scrollTo = true;
		
		/* Implementing the drawers on the event's elements */
		$('#afternoon_concerts_calendar .program').drawer({
			trigger: '.program_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack'],
			scrollTo: false
		});
		$('#afternoon_concerts_calendar .biography').drawer({
			trigger: '.biography_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack']
		});
		
		$('#childrens_concert .program').drawer({
			trigger: '.program_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack'],
			scrollTo: false
		});
		$('#childrens_concert .biography').drawer({
			trigger: '.biography_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack']
		});
		
		$('#annual_benefit_concert .program').drawer({
			trigger: '.program_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack'],
			scrollTo: false
		});
		$('#annual_benefit_concert .biography').drawer({
			trigger: '.biography_switch',
			speed: ['slow', 'slow'],
			easing: ['easeOutQuad', 'easeInBack']
		});
		
		if(location.hash) {
			$('.program_switch', $(location.hash)).click();
		}
		
		/*///////// CLEAR-FLOATS /////////*/
		$('#evening_concerts_calendar').append('<div class="clearfloat"></div>');
		$('#afternoon_concerts_calendar').append('<div class="clearfloat"></div>');
		$('.blog .comments').append('<div class="clearfloat"></div>');

		/*///////// ANIMATING THE MUSICIANS BUTTON /////////*/
		$('#bso_musicians h3').hover(function(){
			$(this).stop().animate({
				backgroundColor: randSelect(palette),
				color: 'white'
			}).children('a').animate({
				color: 'black'
			});
		}, function(){
			$(this).stop().animate({
				backgroundColor: 'black',
				color: 'silver'
			}).children('a').animate({
				color: 'white'
			});
		}).click(function(){
			window.location = $('a', $(this)).eq(0).attr('href');
		}).mouseenter(function(){
			$(this).css('cursor', 'pointer');
		});
	});
	
	$(document).ready(function(){
    DD_belatedPNG.fix('*');
    
    $('.slideshow').each(function(){
      $s = $(this);
      $s.cycle({
        speed: 1000,
        timeout: 4000,
        fx: 'fade',
        easing: 'easeInOutQuad',
        pauseOnPagerHover: 1,
        next: $s
      });
    });
	});
})(jQuery);
