/*** GALLERY FUNCTIONS ***/

document.title = "Andrew Suvalsky :: Gallery";
                       

// USER STATE VARIABLES
	var window_height;
	var photo_size = '480';
	
	
$(document).ready(function(){ 
	
	// GALLERY NAV LINKS
		// see gallery_nav_scroll_to()
	
	// SWINGS PHOTOS THUMB-LINKS
	$('#gallery ul#thumbs li.photos.swings.thumb-1').livequery('click', function(event) { 
        load_photo('photos','swings','001'); return false;
    });
	$('#gallery ul#thumbs li.photos.swings.thumb-2').livequery('click', function(event) { 
        load_photo('photos','swings','127'); return false;
    });                                
	$('#gallery ul#thumbs li.photos.swings.thumb-3').livequery('click', function(event) { 
        load_photo('photos','swings','157'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.swings.thumb-4').livequery('click', function(event) { 
        load_photo('photos','swings','203'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.swings.thumb-5').livequery('click', function(event) { 
        load_photo('photos','swings','332'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.swings.thumb-6').livequery('click', function(event) { 
        // load_photo('photos','swings','006'); return false;
    });

	// VINTAGE PHOTOS THUMB-LINKS
	$('#gallery ul#thumbs li.photos.vintage.thumb-1').livequery('click', function(event) { 
        load_photo('photos','vintage','242'); return false;
    });
	$('#gallery ul#thumbs li.photos.vintage.thumb-2').livequery('click', function(event) { 
        load_photo('photos','vintage','760'); return false;
    });                                
	$('#gallery ul#thumbs li.photos.vintage.thumb-3').livequery('click', function(event) { 
        load_photo('photos','vintage','593'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.vintage.thumb-4').livequery('click', function(event) { 
        load_photo('photos','vintage','313'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.vintage.thumb-5').livequery('click', function(event) { 
        load_photo('photos','vintage','393'); return false;
    });                                    
	$('#gallery ul#thumbs li.photos.vintage.thumb-6').livequery('click', function(event) { 
        load_photo('photos','vintage','465'); return false;
    });

	// MARKETING THUMB-LINKS 
	$('#gallery ul#thumbs li.marketing.thumb-1').livequery('click', function(event) { 
        load_photo('marketing','vintage','bluenote'); return false;
    });
	$('#gallery ul#thumbs li.marketing.thumb-2').livequery('click', function(event) { 
        load_photo('marketing','vintage','metropolitan_room'); return false;
    });
	$('#gallery ul#thumbs li.marketing.thumb-3').livequery('click', function(event) { 
        load_photo('marketing','vintage','iridium'); return false;
    });
	$('#gallery ul#thumbs li.marketing.thumb-4').livequery('click', function(event) { 
        load_photo('marketing','vintage','new_album_swings'); return false;
    });

	// PERFORMANCES THUMB-LINKS
	$('#gallery ul#thumbs li.performances.thumb-1').livequery('click', function(event) { 
		load_performances('metropolitan_room');
    });


	// PERFORMANCES LINKS
	$('#gallery .metropolitain_room.play.link').livequery('click', function(event) { 
		play_video('metropolitan_room'); return false;
    }); 

 }); 


    
switch (demo_setting) {

	/* * * * * * * * * FANCY * * * * * * * * */
	case 'fancy': {
		
        $(document).ready(function(){ 


			   $('#main_content').fadeIn('300'); 
				//  change_content.js normally hides the content, then fades in once everything is loaded to prevent 'flashing'
				//	that sequnce cause jcarosel to fail, so we fade in as soon as the docuemnt is ready
			   $('#nav .nav').addClass('current-gallery');

			// USER STATE
				window_height = $(window).height();
				switch (true) {
				case (window_height > 850 ): 
					// alert('window height: ' + window_height + '\nlarge: 680');
					photo_size = '680';
					$('#photo_container').css('height','780px');
					load_photo('photos','swings','001');
					break;
				case (window_height < 785): 
					// alert('window height: ' + window_height + '\nsmall: 480');
					photo_size = '480';
					$('#photo_container').css('height','580px');
					load_photo('photos','swings','001');
					break;
				default: 
					// alert('window height: ' + window_height + '\nmedium: 580');
					photo_size = '580';
					$('#photo_container').css('height','680px');
					load_photo('photos','swings','001');
				}


			// INITIALIZE JCAROUSEL
				jQuery('#thumbs').jcarousel({
				    scroll:6,
					//size: thumbs_size
					initCallback: gallery_nav_scroll_to,
					itemFirstInCallback: find_thumbs_index
				});

		});
        

		// GALLERY NAV SCROLL TO
			function gallery_nav_scroll_to(carousel) {
			    $('#gallery_nav .swings.photos').bind('click', function() {
			        // alert('swings photos');
					carousel.scroll(jQuery.jcarousel.intval(1));
					$('#gallery_nav li.current').removeClass('current');
					$('#gallery_nav li.photos.swings').addClass('current');
			        return false;
			    });
				$('#gallery_nav .vintage.photos').bind('click', function() {
			        // alert('vintage photos');
					carousel.scroll(jQuery.jcarousel.intval(7));
					$('#gallery_nav li.current').removeClass('current');
					$('#gallery_nav li.photos.vintage').addClass('current');
			        return false;
			    });
				$('#gallery_nav .marketing').bind('click', function() {
			        // alert('marketing');
					carousel.scroll(jQuery.jcarousel.intval(13));
					$('#gallery_nav li.current').removeClass('current');
					$('#gallery_nav li.marketing').addClass('current');
			        return false;
			    });
				$('#gallery_nav .performances').bind('click', function() {
					// alert('performances')
			        carousel.scroll(jQuery.jcarousel.intval(19));
					$('#gallery_nav li.current').removeClass('current');
					$('#gallery_nav li.performances').addClass('current');
			        return false;
			    });
			}


		// BREAD CRUMB TABS 
			function find_thumbs_index(carousel, item, idx, state) {
				var thumbs_index = idx;
				$('#gallery_nav li.current').removeClass('current');
				if (thumbs_index == 1 ) { 
					// alert('thumbs_index: ' + thumbs_index + '\nphotos'); 
					$('#gallery_nav li.swings.photos').addClass('current');
				}
				if (thumbs_index == 7 ) { 
					// alert('thumbs_index: ' + thumbs_index + '\nphotos'); 
					$('#gallery_nav li.vintage.photos').addClass('current');
				}
				if (thumbs_index == 13 ) { 
					// alert('thumbs_index: ' + thumbs_index + '\nmarketing'); 
					$('#gallery_nav li.marketing').addClass('current');
				}
				if (thumbs_index == 19 ) { 
					// alert('thumbs_index: ' + thumbs_index + '\nperformances'); 
					$('#gallery_nav li.performances').addClass('current');
				}

			}                 

   	} break;



	/* * * * * * * * * STRIPPED * * * * * * * * */
	default: {   
	
		$(document).ready(function(){  
			
			$('#gallery').addClass('stripped');
			$('#main_content').show(); 
			$('#thumbs .photos.swings').show(); 
			$('#gallery_nav li.photos.swings').addClass('current'); 
			load_photo('photos','swings','001');
			
			
			$('#gallery_nav .swings.photos').click(function() {
				$('#thumbs li:visible').hide();
				$('#gallery_nav li.current').removeClass('current');
				$('#gallery_nav li.photos.swings').addClass('current'); 
				$('#thumbs .photos.swings').show();
		        return false;
		    });
			$('#gallery_nav .vintage.photos').click(function() {
				$('#thumbs li:visible').hide();
				$('#gallery_nav li.current').removeClass('current');
				$('#gallery_nav li.photos.vintage').addClass('current'); 
				$('#thumbs .photos.vintage').show();
		        return false;
		    });     
			$('#gallery_nav .marketing').click(function() {
				$('#thumbs li:visible').hide();
				$('#gallery_nav li.current').removeClass('current');
				$('#gallery_nav li.marketing').addClass('current'); 
				$('#thumbs .marketing').show();
		        return false;
		    });  
			$('#gallery_nav .performances').click(function() {
				$('#thumbs li:visible').hide();
				$('#gallery_nav li.current').removeClass('current');
				$('#gallery_nav li.performances').addClass('current'); 
				$('#thumbs .performances').show(); 
		        return false;
		    });
			   
		});  
		
 
	
  
	
	} break;           

} 	/* * * * * * * * * END STRIPPED * * * * * * * * */



          

	// PHOTO FUNCTIONS
	 	function load_photo(type,collection,photo) {
			$('#performances:visible').hide();
			$('#photo_container:hidden').show();
			/* CURRENTLY NOT NEEDED
			var this_article = $('#article>div').attr('id');
			if (this_article != collection) {
				// alert('loading photos')
				$('#article').load('_photos',function(){
					$('#gallery').addClass('presentation');
					$('#photo').attr('src','/gallery/_' + collection + '/' + type + '/' + photo_size + '/' + photo + '.jpg').fadeIn('slow');
					$('#reflection').attr('src','/gallery/_' + collection + '/' + type + '/' + photo_size + '/reflections/' + photo + '.png');
				});
			} else {
				// alert('changing photo');
				$('#photo').attr('src','/gallery/_' + collection + '/' + type + '/' + photo_size + '/' + photo + '.jpg').fadeIn('slow');
				$('#reflection').attr('src','/gallery/_' + collection + '/' + type + '/' + photo_size + '/reflections/' + photo + '.png');
			} 
			*/
			// NOTE... NEED PRELOAD AND THEN ADD IMAGES TOGEHTER (perhaps with fadeIn() )
			if (type == 'photos') { 
				$('#photo').attr('src','/gallery/photos/' + collection + '/' + photo_size + '/' + photo + '.jpg').fadeIn('slow'); 
				$('#reflection').attr('src','/gallery/photos/' + collection + '/' + photo_size + '/reflections/' + photo + '.png').fadeIn('slow'); 
			}
			if (type == 'marketing') { 
				$('#photo').attr('src','/gallery/marketing/' + photo_size + '/' + photo + '.jpg').fadeIn('slow');
				$('#reflection').attr('src','/gallery/marketing/' + photo_size + '/reflections/' + photo + '.png').fadeIn('slow'); 
			}
		}




	// VIDEO FUNCTIONS (EXAXTLY THE SAME AS THOSE USED ON PRESS
		function load_performances(video) {
			$('#photo_container').hide();
			$('#performances').show();
			$('#performances .info').hide();
			$('#performances #metropolitain_room').show(); 
		}

		function play_video(video) {
			// FADE OUT PAGE MUSIC
			try {  
				fadeOut_music('300'); 
			}
			catch (error) {}
			try { 
				if (document.QT.playing == true) { document.QT.Stop(); } 
				else if (document.QT.playing == false) { document.QT.Play(); }
			}
			catch (error) {
				// alert('Video loading');
				$('#media_container').removeClass('inside box');
				$('#media_container').media( {
					width:320, // set in css
					height:256, // 240 + 16
					autoplay:true, // plays as soon as possible
					src:'/gallery/performances/' + video + '.mp4',
					attrs: { 	// EMBED ATTRIBUTES 	
						name:'QT',
						controller:'true',
						enablejavascript:'true',
						kioskmode:'true'
						},  
					params: { 	// OBJECT ATTRIBUTES
						name:'QT',
						controller:'true',
						enablejavascript:'true',
						kioskmode:'true'
						}, 
					caption: false // supress caption text
					}
				);
			}
		}
