/*
    Use exotic fonts on your html page and interface it with our translation layer
    This is the first Flash translated text replacement of it's kind for EF and will be improved with time.
    Some languages do not support some character sets offered by soem embedded fonts.
    Alternaive fonts (or the default sans_serif) should be used.
    
    Version 1
    Matt Evans
    April 2006
    
    N.b. This version has the Y-adjustment disabled.
    It is also set up to handle a small delay to allow multiple calls
*/
	
	
	
	
	noRepeat = "";
	flashfonts = new Array();
	addEvent(window, 'load', insertFlashFonts);
	
	//addEvent() by John Resig, adds an event listener compatible with the different browsers, used here to check for onload
    function addEvent( obj, type, fn ){ 
       if (obj.addEventListener){ 
          obj.addEventListener( type, fn, false );
       }
       else if (obj.attachEvent){ 
          obj["e"+type+fn] = fn; 
          obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
          obj.attachEvent( "on"+type, obj[type+fn] ); 
       }
    } 
    
	function fancyFont(_id,font,details)
	{
	    //Unfortunately this is currently underpeforming as the font doenst' have the correct glyphs and
	    //the javascript is slowing down the page
	    var altText = (details.split("~"))[2];
	    document.write('<div class="temp_flashtext">'+altText+'</div>');
	    
	    
	    //var altText = (details.split("~"))[2];
	    //var subHeight = ((details.split("~"))[1])*1.71;
	    //document.write('<div id="'+_id+'alttext" style="height:'+subHeight+'px;">'+altText+'</div><div id="'+_id+'" style="width:1px;height:'+subHeight+'px;position:absolute;left:-9999;"></div>');//use the style sheet to constrain the title
	    //arguments[arguments.length] = subHeight+"";
	    //flashfonts.push(arguments);
	}	
	
	function insertFlashFonts() {
	    for (var s=0; s<flashfonts.length; s++)
	    {
	        writefancyFont(flashfonts[s][0],flashfonts[s][1],flashfonts[s][2],flashfonts[s][3]);
	    }
	}
    
	function writefancyFont(_id,font,details,subheight)
	{
	    var altText = (details.split("~"))[2];
		var swfWidth = (details.split("~"))[3];
		var flash_id = "fancyfont_"+_id;
        var flashText = new FlashObject("/_css/mylt/flashfonts/"+font+".swf", flash_id, '1', subheight+'', 6, "#fff");
        flashText.addVariable("divId",_id);
		flashText.addVariable("myId",flash_id);
		flashText.addVariable("ctr",ctr);
		flashText.addVariable("details",details);
		flashText.addParam("wmode", "transparent");
		flashText.addParam("allowScriptAccess", "sameDomain");
		flashText.altTxt = altText;
		flashText.bypassTxt = '';
		flashText.write(_id);
    }
	
	function resizeFlash(_id,_fid,w,h) 
	{
		obj = document.getElementById(_id);
		if (obj && noRepeat.indexOf(_id)==-1) {
		    document.getElementById(_id+'alttext').style.display = "none";
		    obj.style.width = w+"px";
		    //obj.style.height = h+"px";
		    obj.style.position = "relative";
		    obj.style.left = "0";
		    noRepeat += _id+",";
		}
		obj = thisMovie(_fid);
		if (obj && noRepeat.indexOf(_fid)==-1) {
		    obj.width = w;
		    //obj.height = h;
		    noRepeat += _fid+",";
		}
		obj = document.getElementById(_fid);
		if (obj && noRepeat.indexOf(_fid)==-1) {
		    obj.style.width = w+"px";
		    //obj.style.height = h+"px";
		    noRepeat += _fid+",";
		}
		if (obj) {
		    obj.SetVariable("runInterval", false);  //tell flash to stop sending resize commands
		}
	}
	
	
	// Flash Movie Controllers
	//
	
	function thisMovie(movieName) 
	{
      // IE and Netscape refer to the swf movie object differently.
      // This function returns the appropriate syntax depending on the browser.
      if (navigator.appName.indexOf ("Microsoft") !=-1) {
        return window[movieName]
      }	else {
        return document[movieName]
      }
    }
    
    // Checks if movie is completely loaded.
    // Returns true if yes, false if no.
    function movieIsLoaded (theMovie) {
      if (typeof(theMovie) != "undefined") {
        return theMovie.PercentLoaded() == 100;
      } else {
        return false;
      }
    }

    function playmovie(movieName) {
      if (movieIsLoaded(thisMovie(movieName))) {
        thisMovie(movieName).Play();
      }
    }

    function stopmovie(movieName) {
      if (movieIsLoaded(thisMovie(movieName))) {
        thisMovie(movieName).StopPlay();
      }
    }


    function go(theFrame) {
      if (movieIsLoaded(thisMovie(movieName))) {
        thisMovie(movieName).GotoFrame(theFrame);
      }
    }
