$(document).ready(function(){

/* Artist flickr Sets */
$('a[rel*=flickryo]').facebox() 

/* Tabs */
$("ul#news_menu_tabbed").idTabs();
$("ul#info_menu_tabbed").idTabs(); 


// SPLASH RESIZER
/* We set the splash image height depending on the window width, assuming large width means large overall screen */	
/* TODO: May need to set a max-height sort of thing to keep from destroying images on very large, 30in, monitors */

function content_resize() 
{
	var w = $( window );
	var H = w.height();
	var W = w.width();
	var Hog = w.height();
	var imgb = $('.splash_box').width();
	var panels = $('.scrollContainer > div');

	if ( W < 1500 ){
	// For a dependence variable height
	//	$( '.image_box' ).css({'height' : H-300 });
	$( '.image_box' ).css({'height' : "450px" });
	$( '.logo_overlay' ).css({'height' : "450px" });
	
		if ( W < 1000 ){
			$( '.image_box' ).css({'height' : '400px' });
			$( '.logo_overlay' ).css({'height' : '400px' });	
			} 
	} 
	
	else {
	// For a dependence variable height
	//	$( '.image_box' ).css({'height' : H-100 });
	$( '.image_box' ).css({'height' : "600px" });
	$( '.logo_overlay' ).css({'height' : "600px" });
	}

	$( '.scrollContainer > div' ).css({'width' : imgb });
	$( '.scrollContainer' ).css({'width' : imgb });					
}	
	
$( window ).wresize( content_resize );
content_resize();


/* DEPRECATED?? */

$('#nav_artists').hover(function(){
	$('.pop ul#artists_top_nav').css({'background' : '#000'});},
	function() {
	$('.pop ul#artists_top_nav').css({'background' : '#FFF'});
});


 $('a[rel="external"]').click( function() {
     window.open( $(this).attr('href') );
     return false;
 });

 $('a[class="external"]').click( function() {
     window.open( $(this).attr('href') );
     return false;
 });



$('div.nav_label2').hover(function() {
	$('.pop', this).show();},
	function() {
	$('.pop', this).hide();
});

/* END DEPRECATED?? */	


$("#twitter").getTwitter({
	userName: "downtownmusic",
	numTweets: 1,
	preloaderId: "tweetLoader",
	loaderText: "Loading tweets...",
	slideIn: false,
	showHeading: false,
//	headingText: "Latest Tweets",
	showProfileLink: true
});

	
	
//CYCLER
$('.scrollContainer').cycle({ 
	fx: 'fade', 
	speed: 'slow',
	timeout: 4000,  
	fit: 0, 
	containerResize: 0,    
	pager:  '#slideControl',
	//    before: onBefore,
	after:   onAfter,
	pauseOnPagerHover: true, 
	pagerAnchorBuilder: function(idx, slide) { 
	  // return selector string for existing anchor 
		return '#slideControl li:eq(' + idx + ') a'; 
    }  
 });

	
	function onBefore() {
		var scull = $('.splash_box').width();		
		$( '.spotlight_item' ).css({'width' : scull });
		$( '.scrollContainer' ).css({'width' : scull });				 
	}

	/* This Pull spotlight info from further down the page and put it where it is */
	function onAfter() {
		var str = $('> span.staticCaption', this).text();
		var body = $('> div.staticBody', this).html();
		var scull = $('.splash_box').width();				 
			
			$('#dynoCaption').html('<h4>' + str + '</h4>')
			$('#dynoBody').html( body )	
				
						
			$( '.spotlight_item' ).css({'width' : scull });
			$( '.scrollContainer' ).css({'width' : scull });		 
	}
	
	$('#slideControl li a').click(function() { 
	    $('.scrollContainer').cycle('pause'); 
	});
	

	$('#popout_btn').click(function() { 
	    $('.scrollContainer').cycle('pause'); 
	});	


	$('#splash_caption').hover(function() { 
	    $('.scrollContainer').cycle('pause'); 
	});	

	
 	$('#dynoBody').hide();

	$("#spotlight_toggle_on").click(function(){ 
		$('.scrollContainer').cycle('pause'); 
		$('#splash_caption').animate({height: "20em"},"fast"); 
		$('#dynoBody').fadeIn('slow');
		$(this).hide();
		$("#spotlight_toggle_off").show()
		return false;
	});
	
	$("#spotlight_toggle_off").click(function(){ 
		$('#dynoBody').fadeOut('fast');
		$('#splash_caption').animate({height: "5em"},"slow");
		$(this).hide();
		$("#spotlight_toggle_on").show()
		$('.scrollContainer').cycle('resume');
		return false; 		 			
	});
	
	$("#artist_aux_on").click(function(){ 
		$('#splash_caption').animate({height: "20em"},"fast"); 

		$(this).hide();
		$("#artist_aux_off").show()
		return false;
	});
	
	$("#spotlight_toggle_off").click(function(){ 
		$('#dynoBody').fadeOut('fast');
		$('#splash_caption').animate({height: "5em"},"slow");
		$(this).hide();
		$("#spotlight_toggle_on").show()
		$('.scrollContainer').cycle('resume');
		return false; 		 			
	});	
		
	
	$('a#splash_feature_down').hide();
	
	$('a#splash_feature_up').click(function(){
		$(".splash_artist_list").scrollTo( '+=93px', 800);
		$('a#splash_feature_down').show();
		return false;		
	});
	
	$('a#splash_feature_down').click(function(){
		$(".splash_artist_list").scrollTo( '-=93px', 800);
		return false;		
	});	


//The toggle button
	var showText='Show';
	var hideText='Hide';
	
	$('.list .buttonAdd').html('<a href="#" class="toggleLink '+showText+' ">'+showText+'</a>');
	$('.simple_post_body').hide();
	
	$('a.toggleLink').click(function() {
		$(this).html ($(this).html()==hideText ? showText : hideText);
		// toggle the display - uncomment the next line for a basic "accordion" style
		//	$('.simple_post_body').hide();
		//	$('a.toggleLink').html(showText);
		$(this).parent().next().next().next('.simple_post_body').slideToggle();
	
		return false;
	});


	$('#slideshow').cycle('stop');
	
	//TOC, shows how to scroll the whole window
	$('#news_top_nav li a').click(function(){
		$.scrollTo( this.hash, 800);
		return false;		
	});	

	
});  /* END BEHAVIOURS */


