function FlashLink() {
}

FlashLink.start = function(flashURL, flashID, width, height, version, expressInstallURL) {
  this.flashID = flashID;

  var enableFlashLink = true;
  //there is no # in de url, redirect to same page with # 
  if(window.location.hash.length == 0) { 
    var flashLinkURL = "/#"+window.location.pathname;
    if(window.location.pathname == "" || window.location.pathname == "/") {
      //we stay in index, no new request is generated, enableFlashLink
      enableFlashLink = true;
    } else {
      enableFlashLink = false;
    }
    window.location = flashLinkURL;
  }
  
  if(enableFlashLink) {
    swfobject.embedSWF(flashURL, flashID, width, width, version, expressInstallURL, null, { allowFullScreen:true, menu:false });
  }
  document.body.style.overflow = 'hidden';
}

FlashLink.flashInitialize = function() {
  $.History.bind(function(state){
    var flash = $("#"+FlashLink.flashID);
    if(flash.size() > 0) {
      flash.get(0).setFlashLinkState(state);
    }
  });
  return window.location.hash.substr(1);
}

FlashLink.flashRequest = function(request) {
  if(googleAnalyticsTracker == null) {
    try {
      googleAnalyticsTracker = _gat._getTracker( _gaq[0] );
    } catch(e) {
      
    }
  }
  try {
    googleAnalyticsTracker._trackPageview(request);
  } catch(e) {
    
  }
  $.History.go(request);
}

FlashLink.back = function() {
  window.history.back();
}

FlashLink.flashTitle = function(title) {
  document.title = title;
}

function initFlTemplate(flashURL, flashID, width, height, version, $expressInstallURL) {
  FlashLink.start(flashURL, flashID, width, height, version, $expressInstallURL);
}

