// MODALS
$().ready(function() {
	$('#mailing-list').jqm({trigger: 'a.trigger-mailing-list', toTop: true}); // homepage
	$('#mailing-list').jqmAddClose('span.close');
	
	$('#home-video').jqm({trigger: 'a.watch-video', toTop: true}); // homepage
	$('#home-video').jqmAddClose('span.close');
	
	$('#event-video').jqm({trigger: '.detail-video', toTop: true}); // 
	$('#event-video').jqmAddClose('span.close');

});


// BACKGROUND IMAGES (SUPERSIZE PLUGIN)

jQuery(function($){
	if ($('#concerts-detail').length > 0 ) { $.supersized({slides : [ { image : '/img/concerts/detail/background.jpg' } ]}); }
	if ($('#concerts-artists').length > 0 ) { $.supersized({slides : [ { image : '/img/concerts/artists/background.jpg' } ]}); }
	if ($('#concerts-artists-detail').length > 0 ) { $.supersized({slides : [ { image : '/img/concerts/artists/background.jpg' } ]}); }
	if ($('#concerts-season').length > 0 ) { $.supersized({slides : [ { image : '/img/concerts/season/background.jpg' } ]}); }
	if ($('#about-overview').length > 0 ) { $.supersized({slides : [ { image : '/img/about/overview/background.jpg' } ]}); }
	if ($('#about-staff').length > 0 ) { $.supersized({slides : [ { image : '/img/about/staff/background.jpg' } ]}); }
	if ($('#about-board').length > 0 ) { $.supersized({slides : [ { image : '/img/about/board/background.jpg' } ]}); }
	if ($('#media-video').length > 0 ) { $.supersized({slides : [ { image : '/img/media/video/background.jpg' } ]}); }
	if ($('#media-recordings').length > 0 ) { $.supersized({slides : [ { image : '/img/media/recordings/background.jpg' } ]}); }
	if ($('#media-bytes').length > 0 ) { $.supersized({slides : [ { image : '/img/media/bytes/background.jpg' } ]}); }
	if ($('#support').length > 0 ) { $.supersized({slides : [ { image : '/img/support/background.jpg' } ]}); }
	if ($('#contact').length > 0 ) { $.supersized({slides : [ { image : '/img/contact/background.jpg' } ]}); }
});

$(function() {


// CONCERT SEASON EVENTS HOVER

$('.concert').mouseenter(function(){
	$(this).children('.concert-date').animate({width:60},{duration:200},'easeInQuad'); // date flyout
	if ( $.browser.msie ) {		
		$(this).children('.concert-overlay').hide(); // disable fancy fade for IE
	} else {
		$(this).children('.concert-overlay').fadeTo('slow',0); // fancy fade
	}
}).mouseleave(function(){
	$(this).children('.concert-date').animate({width:43},{duration:200},'easeInQuad');
	if ( $.browser.msie ) {
		$(this).children('.concert-overlay').show(); // disable fancy fade for IE
	} else {
		$(this).children('.concert-overlay').fadeTo('slow',1); // fancy fade
	}
});


// AUDIO PLAYER TOGGLE

	$('.listen li a').click(function(e) {
		  $(this).parent().find('.audioplayer').slideToggle(300, function() {
		  });
		  $(this).parent().toggleClass('playing');
		  e.preventDefault();
	});


// NAV MENU	

$('li.hassubnav').hover(function(){ 
	
		var subNavLink = $(this).children('a.mainnav');
		var mainNav = $('li.hassubnav a').parent();
		var SubNav = mainNav.children('.subnav');
		
		var halflink = subNavLink.width()/2;
		var distance = halflink - 33; 
		
		$(this).children('div.subnav').css('margin-left', distance); 
		$(this).children('a.mainnav').stop().animate({backgroundPosition:"(50% 110px)"},100,'easeInQuad');
		
			$(this).addClass('opensubnav');
			$(this).children('div.subnav').delay(100).slideDown(100);

}, function() { 
		$(this).children('div.subnav').slideUp(100);
		$(this).children('a.mainnav').animate({backgroundPosition:'(50% 77px)'},100,'easeInQuad');
		$(this).removeClass('opensubnav');
	
	}); 
	

$('#header').mouseleave(function(){
		$('li.hassubnav').find('div.subnav').slideUp(100);
		$('#header-content').find('li.opensubnav').children('a.mainnav').animate({backgroundPosition:'(50% 67px)'},100,'easeInQuad');
		$('#header-content').find('li.opensubnav').removeClass('opensubnav');
});

$('#header ul li div.subnav ul li:last').css('border', '0px');

	// cycle thru the image slides

		$('#slideshow img:gt(0)').hide();
	    setInterval(function(){
	      $('#slideshow :first-child').fadeTo("slow",0)
	         .next('img').fadeTo("slow",1)
	         .end().appendTo('#slideshow');}, 
	      6000);

	

	
	// maintain full-width and aspect ratio
	
	$(window).resize(function(){ scalingSlideshow(); }).trigger('resize');
	function scalingSlideshow(){
		if ($(window).width() < 1400 ) {
		$('#slideshow img').stop().css({width: "1400px"});
		}
		else {
		$('#slideshow img').stop().css({width:$(window).width()});
		}
	}


// NEWS TICKER

	$('#newsbar ul').cycle({
		fx: 'fade',
		speed: 400, 
		cleartypeNoBg: true
	});
	

// ARTISTS LIST & GRID VIEW
	
	$('a.view-list').click(function(){		
		$('#content-container').addClass('list-view');
		$('a.view-list').css({backgroundPosition: 'bottom'});
		$('a.view-grid').css({backgroundPosition: 'top'});
	});
	$('a.view-grid').click(function(){		
		$('#content-container').removeClass('list-view');
		$('a.view-list').css({backgroundPosition: 'top'});
		$('a.view-grid').css({backgroundPosition: 'bottom'});
	});	
	
	// other stuff
	
	$('ul#featured_events li:nth-child(2)').css('margin-right', '0px');
	$('#upcoming-performances ul li:last').css('background-image', 'none');
	$('#upcoming-performances ul li:last').css('margin-bottom', '0px');
	
	$('#calendar-shell').cycle({
				fx: 'fade',
			    speed:  'fast', 
			    timeout: 0,
		    	prev:   '.cal-left', 
		    	next:   '.cal-right', 
				cleartypeNoBg: true
		});
		
	// qtip plugin attempt - calendar
	
	$('.calendartb td a[rel]').each(function() {
	      $(this).qtip({
		   content: {
		      text: '<img src="/img/loading.gif" class="loader" alt=""/>', 
			  	ajax: {
	             url: $(this).attr('rel'),	// Use the rel attribute of each element for the url to load
				type: 'GET', // POST or GET
				         data: {}, // Data to pass along with your request
				         success: function(data, status) {
				            // Process the data

				            // Set the content manually (required!)
				            this.set('content.text', data);
				}
	          }, 
			  title: {
			         text: $(this).children('div.ajax-title').text(),
			         button: true
			      }
		 },
		   	 position: {
	           at: 'center left', // Position the tooltip above the link
	           my: 'center right',	
	           adjust: { screen: true } // Keep the tooltip on-screen at all times
	        },
			show: {
			            event: 'mouseover',
			            solo: true // Only show one tooltip at a time
			         },
			         hide: { 
								delay: 500, 
								fixed: true, 
								event: 'mouseleave'
								
						},
			style: {
	            classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow'
	         }
		});
	});
	
	// replace dash with br 
	
	$('div.concert-week .concert h3').each(function() {
	   $(this).html($(this).html().replace(/[_-]/g,"<br/>"));
	});
	$('#upcoming-performances a.button').each(function() {
	   $(this).html($(this).html().replace(/[_-]/g,"<br/>"));
	});
	$('div.event1 h3').each(function() {
	   $(this).html($(this).html().replace(/[_-]/g,"<br/>"));
	});
	
	// ARTIST TOOLTIP - get left and right
	
	
	$('.artist').each(function() { 
		var artistp = $(this);
		var position = artistp.position();
		if(position.left < 650) { 
			$(this).addClass('lefty');
		} else { 
			$(this).addClass('righty');
		}
	}); 
	
	// qtip lefties
	
	$('.lefty a[rel]').each(function() {
	      $(this).qtip({
		   content: {
		      text: '<img src="/img/loading.gif" class="loader" alt=""/>', 
			  	ajax: {
	             url: $(this).attr('rel') // Use the rel attribute of each element for the url to load
	          }, 
			  title: {
			         text: $(this).parent().children('h3').text(),
			         button: true
			      }
		 },
		   	 position: {
	           at: 'center right', // Position the tooltip above the link
	           my: 'center left',
	           adjust: { screen: true } // Keep the tooltip on-screen at all times
	        },
			show: {
			            event: 'mouseover',
			            solo: true // Only show one tooltip at a time
			         },
			         hide: { 
								delay: 500, 
								fixed: true, 
								event: 'mouseleave'

						},
			style: {
	            classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow'
	         }
		});
	});
	
	// qtip righties
	
	$('.righty a[rel]').each(function() {
	      $(this).qtip({
		   content: {
		      text: '<img src="/img/loading.gif" class="loader" alt=""/>', 
			  	ajax: {
	             url: $(this).attr('rel') // Use the rel attribute of each element for the url to load
	          }, 
			  title: {
			         text: $(this).parent().children('h3').text(),
			         button: true
			      }
		 },
		   	 position: {
	           at: 'center left', // Position the tooltip above the link
	           my: 'center right',
	           adjust: { screen: true } // Keep the tooltip on-screen at all times
	        },
			show: {
			            event: 'mouseover',
			            solo: true // Only show one tooltip at a time
			         },
		    		hide: { 
								delay: 500, 
								fixed: true, 
								event: 'mouseleave'

						},		
			style: {
	            classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow'
	         }
		});
	});
	
	//min height of content-container 
	var windowheight = $(window).height() - 356; 
	$('#content-container').css('min-height', windowheight);
		
});

