(function($) {
  /**
  * videoPlayer 1.0.0. 
  * 
  * Launch  : April 2010
  * Version : 1.0.0
  * Released: 02/03/2010 - Roberto Sciarretta
  */
  function videoPlayer(elem, conf) {
    var self = this;
    jQuery.extend(self, {
      getVersion: function() {
        return [1, 0, 0];
      },
      getParent: function() {
        return elem;
      },
      init: function() {
      },
      start: function() { },
      stop: function() { },
      pause: function() { },
      resize: function(minimize) {
        var $cont = $j(elem.parents('.resizable')[0]);
        if (minimize){
					$cont.removeClass('pgbig');
					$cont.css('width', conf.width + 'px');
					$j('object', $cont).attr('height', conf.heightFlash).attr('width', conf.widthFlash);
					if(typeof conf.resize === 'function') conf.resize('small');
        } else if ($cont.hasClass('pgbig') == true) {
          $cont.toggleClass('pgbig');
          $cont.css('width', conf.width + 'px');
          $j('object', $cont).attr('height', conf.heightFlash).attr('width', conf.widthFlash);
          if (typeof conf.resize === 'function') conf.resize('small');
        } else {
          $cont.toggleClass('pgbig');
          $cont.css('width', conf.width_big + 'px');
          $j('object', $cont).attr('height', conf.heightFlash_big).attr('width', conf.widthFlash_big);
          if (typeof conf.resize === 'function') conf.resize('large');
        };
      }
    });
    this.init();
  }
  jQuery.fn.videoPlayer = function(conf) {
    // Check if a uefaLive is already present
    var api = jQuery(this).eq(typeof conf == 'number' ? conf : 0).data("d3videoPlayer");
    if (api) return api;
    // Default configuration
    var defaultConf = {
      width: 658,
      width_big: 990,
      widthFlash: 512,
      heightFlash: 316,
      widthFlash_big: 770,
      heightFlash_big: 460
    };
    jQuery.extend(defaultConf, conf);
    jQuery.extend(jQuery(this), defaultConf);
    this.each(function() {
      var el = new videoPlayer(jQuery(this), defaultConf);
      jQuery(this).data("d3videoPlayer", el);
    });
    return jQuery(this).data("d3videoPlayer");
  };
})();
function getSwf(name) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[name];
  } else {
    return document[name];
  }
}
function flashVideoPlayer(_id, _action) {
  //if (!_id){_id = $j('#flashContainer object').attr('id')}; //truschino claudia da levare
  if (_action != 'init') var _vp = $j('#' + _id).data("d3videoPlayer");
  //alert("ELEMENT ID: " + _id + "\nACTION: " + _action);
  //alert($j('#' + _id).html());
  switch (_action) {
    case 'init':
      if ($j('#' + _id).parents('.videoPlayer').attr('id') == 'VideoArticle') {
        $j('#' + _id).videoPlayer({
          width: 490,
          height: 303,
          widthFlash: 490,
          heightFlash: 303,
          resize: function(type) {
            if (type == 'small') {
              $j('.videoArticle .rtCol').removeClass('hide');
              $j('#flashContainer').addClass('init');
            } else {
              $j('.videoArticle .rtCol').addClass('hide');
              $j('#flashContainer').removeClass('init');
            }
          }
        });
      } else {
        $j('#' + _id).videoPlayer()
      }
      // Serve per visualizzare il bottone full window
      if ((($j('#' + _id).parents('.artPage')).length > 0) && (($j('#' + _id).parents('.matchLeft')).length == 0)) {
        $j('#' + _id)[0].showFullWindow();
      }
      break;
    case 'start':
      break;
    case 'resize':
      _vp.resize();
      break;
    case 'videoComplete':
      eval(callBackFunctVpOnComplete + '(\'' + _id + '\')');
      break;
  };
}
function SetCallbackVideoPlayerComplete(funName) {
  if (funName != '') { callBackFunctVpOnComplete = funName; }
}
function DefaultVideoComplete(_divid) {
  // check if user do fullsize
  if ($j($j('#' + _divid).parents('.resizable')[0]).hasClass('pgbig') == true) {
    $j($j('#' + _divid).parents('.resizable')[0]).toggleClass('pgbig');
    $j($j('#' + _divid).parents('.resizable')[0]).css('width', '658px'); // width like conf.width
    $j('object', $j($j('#' + _divid).parents('.resizable')[0])).attr('height', 316).attr('width', 512); // height like conf.heightFlash width like widthFlash
  }
  $j('#flashThumb').show();
  $j('#flashContainer').hide();
}
function TgVideoComplete() {
  $j('#xmlnews').hide();
  $j('#xmlnews').css('left', '0px');
  $j('.videolistgrid').show();
  $j('#flashThumb').show();
  $j('#flashContainer').hide();
  $j('#flashNews').show();
  $j('.articleFlashPlayer .kind').show();
}


