// Ovation Video Javascript
// Revised for HomeLoan.com 02/10/06
// www.OvationSolutions.com

//Get query string
start = getQueryVariable('start');
//choice = getQueryVariable('choice');
//wmv_video = "ovation_files/btfc.wmv";

//Initialize variables
move_layer_flag = "n";

//Check for Flash
flash_version = 0;
flash_version = get_flash_info();
//flash_version = 0; //for testing

//Check if browser supports transparent Flash
browser_trans = "n";
browser_trans = check_browser_trans();
//browser_trans = "n"; //for testing

//FUNCTIONS
//Get Flash Information
function get_flash_info() {
	var latest_version = 8;
	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 presentation player
function write_presentation() {
	if(flash_version >= 6) {
		move_layer_flag = "y";
		if(browser_trans == "y") {
			if(start == "y") {
				document.write('<div id=\"presentation\" style=\"position:absolute;top:0;left:0;width:650px;margin-top:0;z-index:100}\">');
				document.write('<table width=\"650\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>');
				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=\"650\" height=\"450\"><param name=\"movie\" value=\"hl_start.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\" /><PARAM NAME=bgcolor VALUE=#FFFFFF><embed src=hl_start.swf/index.html" quality=\"high\" wmode=\"transparent\" bgcolor=#FFFFFF pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"650\" height=\"450\"></embed></object>');
				document.write('</td></tr></table></div>');
			}
			else {
				document.write('<div id=\"presentation\" style=\"position:absolute;top:0;left:0;width:264px;margin-top:0;z-index:100}\">');
				document.write('<table width=\"264\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>');
				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=\"264\" height=\"192\"><param name=\"movie\" value=\"hl_launch.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\" /><PARAM NAME=bgcolor VALUE=#FFFFFF><embed src=hl_launch.swf/index.html" quality=\"high\" wmode=\"transparent\" bgcolor=#FFFFFF pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"264\" height=\"192\"></embed></object>');
				document.write('</td></tr></table></div>');
			}
		}
		else {
			document.write('<div id=\"presentation\" style=\"position:absolute;top:0;left:0;width:264px;margin-top:0;}\">');
			document.write('<table width=\"264\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>');
			document.write('<a href=#\"><img border=\"0\" src=images/launch.jpg/index.html" width=\"264\" height=\"192\" onClick=\"ov_open_window(\'intro.htm/index.html',650,450);\"></a>');
			document.write('</td></tr></table></div>');
		}
	}
}
//parent of move_layer
function move_layer() {
	if (move_layer_flag == "y") {
		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 = 0;
	if(browser_trans == "n") {
		player_offset = 0;
	}
	if(document.layers){
		document.presentation.left=getImageX("presentation_location")-player_offset;
		document.presentation.top=getImageY("presentation_location");
	}
	if(document.all){
		document.all.presentation.style.left=getImageX("presentation_location")-player_offset;
		document.all.presentation.style.top=getImageY("presentation_location");
	}
	if(document.getElementById){
		document.getElementById("presentation").style.left=getImageX("presentation_location")-player_offset;
		document.getElementById("presentation").style.top=getImageY("presentation_location");
	}
}

//writes the video launch 
function write_launch() {
	document.write('<img id=\"presentation_location\" name=\"presentation_location\" border=\"0\" src=images/image005.jpg/index.html" width=\"264\" height=\"192\">');
}

//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);
}

//writes generic flash embed code with transparency option
function ov_write_flash_trans(file,w,h) {
	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=\"' + file + '\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=' + file + '/index.html" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"' + w + '\" height=\"' + h + '\"></embed></object>');
}

//write custom message code
function ov_write_custom_flash(message) {
          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=\"400\" height=\"150\">');
            document.write('<param name=\"movie\" value=\"dynamic.swf?id=' + message + '\">');
            document.write('<param name=\"quality\" value=\"high\">');
			document.write('<param name=\"wmode\" value=\"transparent\">');
            document.write('<embed src=dynamic.swf-id=' + message + '-" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"  wmode=\"transparent\" width=\"400\" height=\"150\"></embed>');
          document.write('</object>');
}
