// Ovation Video Javascript
// Revised for Bob Turner Ford Country 11/06/05
// Revised for Welcome Charlie Video 1/31/06
// This version works when it's one video with no layers or transparency
// www.OvationSolutions.com

//Get query string
/* 
Changed this code when no longer new and used
choice = getQueryVariable('choice');
if (choice == "new") {
	wmv_video = "ovation_files/btfc_new.wmv";
}
else if (choice == "used") {
	wmv_video = "ovation_files/btfc_used.wmv";
} 
*/
choice = getQueryVariable('choice');
//wmv_video = "sf30.wmv";

//Check for Flash
flash_version = 0;
flash_version = get_flash_info();
//flash_version = 0; //for testing

//Check if browser supports transparent Flash
browser_trans = "y";
//browser_trans = check_browser_trans();
//browser_trans = "n"; //for testing

//FUNCTIONS
//Get Flash Information
function get_flash_info() {
	var latest_version = 10;
	var agent = navigator.userAgent.toLowerCase(); 
	if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flash_version = 0;
	}
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flash_plugin = navigator.plugins['Shockwave Flash'];
		if (typeof flash_plugin == 'object') { 
			for (var i = latest_version; i >= 3; i--) {
    	    	if (flash_plugin.description.indexOf(i + '.') != -1) {
					flash_version = i;
					break;
            	}
			}
		}
	}
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		var doc = '<scr' + 'ipt language="VBScript"\> \n';
      	doc += 'On Error Resume Next \n';
      	doc += 'Dim obFlash \n';
      	doc += 'For i = ' + latest_version + ' To 3 Step -1 \n';
      	doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
      	doc += '   If IsObject(obFlash) Then \n';
      	doc += '      flash_version = i \n';
      	doc += '      Exit For \n';
      	doc += '   End If \n';
      	doc += 'Next \n';
      	doc += '</scr' + 'ipt\> \n';
      	document.write(doc);
	}
	else if (agent.indexOf("webtv/2.5") != -1) flash_version = 3;
	else if (agent.indexOf("webtv") != -1) flash_version = 2;
	else {
		flash_version = 0;
	}
	return flash_version;
}

/* Check if Browser can support transparent Flash
According to Macromedia, these can:
	Internet Explorer 3 or higher (Windows)
	Internet Explorer 5.1* and 5.2* (Macintosh)
	Netscape 7.0*
	Mozilla 1.0 or higher*
	AOL* 
	CompuServe* 

	* Macromedia Flash Player version 6,0,65,0 (Windows) or 6,0,67,0 (Macintosh) or higher required for this feature.
*/
function check_browser_trans() {
	var browser = new BrowserDetect();
	var supports_trans = "n";
	safari = "n";
	//Internet Explorer 3 or higher (Windows)
	if ( browser.isWin && browser.isIE4up ) supports_trans = "y";
	if (flash_version >= 6) {
		//Internet Explorer 5.1* and 5.2* (Macintosh)
		if ( browser.isMac && browser.isIE5up ) supports_trans = "y";
		//Netscape 7.0*
		if ( browser.isNS7up ) supports_trans = "y";
		//Mozilla 1.0 or higher*
		if ( browser.isMozilla ) supports_trans = "y";
		//AOL*
		if ( browser.isAol ) supports_trans = "y";
	}
	if ( browser.isSafari ) safari = "y";
	return supports_trans;
}

function BrowserDetect() {
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
	var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}

//decoded query string
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
    	}
	}
}

//gets the x location of a photo
function getImageX(imgID) { 
    var obj = (document.images && document.images[imgID]) ? 
        document.images[imgID] : 
        (document.getElementById && document.getElementById(imgID)) ? 
        document.getElementById(imgID) : null 
    if (obj.x) return obj.x 
    if (obj.offsetLeft || obj.offsetParent) { 
        var x = obj.offsetLeft 
        while (obj = obj.offsetParent) x += obj.offsetLeft 
        return x 
    } 
    return 0 
} 

//gets the y location of a photo
function getImageY(imgID) { 
    var obj = (document.images && document.images[imgID]) ? 
        document.images[imgID] : 
        (document.getElementById && document.getElementById(imgID)) ? 
        document.getElementById(imgID) : null 
    if (obj.y) return obj.y
    if (obj.offsetTop || obj.offsetParent) { 
        var y = obj.offsetTop 
        while (obj = obj.offsetParent) y += obj.offsetTop 
        return y 
    } 
    return 0 
}

//writes the video player
function write_video(video_name,swf_file,video_settings_file,w,h) {
	wmv_video = 'http://ovationsolutions.com/' + video_name + '/' + video_name + ".wmv";
	wmv_h = h + 100;
	if(choice == "wmv") {
		var WMP7;
		if ( navigator.appName != "Netscape" ){   
		     WMP7 = new ActiveXObject('WMPlayer.OCX');
		}
		// Windows Media Player 7 Code
		if ( WMP7 ) {
	     	document.write ('<OBJECT ID=MediaPlayer ');
	     	document.write (' CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6');
	     	document.write (' standby="Loading Microsoft Windows Media Player components..."');
	     	document.write (' TYPE="application/x-oleobject" width="' + w + '" height="' + wmv_h + '">');
	     	document.write ('<PARAM NAME="url" VALUE="' + wmv_video + '">');
	     	document.write ('<PARAM NAME="AutoStart" VALUE="true">');
	     	document.write ('<PARAM NAME="ShowControls" VALUE="1">');
	     	document.write ('<PARAM NAME="uiMode" VALUE="mini">');
	     	document.write ('</OBJECT>');
		}
		// Windows Media Player 6.4 Code
		else {
	     //IE Code
	     document.write ('<OBJECT ID=MediaPlayer ');
	     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,5,715 ');
	     document.write ('standby="Loading Microsoft Windows Media Player components..." ');
	     document.write ('TYPE="application/x-oleobject" width="' + w + '" height="' + wmv_h + '">');
	     document.write ('<PARAM NAME="FileName" VALUE="' + wmv_video + '">');
	     document.write ('<PARAM NAME="AutoStart" VALUE="true">');
	     document.write ('<PARAM NAME="ShowControls" VALUE="1">');
	     //Netscape code
	     document.write ('    <Embed type="application/x-mplayer2"');
	     document.write ('        pluginspage="http://www.microsoft.com/windows/windowsmedia/"');
	     document.write ('        filename="' + wmv_video + '"');
	     document.write ('        src="' + wmv_video + '"');
	     document.write ('        Name=MediaPlayer');
	     document.write ('        ShowControls=1');
	     document.write ('        ShowDisplay=1');
	     document.write ('        ShowStatusBar=1');
	     document.write ('        width=' + w);
	     document.write ('        height=' + wmv_h + '>');
	     document.write ('    </embed>');
	     document.write ('</OBJECT>');
		}
	}
	else {
		if(flash_version >= 8) {
			if(browser_trans == "y") {
				document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"' + w + '\" height=\"' + h + '\"><param name=\"movie\" value=\"../so_files/' + swf_file + '?video_settings=../' + video_name + '/' + video_settings_file + '\"><param name=\"quality\" value=\"high\"><PARAM NAME=bgcolor VALUE=#000000><embed src=\"../so_files/' + swf_file + '?video_settings=../' + video_name + '/' + video_settings_file + '\" quality=\"high\" bgcolor=#000000 pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + w + '\" height=\"' + h + '\"></embed></object>');
			}
		}
		else {
			if(browser_trans == "y") {
				window.location="index.php?choice=wmv";
			}
		}
	}
}
//parent of move_layer
function move_layer() {
	if(safari == "y") {
		//Safari requires a short wait for this step
		setTimeout("move_layer_sub()",1500);
	}
	else {
		move_layer_sub();
	}
}
//moves the video layer to where it belongs
function move_layer_sub() {
	var player_offset = 50;
	if(browser_trans == "n") {
		player_offset = 0;
	}
	if(document.layers){
		document.video.left=getImageX("video_location")-player_offset;
		document.video.top=getImageY("video_location");
	}
	if(document.all){
		document.all.video.style.left=getImageX("video_location")-player_offset;
		document.all.video.style.top=getImageY("video_location");
	}
	if(document.getElementById){
		document.getElementById("video").style.left=getImageX("video_location")-player_offset;
		document.getElementById("video").style.top=getImageY("video_location");
	}
}

//writes the choices dialogue box
function write_choices() {
	document.write('<IMG src=\"ovation_files/video_choices_no_trans.gif\"');
	document.write('	width=235 height=144 border=0');
	document.write('	id=\"video_location\" title=\"video_location\"');
	document.write('	usemap=\"#choices_map2\">');
	document.write('<map name=\"choices_map2\" id=\"choices_map2\">');
	document.write('	<area shape=\"rect\" coords=\"28,82,208,113\"');
	document.write('		alt=\"Please make selection to view video\" href=\"ovation_files/video_wmv.htm?choice=new\" target=\"_blank\">');
	document.write('</map>'); 
}

//open new window
function ov_open_window(file,w,h) {
	var open_string = "width=" + w + ",height=" + h + ",left=100,top=100,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no";
	window.open(file,'video',open_string);
}

//write flash banner
function ov_write_flash() {
	document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"300\" height=\"147\"><param name=\"movie\" value=\"ovation_files/banner.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=\"ovation_files/banner.swf\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"300\" height=\"147\"></embed></object>\n');
}