  (function($) {
/*
unifiedPlayer.js v1.2
Last updated: 12 July 2010
Created by Gareth Clubb (Perform Group)
http://helpdesk.premiumtv.co.uk/mediawiki/index.php/Unified_Player
*/
$.fn.unifiedPlayer = function(options) {
  var config = {
    //configXML: "/nameValue/nameValueXML/0,,13118~3676,00.xml",
    configXML: "/xml/PlayerConfig.xml",
    selectedBandwidth:"high",
    setPlayerType:"vod",
    disableControls:"false",
    useInitialSplashScreen: "false",
    width: "640",
    height: "360",
    requiredVersion: "10.0.0",
    locale: "en_GB",
    hideTimer: "false",
    partnerId:"0",
    allowFullScreen: "true"
    //eventId: GLOBAL_DETAIL_ID,
    //clipId: GLOBAL_DETAIL_ID,
  };

  if(options) $.extend(config, options);
  return this.each(function() {
    var container, swfobj;
    if(!this.id){
     // this.id = 'unified' + new Date().getTime();
     this.id = 'flashElement';
    }
    container = this.id;
   
    $(container).hide();
    function flashMessage(message) {
      $(container).show();
      $(container).html(message);
    }
    if(swfobject.hasFlashPlayerVersion(config.requiredVersion)) {
      var params = {
        wmode: "transparent",
        allowScriptAccess: "always",
        //base: "http://www.premiershiprugby.tv",
        base: "",
        bgcolor: "#ffffff",
        allowFullScreen: config.allowFullScreen
      };
      var settings = {
        configXML: config.configXML,
        selectedBandwidth: config.selectedBandwidth,
        setPlayerType: config.setPlayerType,
        disableControls: config.disableControls,
        useInitialSplashScreen: config.useInitialSplashScreen,
        resourceLocalePath:"/ptvFlash/unifiedplayer/assets/resources/"
      }
      var live = {
        eventId: config.eventId,
        hideTimer: config.hideTimer,
        partnerId: config.partnerId,
        cdn: "akamai"
      }
      var vod = {
        locale: config.locale,
        omnitureAccount: typeof(s_account) != "undefined" ? s_account : false,
        clipId: config.clipId
      }
      switch(config.setPlayerType) {
        case 'live': $.extend(settings, live);
          break;
        case 'vod': $.extend(settings, vod);
          break;
        default: $.extend(settings, vod);
      }
      swfobj = swfobject.embedSWF("/ptvFlash/fei/live/unified/UnifiedPlayer.swf", container, config.width, config.height, config.requiredVersion, false, settings, params, {})
      $(container).show();
      swfobject.registerObject(container, config.requiredVersion, "/ptvFlash/SWFObject/SWFObject2_2/expressInstall.swf");
      $('object#' + container).css('visibility','visible');
      return swfobj;
    } else {
      flashMessage('<p>You do not have the latest version of Flash player installed.</p><p>Please download the <a href="http://get.adobe.com/flashplayer/" target="_blank">latest version</a></p>');
    }
  });
};
})(jQuery);


