/*
  Replace elements with a flash text file
  
  pressFunction:String - name of JS function
  hoverFunction:String - name of JS function
  hoverOutFunction:String - name of JS function
  
  text params: font, size, color, xOffset, yOffset, letterSpacing, leading, align, hoverColor, textTransform
  
*/


jQuery.fn.flashComplexImageReplacement = function(path, vars, extras) {
  
  this.each(function(i, e){
    //
    var item = $(e);
    item.addClass("textReplaced");
    
    var flashvars = {};
    //pass txt to flash
    var txt = parseNode(item.get(0), true);
    flashvars.txt = encodeURI(txt);
    
    //assign any extra parameters
    for(var v in extras){
      flashvars[v] = extras[v];
    }
    
    //break up all the variables for all the selectors into textReplace flashvars
    for(var v in vars){
      for(var k in vars[v]){
        flashvars["textReplace_"+v+"_"+k] = vars[v][k];
      }
    }
    
    //create a holder for the flash file
    var rand = String(Math.random() + Math.random() + Math.random());
    rand = rand.replace(".", "");
    var id = "flash_text_replace_" + i + rand;
    item.html('<div id="'+id+'" class="textReplacedWrap">' + txt + '</div>');
    //setup any params
    params = {};
    params.wmode = "transparent";
    
    //pass variables to the flash so it knows what its called and what number it is
    flashvars.embeddedID = id;
    flashvars.embeddedKey = i;
    
    flashvars.width = item.width();
    flashvars.height = item.height();
    
    //check for a url and pass it to the flash
    if(item.attr("href")){
      flashvars.embeddedURL = item.attr("href");
    }
    
    //assign id and name (good practise for ExternalInterface)
    var attributes = {id:id, name:id};
    
    //embed the swf
    swfobject.embedSWF(path, id, item.width(), item.height(), "8.0.0", null, flashvars, params, attributes);
    
  });
  
  return this;
  
};
