// Showtime
// <c>2010 Sue Malsoft
// gImageCapableBrowser - is this browser hip to images? Set up
// a global variable so that we don't have to keep calling a function
// (useful if the function becomes costly to compute).

var gImageCapableBrowser = canManipulateImages();

// the current image being displayed

var iCurrent = 0 ;

// canManipulateImages - check if the browser we're using can do
// clever stuff with document images.

function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}

// 
function identifyPicture(picStr){
	var a = picStr.substring(0,5) ;
	a.toLowerCase() ;
	if( a == 'images' ) {
		// our picture
		return 0;
	}
	if( a == 'http:' ){
		if( ( picStr.indexOf( '.swf?file' ) !=-1 ) || ( picStr.indexOf( '.swf?clip' ) !=-1 ) ){
//		if( ( picStr.indexOf( '.swf?file' ) !=-1 ) ){
			//shockwave file
			return 2;
		} else {
			if(picStr.indexOf( '.youtube.com/watch?v=' ) != -1 ){
				//youtube file
				return 3;
			} else {
				if( (picStr.indexOf( '.asx' ) != -1 )){
					//media player file
					return 4;
				} else {
					// their picture
					return 1;
				}
			}
						
		}
	}
	return 0;
}

function getPlayer(picStr){
	var temp = new Array();
	temp = picStr.split('?');
	return temp[0] ;
}

function getPlayerFile(picStr){
	var temp = new Array();
	if( picStr.indexOf( 'file=' ) != -1 ) {
		temp = picStr.split('file=');
		picStr = temp[1] ;
	}
	if( picStr.indexOf( '&image=') != -1 ) {
		temp = picStr.split('&image=');
	} else {
		if( picStr.indexOf( '&amp;image=') != -1 ) {
			temp = picStr.split('&amp;image=');
		}
	}
	return temp[0] ;
}

function getPlayerImage(picStr){
	var temp = new Array();
	if( picStr.indexOf( 'file=' ) != -1 ) {
		temp = picStr.split('file=');
		picStr = temp[1] ;
	}
	if( picStr.indexOf( '&image=') != -1 ) {
		temp = picStr.split('&image=');
	} else {
		if( picStr.indexOf( '&amp;image=') != -1 ) {
			temp = picStr.split('&amp;image=');
		}
	}
	return temp[1] ;
}

// loadPosterImage

function ShowTimeHeadLineImagePoster(imageNum) {
	if (gImageCapableBrowser) {
		if( iCurrent != imageNum ) {
			var el ;
			var img ;
//			el = document.getElementById('ShowTimeHeadLineImage');
			switch(identifyPicture( myArray[imageNum].image )){
				case 0:
				case 1:						//simple images
//					el.src = myArray[imageNum].image;
					document.getElementById('ShowTimeHeadLineImage2').innerHTML= '<img id="ShowTimeHeadLineImage" src="'+myArray[imageNum].image+'" />' ;
					break;
				case 2:						// shockwave movies
					img = getPlayerImage(myArray[imageNum].image) ;
//					el.src = img;
					document.getElementById('ShowTimeHeadLineImage2').innerHTML= '<img id="ShowTimeHeadLineImage" src="'+img+'" />' ;
					break;
				case 3:						// youtube movie
					img = 'images/YouTube-CC.jpg' ;
					document.getElementById('ShowTimeHeadLineImage2').innerHTML= '<img id="ShowTimeHeadLineImage" src="'+img+'" />' ;
					break;
				case 4:						// windows media
					img = getPlayerImage(myArray[imageNum].image) ;
//					el.src = img;
					document.getElementById('ShowTimeHeadLineImage2').innerHTML= '<img id="ShowTimeHeadLineImage" src="'+img+'" />' ;
					break;
				default:
					break;
			}			
						
			
			el = document.getElementById('ShowTimej1');
			el.href = myArray[imageNum].hotlink ;
			el = document.getElementById('ShowTimej2');
			el.href = myArray[imageNum].hotlink ;
			el = document.getElementById('ShowTimej3');
			el.href = myArray[imageNum].hotlink ;
			ShowtimeSetTNImgBorder( iCurrent, "#eaeceb" ) ;
			document.getElementById('showtimehl').innerHTML= myArray[imageNum].title ;
			document.getElementById('showtimetxt').innerHTML= myArray[imageNum].text ;
			ShowtimeSetTNImgBorder( imageNum, "#FF0000" ) ;
			iCurrent = imageNum;
			return false;
		}
		return true;
	}
	else {
		return true;
	}
}

function ShowtimeSetTNImgBorder( imageNum, col) {
	var el = document.getElementById('ShowTimeTN'+imageNum );
	el.style.backgroundColor = col  ;
}

function ShowTimeDisplayThumbnailImages(){
	for (var imageNum = 0; imageNum < myArray.length; imageNum++) {
		ShowTimeDisplayThumbnailImage(imageNum);
	}
}

function ShowTimeDisplayThumbnailImages2(){
	for (var imageNum = 0; imageNum < myArray.length; imageNum++) {
		ShowTimeDisplayThumbnailImage2(imageNum);
	}
}

function ShowTimeDisplayThumbnailImage2(imageNum) {
//	document.writeln( ' 	<div class="ShowTimeTNimage" id="ShowTimeTH'+imageNum+'">' );
	document.writeln( ' 	<div class="ShowTimeTNimage" >' );
	var picType = identifyPicture( myArray[imageNum].image ) ;
	switch(picType){
		case 0:
			document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="' + myArray[imageNum].image +'" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
			break;
		case 1:
			document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="' + myArray[imageNum].image +'" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
			break;
		case 2:
			var img = getPlayerImage(myArray[imageNum].image) ;
			document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="' + img +'" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
			break;
		case 3:
			document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="images/YouTube-CC.jpg" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
			break;
		case 4:
			var img = getPlayerImage(myArray[imageNum].image) ;
			document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="' + img +'" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
			break;
		default:
			break;
			
	}

	
//	if( a != "http:" ) {
//		document.writeln( ' 		<img id="ShowTimeTN'+imageNum+'" src="' + myArray[imageNum].image +'" alt="'+myArray[imageNum].title+'" onMouseOver="return(ShowTimeHeadLineImagePoster('+imageNum+'))">' ) ;
//	} else {	
//		document.writeln( '			<p>' );
//		document.writeln( '				<object type="application/x-shockwave-flash" style="width:118px; height:76px;" data="' + myArray[imageNum].image + '">' );
//		document.writeln( '					<param name="movie" value="'  + myArray[imageNum].image + '" />' );
//		document.writeln( '				</object>' );
//		document.writeln( '			</p>' );
//	}

	document.writeln( ' 		<div class="ShowTimeTNheadline">' + myArray[imageNum].title + '</div>' );
	document.writeln( ' 	</div>' );
}

function ShowTimeDisplayThumnailHeadlines(){
	for (var imageNum = 0; imageNum < myArray.length; imageNum++) {
		document.writeln( ' <td class="ShowTimeTNheadline">' );
//		document.writeln( ' <td>' );
		ShowTimeDisplayHeadline(imageNum);
		document.writeln( ' </td>' );
	}
}

function ShowTimeDisplayHeadline(imageNum) {
	document.writeln( myArray[imageNum].title );
}

function ShowTimeDisplay() {
	var img;
	document.writeln( '<div id="ShowTime">' );
	document.writeln( '	<div id="wrapper">' );
	document.writeln( '		<div id="firefox-bug-fix">' );
	document.writeln( '			<div id="ShowTimeImageBorder" class="ShowTimeColumns" >' );
	document.writeln( '				<a id="ShowTimej1" href="'+myArray[0].hotlink+'">' ) ;
	document.writeln( '					<div id="ShowTimeHeadLineImage2">' ) ;
	switch(identifyPicture( myArray[0].image )){
		case 0:
		case 1:
			document.writeln( ' 		       <img id="ShowTimeHeadLineImage" src="'+myArray[0].image+'" />' ) ;
			break;
		case 2:
			img = getPlayerImage(myArray[0].image) ;
			document.writeln( ' 		       <img id="ShowTimeHeadLineImage" src="'+img+'" />' ) ;
			break;
		case 3:
			document.writeln( ' 		       <img id="ShowTimeHeadLineImage" src="images/YouTube-CC.jpg" />' ) ;
			break;
		case 4:
			img = getPlayerImage(myArray[0].image) ;
			document.writeln( ' 		       <img id="ShowTimeHeadLineImage" src="'+img+'" />' ) ;
			break;
		default:
			document.writeln( '			<p>' );
			document.writeln( '				<object type="application/x-shockwave-flash" style="width:420px; height:300px;" data="'+myArray[0].image+'">' );
			document.writeln( '					<param name="movie" value="'+myArray[0].image+'" />' );
			document.writeln( '				</object>' );
			document.writeln( '			</p>' );
			break;
	}
	document.writeln( '					</div><!-- end of ShowTimeHeadLineImage2 -->' ) ;
	document.writeln( '				</a>' );
	document.writeln( '			</div><!-- end of ShowTimeColumns -->' );
	document.writeln( '			<div class="ShowTimeTextBorder">' );
	document.writeln( '				<div id="ShowTimeTextCell"  class="ShowTimeColumns">' );
	document.writeln( '					<a id="ShowTimej2" href="'+myArray[0].hotlink+'">' );
	document.writeln( '						<h1 id="showtimehl">'+myArray[0].title+'</h1>' );
	document.writeln( '					</a>' );
	document.writeln( '					<div id="showtimetxt">'+myArray[0].text+'</div><!-- end of showtimetxt -->' );
	document.writeln( '					<div class="readmore">' );
	document.writeln( '						<a class="more" id="ShowTimej3" href="'+myArray[0].hotlink+'">&hellip;read more</a>' );
	document.writeln( '					</div><!-- readmore -->' ) ;
	document.writeln( '				</div><!-- end of ShowTimeColumns -->' );
	document.writeln( '          </div>');
	document.writeln( '		</div><!-- end of firefox-bug-fix -->' );
	document.writeln( '	</div><!-- End of wrapper -->' );
	document.writeln( ' <div id="wrapper">' );
	document.writeln( ' 	<div id="firefox-bug-fix">' );
	document.writeln( ' 		<div id="ShowtimeTNContainer">')
	for (var imageNum = 0; imageNum < myArray.length; imageNum++) {
		ShowTimeDisplayThumbnailImage2(imageNum);
	}
//	ShowTimeDisplayThumbnailImages2();
	ShowtimeSetTNImgBorder( iCurrent, '#FF0000') ;
	document.writeln( ' 		</div><!-- end of ShowtimeTNContainer -->' );
	document.writeln( ' 	</div><!-- end of firefox-bug-fix -->' );
	document.writeln( ' </div><!-- end of wrapper -->' );
	document.writeln( '</div><!--ShowTime-->' ) ;
	document.writeln( '<hr/>' ) ;
}



// All images MUST BE OF THE SAME SIZE, since
// the dimensions of the first image will be
// used for all subsequent images.
// All the images for your slide show need to 
// be stored in the same directory.
// You can use any group and any 
// number of images. Place your images within 
// each set of quotation marks below.
// If the images are all in your Angelfire 
// images subdirectory, makes sure the name 
// of each image starts with "images/" like
// in the example below.
            	
function displayMovieOrImage( picSource, width, height ){
	switch(identifyPicture( picSource )){
		case 2:
			document.writeln( '<!-- shockwave movie --->' );
			document.writeln( '<p>' );
			document.writeln( '  <object type="application/x-shockwave-flash" style="width:' +width+ 'px; height:' +height+ 'px;" data="' + picSource + '">' ) ;
			document.writeln( '		<param name="movie" value="' +picSource+ '" />' );
			document.writeln( '  </object>' );
			document.writeln( '</p>');
			document.writeln( '<!-- end of shockwave movie --->' );
			break;
		case 3:
			document.writeln( '<!-- YouTube movie --->' );
			document.writeln( '<p>' );
			document.writeln( '  <object type="application/x-shockwave-flash" style="width:' +width+ 'px; height:' +height+ 'px;" data="' + picSource + '">' ) ;
			document.writeln( '		<param name="movie" value="' +picSource+ '" />' );
			document.writeln( '  </object>' );
			document.writeln( '</p>');
			document.writeln( '<!-- YouTube movie --->' );
			break;
		case 4:
		var film= getPlayerFile( myArray[0].image );
			document.writeln( '<!–- begin embedded WindowsMedia file… --–>' );
			document.writeln( '<p>' );
			document.write(   ' <object id="mediaPlayer" width="' +width+ '" height="' +height+ '" ' ) ;
			document.write(   'classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ' );
			document.write(   'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" ' );
			document.write(   'standby="Loading Windows Media Player components..." ' );
			document.write(   'type="application/x-oleobject" ' );
			document.writeln( '>' ) ;
			document.writeln( '  <param name="fileName" value="' +film+ '" />' ) ;
			document.writeln( '  <param name="animationatStart" value="true" />' ) ;
			document.writeln( '  <param name="transparentatStart" value="true" />' ) ;
			document.writeln( '  <param name="autoStart" value="true" />' ) ;
			document.writeln( '  <param name="showControls" value="true" />' ) ;
			document.writeln( '  <param name="loop" value="false" />' ) ;
			document.write(   '  <embed type="application/x-mplayer2" ' );
			document.write(   'src="' +film+' " width="' +width+ '" height="' +height+ '" ' ); 
/*			document.write(   'id="mediaPlayer" name="mediaPlayer" displaysize="4" autosize="-1" bgcolor="darkblue" ' );		
			document.write(   'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" ' );
			document.write(   'showcontrols="true" showtracker="-1" showdisplay="0" showstatusbar="-1" videoborder3d="-1" width="280" height="200" ' );
			document.write(   'src="' +film+ '" autostart="true" designtimesp="5311" loop="true" >' ) ;		*/
			document.writeln( ' >' ) ;
			document.writeln( '  </embed>' ) ;
			document.writeln( '</object>' ) ;
			document.writeln( '</p>');
			document.writeln( '<!-– …end embedded WindowsMedia file --–>' ) ;
			break;
		default:
			document.writeln( '<!-- simple picture --->' ) ;
			document.writeln( '     <img src="' +picSource+ '" alt="" width="' +width+ '" height="' +height+ '"/>' );
			document.writeln( '<!-- end of simple picture --->' ) ;
			break;
	}
}
