// Scripts for /Guitars/

// VARIABLES
var g_iCurrentPhoto = Number(1);
var g_iSlideshowTimer = Number(0);
var g_bPlaying = false;
var g_iGuitarsMenuTimerID = Number( 0 );
var g_strVisibleGuitarsMenu = String("");

// FUNCTIONS

// Called when the page loads, initialize the page
function GuitarsPageLoaded() {

	// Load in the logos
	LoadLogos();
	
	// Fix the channel transparency, if needed
	FixTransparency();
	
	// Show the proper logo
	ShowLogo();
	
	// Show the photo caption, if any
	ShowPhotoCaption();
	
	// Show the Photo Controls, if needed
	ShowPhotoControls();
	
	// Make the tab and the channel visible
	ShowInterface();

	// Start the slideshow, if any
	g_bPlaying = ( g_iPhotoCount > 1 )
	StartSlideshow();

	// Make the page as having finished loaded
	bLoaded=true;
}

// Load the transparent logos, fixed for IE 6
function LoadLogos() {
	if ( navigator.appVersion.indexOf( "MSIE") != -1 ) {
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
	
		if ( version < 5.5 ) {
			// Use gif instead of PNG for Pre 5.5 IE
			document.images['guitars-logo-red-blank'].src = '/Guitars/Shared/Images/Logo-Red.gif';
			document.images['guitars-logo-white-blank'].src = '/Guitars/Shared/Images/Logo-White.gif';
		} else if ( version >= 7 ) {
			document.images['guitars-logo-red-blank'].src = '/Guitars/Shared/Images/Logo-Red.png';
			document.images['guitars-logo-white-blank'].src = '/Guitars/Shared/Images/Logo-White.png';
		} else {
			DocumentObject( 'guitars-logo-red-blank', true ).filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/Guitars/Shared/Images/Logo-Red.png\', sizingMethod=\'scale\');'
			DocumentObject( 'guitars-logo-white-blank', true ).filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/Guitars/Shared/Images/Logo-White.png\', sizingMethod=\'scale\');'
		}
	} else {
		document.images['guitars-logo-red-blank'].src = '/Guitars/Shared/Images/Logo-Red.png';
		document.images['guitars-logo-white-blank'].src = '/Guitars/Shared/Images/Logo-White.png';
	}
}

// Fix the channel transparency in IE 6
function FixTransparency() {
	if ( navigator.appVersion.indexOf( "MSIE") != -1 ) {
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])

		if ( version >= 5.5 && version < 7 ) {
			DocumentObject( 'guitars-channel-contents', true ).filter = 'alpha(opacity=90);'
		}
	}	
}

// Display the appropriate logo for the current photo
function ShowLogo() {
	DocumentObject( 'guitars-logo-red', true ).display = ( g_aPhotoLogos[(g_iCurrentPhoto-1)] == "red" ) ? "block" : "none";
	DocumentObject( 'guitars-logo-white', true ).display = ( g_aPhotoLogos[(g_iCurrentPhoto-1)] == "white" ) ? "block" : "none";
}

// Display the photo caption
function ShowPhotoCaption() {
	if ( g_aPhotoCaptions ) {
		if ( g_iPhotoCount > 1 ) {
			DocumentObject( 'guitars-photo-label-slideshow', false ).innerHTML = g_aPhotoCaptions[(g_iCurrentPhoto-1)];
		} else {
			DocumentObject( 'guitars-photo-label', false ).innerHTML = g_aPhotoCaptions[(g_iCurrentPhoto-1)];
		}
	}
}

// Hide the channel
function GuitarsHideChannel() {
	DocumentObject( 'guitars-channel-contents', true ).marginTop = '-561px';
	DocumentObject( 'guitars-tabs', true ).display = 'none';
}

// Show the channel
function GuitarsShowChannel() {
	DocumentObject( 'guitars-channel-contents', true ).marginTop = '0px';
	DocumentObject( 'guitars-tabs', true ).display = 'block';
}

// Show a rollover
function ShowRollover( strRollover ) {
	DocumentObject( strRollover + "-rollover", true ).display = 'block';
}

// Hide a rollover
function HideRollover( strRollover ) {
	DocumentObject( strRollover + "-rollover", true ).display = 'none';
}

// Make the interface visible
function ShowInterface( ) {
	DocumentObject( 'guitars-tabs', true ).display = 'block';
	DocumentObject( 'guitars-channel', true ).display = 'block';
}

// If there is more then one photo, then make the photo controls visible
function ShowPhotoControls( ) {
	if ( g_iPhotoCount > 1 ) {
		DocumentObject( 'guitars-photo-controls', true ).display = 'block';
	}
}

// Display the previous photo
function ShowPreviousPhoto( ) {
	g_iOldPhoto = g_iCurrentPhoto;
	// Show the next photo
	g_iCurrentPhoto = ((g_iCurrentPhoto+g_iPhotoCount-2)%g_iPhotoCount)+1;
	DocumentObject( 'guitar-photo-'+g_iCurrentPhoto, true ).display = 'block';
	// Hide the current photo
	DocumentObject( 'guitar-photo-'+g_iOldPhoto, true ).display = 'none';
	// Update the logo
	ShowLogo();
	// Update the caption
	ShowPhotoCaption();
}

// Pause/Play the photo slideshow
function PausePlayPhotos( ) {
	StopSlideshow();
	g_bPlaying = ! g_bPlaying;
	if ( g_bPlaying ) {
		ShowNextPhoto();
	}
}

// Display thee next photo
function ShowNextPhoto( ) {
	// Stop the slideshow, if playing
	StopSlideshow()
	// Show the next photo
	g_iOldPhoto = g_iCurrentPhoto;
	g_iCurrentPhoto = (g_iCurrentPhoto%g_iPhotoCount)+1;
	DocumentObject( 'guitar-photo-'+g_iCurrentPhoto, true ).display = 'block';
	// Hide the current photo
	DocumentObject( 'guitar-photo-'+g_iOldPhoto, true ).display = 'none';
	// Update the logo
	ShowLogo();
	// Update the caption
	ShowPhotoCaption();
	// Continue the slideshow, if playing
	StartSlideshow();
}

// Start the slideshow
function StartSlideshow( ) {
	// Clear the timeout, if any
	clearTimeout( g_iSlideshowTimer );
	// Set a new timer
	if ( g_bPlaying ) {
		g_iSlideshowTimer = setTimeout( 'SlideShowNextPhoto();', 5000 );
	}
}

function SlideShowNextPhoto( ) {
	if ( g_bPlaying ) {
		if ( g_iCurrentPhoto == g_iPhotoCount ) {
			g_bPlaying = false;
		}
		ShowNextPhoto();
	}
}

function StopSlideshow( ) {
	// Clear the timeout, if any
	clearTimeout( g_iSlideshowTimer );
}

function GuitarsMenuRollOn( strMenu ) {
	// Hide the previous menu, if any
	clearTimeout( g_iGuitarsMenuTimerID );
	if ( strMenu != g_strVisibleGuitarsMenu ) {
		HideGuitarsMenus();
	}
	// Show the menu
	DocumentObject( strMenu, true ).display = 'block'
	g_strVisibleGuitarsMenu = strMenu;
}

function GuitarsMenuRollOff() {
	g_iGuitarsMenuTimerID = setTimeout( 'HideGuitarsMenus();', 1500 );
}

function HideGuitarsMenus() {
	if ( g_strVisibleGuitarsMenu != "" ) {
		clearTimeout( g_iGuitarsMenuTimerID );
		g_iGuitarsMenuTimerID = 0;
		DocumentObject( g_strVisibleGuitarsMenu, true ).display = 'none';
	}
}

function GuitarsMenuSubroll( bOn ) {
	clearTimeout( g_iGuitarsMenuTimerID );
	if ( ! bOn ) {
		g_iGuitarsMenuTimerID = setTimeout( 'HideGuitarsMenus();', 1500 );
	}
}