// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}

// AP - flashEmbed
var MYOUT = '';
function flashEmbed(fname,w,h,myId,hasRollOver,sw,popUp,skip){
var pop = (popUp == undefined || popUp == null) ? false : popUp;
var skipIt = (skip == undefined || skip == null) ? false : skip;

var swf = fname;
var png = fname.substring(0,fname.lastIndexOf('.swf')) + '.png';
//var popStart = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n<html>\n<head>\n<title>Chart</title>\n<link rel="stylesheet" type="text/css" href="/investors/annualreport2005/css/charts.css" />\n<script src="/investors/annualreport2005/js/common.js" type="text/javascript"></script>\n</head>\n<body id="popChart">\n<div id="popHead"><img src="/investors/annualreport2005/images/logoTelus.gif" alt="TELUS" border="0" id="logo" /><a href="#" onclick="window.close();" id="closewin"><img src="/investors/annualreport2005/images/close_window.gif" alt="close window" border="0" /></a><br style="clear:both;" /></div><div align="center">';
// I changed this due to hanging issues in IE...now we call doc.write from the pop-up instead of writing the contents dynamically.
var popStart = '';

// display normal size
if(hasRollOver!=true || (hasRollOver==true && pop==false)){
var myWidth = w;
var myHeight = h;
var scaleFactor = 1;
} else {
//Calculate zoomed sizes
if (pop==true){
var myWidth = sw;
var scaleFactor = myWidth/w;
var myHeight = Math.round(h * scaleFactor);
}
}

// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
var vars = [swf,hasRollOver,scaleFactor,sw,pop,skipIt];
var varString = '?vars=' + vars.join('--');
if(skipIt){
varString = '?skipit=true';
}
// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) {  // if we've detected an acceptable version
	var out = [];
	out[out.length] = '<div class="chart" id="';
	out[out.length] = myId;
	out[out.length] = '">';
	out[out.length] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="';
	out[out.length] = myWidth;
	out[out.length] = '" height="';
	out[out.length] = myHeight;
	out[out.length] = '" id="';
	out[out.length] = myId + 'swf';
	out[out.length] = '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="';
	out[out.length] = swf;
	//out[out.length] = '?fname=' + swf + '&scaleFactor=' + scaleFactor + '&nozoom=' + !scale;
    out[out.length] = varString;
	out[out.length] = '" /><param name="quality" value="best" /><param name="wmode" value="transparent" /><embed src="';
	out[out.length] = swf;
	//out[out.length] = '?fname=' + swf + '&amp;scaleFactor=' + scaleFactor + '&amp;nozoom=' + !scale;
    out[out.length] = varString;
	out[out.length] = '" quality="best" width="';
	out[out.length] = myWidth;
	out[out.length] = '" height="';
	out[out.length] = myHeight;
	out[out.length] = '" name="';
	out[out.length] = myId + 'swf';
	out[out.length] = '" play="true" loop="false" align="middle" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	out[out.length] = '</div>';
	
	var oeTags = out.join('');
    if(pop != true){
        document.write(oeTags);   // embed the Flash Content SWF when all tests are passed
    } else {
        //instead of writing it in-page we want to launch a new window
        //oeTags = popStart + oeTags + '</div></body></html>';
        //swfPop(sw,myHeight,oeTags);
        swfPop(sw,myHeight,oeTags);
    }
    
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = '<div class="noflash"><img src="' + png + '" alt="" border="0" /></div>';
    if(pop != true){
        document.write(alternateContent);  // insert non-flash content
    } else {
        //instead of writing it in-page we want to launch a new window
        //alternateContent = popStart + alternateContent + '</body></html>';
        swfPop(sw,myHeight,alternateContent);  
    }
  }
}

function swfPop(w,h,strOut){
    topL = 10;
    leftL = 10;
    width = w + 40;
    height = (h > 500) ? 500 : (h+100);  
    tlbar = 0;      
    scrlbar = 1;      
    wName = 'popUpSwf';
    var tplate = document.location + "";
    tplate = (tplate.lastIndexOf('\/en\/') >= 0) ? '/investors/annualreport2005/en/chart.html' : '/investors/annualreport2005/fr/chart.html';
    
    var str = "toolbar=" + tlbar + ",location=0,directories=0,status=0,menubar=1,scrollbars="+ scrlbar +",width="+ width +",height="+ height +",screenX="+ leftL +",screenY="+ topL +",left="+ leftL +",top="+ topL +",resizable=1";
    var Pwin = window.open(tplate,wName,str,true);

    //Pwin.document.open();
    //Pwin.document.writeln(strOut);
    //alert(Pwin.document.getElementById('chartZoomed'));
    MYOUT = strOut;
    Pwin.focus();
    //Pwin.document.getElementById('chartZoomed').innerHTML = strOut;
    //Pwin.document.close();
    return true;
}

function flashNavEmbed(lang){
var curr = 0;

var tmp = document.body.id;
if(tmp.toLowerCase().indexOf('message')>=0){
curr = 1;
}
if(tmp.toLowerCase().indexOf('overview')>=0){
curr = 2;
}
if(tmp.toLowerCase().indexOf('financials')>=0){
curr = 3;
}

//hide existing nav 
var myId = 'flashNav';
document.getElementById('mainNav').style.visibility = 'hidden';
var swf = (lang != 'fr') ? "/investors/annualreport2005/en/images/flash/nav_new.swf" : "/investors/annualreport2005/fr/images/flash/nav_new_fr.swf"; 
// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// Check to see if the version meets the requirements for playback
if (hasReqestedVersion) {  // if we've detected an acceptable version
	var out = [];
	out[out.length] = '<div id="';
	out[out.length] = myId;
	out[out.length] = '">';
	out[out.length] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width=607" height=240"';
	out[out.length] = ' id="';
	out[out.length] = myId + 'swf';
	out[out.length] = '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="';
	out[out.length] = swf;
    out[out.length] = '?isOn=' + curr;
	out[out.length] = '" /><param name="quality" value="best" /><param name="wmode" value="transparent" /><embed src="';
	out[out.length] = swf;
    out[out.length] = '?isOn=' + curr;
	out[out.length] = '" quality="best" width=607" height="240" name="';
	out[out.length] = myId + 'swf';
	out[out.length] = '" play="true" loop="false" align="middle" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	out[out.length] = '</div>';
	
	var oeTags = out.join('');
    document.write(oeTags);   // embed the Flash Content SWF when all tests are passed
    
    
  } else {  // flash is too old or we can't detect the plugin
    //unhide the "normal" nav
    document.getElementById('mainNav').style.visibility = 'visible';
  }
}