/*

*	Charles - November 2006 - Initial Writing

*/



var dom = document.getElementById   ? true:false;

var nn4 = document.layers           ? true:false;

var ie4 = document.all              ? true:false;

var mac = false;

if (navigator.userAgent.toLowerCase().indexOf("mac") != -1){

	mac = true;

}



function imgZoomer(objImg, width, height){

	objImg["width"]  = objImg["width"]  + width;

	objImg["height"] = objImg["height"] + height;

}



function imgUnZoomer(objImg, width, height){

	objImg["width"]  = objImg["width"]  - width;

	objImg["height"] = objImg["height"] - height;

}



function findPosX(obj){

	var curleft = 0;

	if (obj.offsetParent){

		while (obj.offsetParent){

			curleft += obj.offsetLeft

			obj = obj.offsetParent;

		}

	}

	else if (obj.x){

		curleft += obj.x;

	}

	return curleft;

}



function findPosY(obj){

	var curtop = 0;

	if (obj.offsetParent){

		while (obj.offsetParent){

			curtop += obj.offsetTop

			obj = obj.offsetParent;

		}

	}

	else if (obj.y){

		curtop += obj.y;

	}



	return curtop;

}



function lightup_chuck(imageobject, opacity){

	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5){

		//Others

		imageobject.style.MozOpacity = opacity / 100;

	}

	else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4){

		//For Microsoft

		imageobject.style.filter = "Alpha(opacity=" + opacity + ")";

	}

}



function toggle(obj) {

	var el = document.getElementById(obj);

	if ( el.style.display != 'none' ) {

		el.style.display = 'none';

	}

	else {

		el.style.display = '';

	}

}





function fncGetBeginNumFromImgID(strImageID){

		if( strImageID.match(/^img_[0-9]{1,3}$/) ){

			return parseInt(  strImageID.substr( strImageID.lastIndexOf("_") + 1, strImageID.length-strImageID.lastIndexOf("_") )  );

		}

		else{

			return false;

		}

}





function fncSwap(strSwapToBeginIndex, strSwapToFinalIndex){



	//alert('To Begin: ' + strSwapToBeginIndex + "\n\nTo Finish: " +  strSwapToFinalIndex + "\n\nBegin is Next?: " + blnIsBeginNext );



	//Set Begin

	blnIsBeginNext = true;

	strStartEndText = strconstStartEndText;

	document.getElementById("divDownloadArea").style.visibility = "hidden";

	indexOnClick(document.getElementById(strSwapToBeginIndex), 'skipval');



	indexOnClick(document.getElementById(strSwapToFinalIndex), 'skipval');

}







//have to validate that begin is before next - cannot cut backwards

function indexOnClick(objImage, blnDoValidate){



	if( typeof document.getElementById(objImage.id) == 'undefined') {

		return;

	}





	if( blnIsBeginNext == true ){



		if( blnDoValidate == null ){

			//Beginning should not be the final scene          --stuck on swap ?

			if( objImage.id == CONST_strFinal_image_id ){

				alert("Beginning Scene Shouldn't be the Last Scene");

				return;

			}

		}







		document.images['begin_image'].src = arrIndexes[objImage.id].strImageName;

		document.getElementById("td_begin_note").innerHTML = 'Start Time: ' +  arrIndexes[objImage.id].iPlaytimeString;

		document.getElementById("divDownloadArea").style.visibility = "hidden";



		blnIsBeginNext = false;

		strStartEndText = strconstFinishEndText;

		strBegin_image_id = objImage.id;





		//Wipe the End Image

		document.images['end_image'].src = strImageHome + 'director.jpg';

		document.getElementById("td_end_note").innerHTML = '&nbsp;';

		// End Wipe



	}

	else{



		var validate_begin_num = fncGetBeginNumFromImgID(strBegin_image_id);

		var validate_final_num = fncGetBeginNumFromImgID(objImage.id);



		if( blnDoValidate == null ){



			//Check that End is after the beginning

			//alert( 	"Begin: " + validate_begin_num + "\n\n" + "Final: " + validate_final_num 	);



			if( validate_begin_num == validate_final_num ){

				alert("Begin and End can't be the same scene");

				return;

			}

			else if( validate_final_num < validate_begin_num){

				//alert("Final Scene must come after the Beginning scene");

				fncSwap(objImage.id, strBegin_image_id);

				return;

			}



		}





		var iCLength   = 999999;

		var iMB		   = 0;

		var dblTempSec = 0;



		document.images['end_image'].src = arrIndexes[objImage.id].strImageName;

		document.getElementById("td_end_note").innerHTML = 'End Time: ' +  arrIndexes[objImage.id].iPlaytimeString;







		dblTempSec = parseInt(arrIndexes[objImage.id].iSeconds) - parseInt(arrIndexes[strBegin_image_id].iSeconds);



		if( dblTempSec < 60 ){

			document.getElementById("divSelectedSeconds").innerHTML = 'Scene Time: ' +  Math.ceil(dblTempSec) + " Seconds";

		}

		else{

			document.getElementById("divSelectedSeconds").innerHTML = 'Scene Time: ' +  Math.ceil( dblTempSec/ 60 ) + " Minutes";

		}



		//  http://mediacutter1.vixeo.com/Fuck_Club/mpg/highband/0/Fuck_Club_1.mpg/20:25/30:35/999999/Fuck_Club_1-20:25-30:35.mpg





		if( typeof arrBitRates["dvd"] != 'undefined' ){

			iCLength =  (arrBitRates["dvd"][1]/(iScenePlayMins*60))  *  ( arrIndexes[objImage.id].iSeconds  - arrIndexes[strBegin_image_id].iSeconds ) ;

			iCLength =  Math.round( iCLength +  ((iCLength * 30) / 100) );

			iCLength = iCLength + arrBitRates["dvd"][2];



			iMB = ((arrBitRates["dvd"][1]/(iScenePlayMins*60))/1024/1024) *  (parseInt(arrIndexes[objImage.id].iSeconds) - parseInt(arrIndexes[strBegin_image_id].iSeconds));



			if( isClientLoggedIn == '1' ){

				document.getElementById("tdlnk_download_dvd").innerHTML  = "<a href='" + strMovieHost + "/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/dvd/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_dvd' style='color: Red;'>Premium Quality (" + Math.ceil(iMB) + " MB)</a>";

				//document.getElementById("tdlnk_download_dvd").innerHTML  = "<a href='" + strMovieHost + "/" + strMovieFolder + "/mpg/dvd/"  + iSceneIsAL + "/" + strSceneFileName + "/" + arrIndexes[strBegin_image_id].iPlaytimeString + "/" + arrIndexes[objImage.id].iPlaytimeString + "/" + iCLength + "/" + strSceneFileName.replace(/\.mpg/, "") + "-" + arrIndexes[strBegin_image_id].iPlaytimeString.replace(/:/, '_') + "-" + arrIndexes[objImage.id].iPlaytimeString.replace(/:/, '_') + "_dvd.mpg" + "' id='lnkDownload_dvd' style='color: Red;'>Premium Quality (" + Math.ceil(iMB) + " MB)</a>";

				//document.getElementById("tdlnk_download_dvd").innerHTML  = document.getElementById("tdlnk_download_dvd").innerHTML +  "<br><a href='http://206.53.57.39/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/dvd/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_dvd' style='color: Red;'>Dev Test - Premium Quality (" + Math.ceil(iMB) + " MB)</a><br><hr>";

			}

			else{

				document.getElementById("tdlnk_download_dvd").innerHTML  = "<a href='http://secure.vixeo.com' id='lnkDownload_dvd' style='color: Red;'>Premium Quality (" + Math.ceil(iMB) + " MB)</a>";

			}

		}

		else{

			document.getElementById("tdlnk_download_dvd").innerHTML  = ""

		}



		//////////////////////////////////////////////////////////////////////////////



		if( typeof arrBitRates["highband"] != 'undefined' ){

			iCLength =  (arrBitRates["highband"][1]/(iScenePlayMins*60))  *  ( arrIndexes[objImage.id].iSeconds  - arrIndexes[strBegin_image_id].iSeconds ) ;

			iCLength =  Math.round( iCLength +  ((iCLength * 30) / 100) );

			iCLength = iCLength + arrBitRates["highband"][2];



			iMB = ((arrBitRates["highband"][1]/(iScenePlayMins*60))/1024/1024) *  (parseInt(arrIndexes[objImage.id].iSeconds) - parseInt(arrIndexes[strBegin_image_id].iSeconds));



			if( isClientLoggedIn == '1' ){

				document.getElementById("tdlnk_download_highband").innerHTML  = "<a href='" + strMovieHost + "/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/highband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_highband' style='color: Red;'>High Quality (" + Math.ceil(iMB) + " MB)</a>";

				//document.getElementById("tdlnk_download_highband").innerHTML  = "<a href='" + strMovieHost + "/" + strMovieFolder + "/mpg/highband/"  + iSceneIsAL + "/" + strSceneFileName + "/" + arrIndexes[strBegin_image_id].iPlaytimeString + "/" + arrIndexes[objImage.id].iPlaytimeString + "/" + iCLength + "/" + strSceneFileName.replace(/\.mpg/, "") + "-" + arrIndexes[strBegin_image_id].iPlaytimeString.replace(/:/, '_') + "-" + arrIndexes[objImage.id].iPlaytimeString.replace(/:/, '_') + "_hig.mpg" + "' id='lnkDownload_highband' style='color: Red;'>High Quality (" + Math.ceil(iMB) + " MB)</a>";

				//document.getElementById("tdlnk_download_highband").innerHTML  = document.getElementById("tdlnk_download_highband").innerHTML +  "<br><a href='http://206.53.57.39/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/highband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_highband' style='color: Red;'>Dev Test - High Quality (" + Math.ceil(iMB) + " MB)</a><br><hr>";

			}

			else{

				document.getElementById("tdlnk_download_highband").innerHTML  = "<a href='http://secure.vixeo.com' id='lnkDownload_highband' style='color: Red;'>High Quality (" + Math.ceil(iMB) + " MB)</a>";

			}

			/*alert(

					"bytes[1]: "        + arrBitRates["highband"][1]     				+ "\n" +

					"iScenePlayMins: "  + iScenePlayMins       						+ "\n" +

					"x this: "  		+ arrIndexes[objImage.id].iSeconds  		+ "\n" +

					"minus this: "    	+ arrIndexes[strBegin_image_id].iSeconds    + "\n"

			);*/

		}

		else{

			document.getElementById("tdlnk_download_highband").innerHTML  = ""

		}







		//////////////////////////////////////////////////////////////////////////////



		iCLength =  (arrBitRates["midband"][1]/(iScenePlayMins*60))  *  ( arrIndexes[objImage.id].iSeconds  - arrIndexes[strBegin_image_id].iSeconds ) ;

		iCLength =  Math.round( iCLength +  ((iCLength * 30) / 100) );

		iCLength = iCLength + arrBitRates["midband"][2];



		iMB = ((arrBitRates["midband"][1]/(iScenePlayMins*60))/1024/1024) *  (parseInt(arrIndexes[objImage.id].iSeconds) - parseInt(arrIndexes[strBegin_image_id].iSeconds));



		if( isClientLoggedIn == '1' ){

			document.getElementById("tdlnk_download_midband").innerHTML  = "<a href='" + strMovieHost + "/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/midband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_midband' style='color: Red;'>Medium Quality (" + Math.ceil(iMB) + " MB)</a>";

			//document.getElementById("tdlnk_download_midband").innerHTML  = "<a href='" + strMovieHost + "/" + strMovieFolder + "/mpg/midband/"  + iSceneIsAL + "/" + strSceneFileName + "/" + arrIndexes[strBegin_image_id].iPlaytimeString + "/" + arrIndexes[objImage.id].iPlaytimeString + "/" + iCLength + "/" + strSceneFileName.replace(/\.mpg/, "") + "-" + arrIndexes[strBegin_image_id].iPlaytimeString.replace(/:/, '_') + "-" + arrIndexes[objImage.id].iPlaytimeString.replace(/:/, '_') + "_mid.mpg" + "' id='lnkDownload_midband' style='color: Red;'>Medium Quality (" + Math.ceil(iMB) + " MB)</a>";

			//document.getElementById("tdlnk_download_midband").innerHTML  = document.getElementById("tdlnk_download_midband").innerHTML +  "<br><a href='http://206.53.57.39/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/midband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_midband' style='color: Red;'>Dev Test - Medium Quality (" + Math.ceil(iMB) + " MB)</a><br><hr>";

		}

		else{

			document.getElementById("tdlnk_download_midband").innerHTML  = "<a href='http://secure.vixeo.com' id='lnkDownload_midband' style='color: Red;'>Medium Quality (" + Math.ceil(iMB) + " MB)</a>";

		}



		//////////////////////////////////////////////////////////////////////////////



		iCLength =  (arrBitRates["lowband"][1]/(iScenePlayMins*60))  *  ( arrIndexes[objImage.id].iSeconds  - arrIndexes[strBegin_image_id].iSeconds ) ;

		iCLength =  Math.round( iCLength +  ((iCLength * 30) / 100) );

		iCLength = iCLength + arrBitRates["lowband"][2];



		iMB = ((arrBitRates["lowband"][1]/(iScenePlayMins*60))/1024/1024) *  (parseInt(arrIndexes[objImage.id].iSeconds) - parseInt(arrIndexes[strBegin_image_id].iSeconds));



		if( isClientLoggedIn == '1' ){

			document.getElementById("tdlnk_download_lowband").innerHTML  = "<a href='" + strMovieHost + "/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/lowband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_lowband' style='color: Red;'>Low Quality (" + Math.ceil(iMB) + " MB)</a>";

			//document.getElementById("tdlnk_download_lowband").innerHTML  = "<a href='" + strMovieHost + "/" + strMovieFolder + "/mpg/lowband/"  + iSceneIsAL + "/" + strSceneFileName + "/" + arrIndexes[strBegin_image_id].iPlaytimeString + "/" + arrIndexes[objImage.id].iPlaytimeString + "/" + iCLength + "/" + strSceneFileName.replace(/\.mpg/, "") + "-" + arrIndexes[strBegin_image_id].iPlaytimeString.replace(/:/, '_') + "-" + arrIndexes[objImage.id].iPlaytimeString.replace(/:/, '_') + "_low.mpg" + "' id='lnkDownload_lowband' style='color: Red;'>Low Quality (" + Math.ceil(iMB) + " MB)</a>";

			//document.getElementById("tdlnk_download_lowband").innerHTML  = document.getElementById("tdlnk_download_lowband").innerHTML +  "<br><a href='http://206.53.57.39/cgi-bin/vdo/wmv/" + strMovieFolder + "/WMV/lowband/" + strSceneFileName + "?" + arrIndexes[strBegin_image_id].iSeconds + "-" + arrIndexes[objImage.id].iSeconds + "' id='lnkDownload_lowband' style='color: Red;'>Dev Test - Low Quality (" + Math.ceil(iMB) + " MB)</a><br>";

		}

		else{

			document.getElementById("tdlnk_download_lowband").innerHTML  = "<a href='http://secure.vixeo.com' id='lnkDownload_lowband' style='color: Red;'>Low Quality (" + Math.ceil(iMB) + " MB)</a>";

		}



		//////////////////////////////////////////////////////////////////////////////





		document.getElementById("divDownloadArea").style.visibility = "visible";





		blnIsBeginNext = true;

		strStartEndText = strconstStartEndText;

		strFinal_image_id = objImage.id;



	}







	//----- Visual Select-a-Mundo -------------------------------------

	var very_starter = fncGetBeginNumFromImgID(CONST_strBegin_image_id);

	var very_ender   = fncGetBeginNumFromImgID(CONST_strFinal_image_id);



	var current_starter = fncGetBeginNumFromImgID(strBegin_image_id);

	var current_ender   = fncGetBeginNumFromImgID(strFinal_image_id);



	/*

	alert(

			"very_starter: "     + very_starter     + "\n" +

			"very_ender: "       + very_ender       + "\n" +

			"current_starter: "  + current_starter  + "\n" +

			"current_ender: "    + current_ender    + "\n"

	);

	*/



	for( var cntMiddle = very_starter ;  cntMiddle <= very_ender ; cntMiddle++){



		if(  (cntMiddle >= current_starter && cntMiddle <=  current_ender) ||  (current_starter > current_ender && current_starter == cntMiddle) ){

			document.getElementById("pos_" + cntMiddle + "_innertop").innerHTML    = '<img src="' + strImageHome + 'filmstrip_green.jpg" height="10" width="' + CONST_image_width + '" />';

			document.getElementById("pos_" + cntMiddle + "_innerbottom").innerHTML = '<img src="' + strImageHome + 'filmstrip_green.jpg" height="10" width="' + CONST_image_width + '" />';



			lightup_chuck(document.getElementById("img_" + cntMiddle), 100);

		}

		else{

			document.getElementById("pos_" + cntMiddle + "_innertop").innerHTML    = '<img src="' + strImageHome + 'filmstrip_grey.jpg" height="10" width="' + CONST_image_width + '" />';

			document.getElementById("pos_" + cntMiddle + "_innerbottom").innerHTML = '<img src="' + strImageHome + 'filmstrip_grey.jpg" height="10" width="' + CONST_image_width + '" />';



			lightup_chuck(document.getElementById("img_" + cntMiddle), 50);

		}



	}

	//---------------------------------------------------------------





	document.getElementById("dhtmltooltip").innerHTML = strStartEndText;

}

