window.addEvent("domready", function(){
    var oSmoothScroll = new SmoothScroll();
});

function nospam(name, domain) {
    document.location = "mailto:" + name + "@" + domain;
}


/*
 * Boku extended code: display notification of site rebrand 
 *
 * Mostly a horrendous collection of hacks and workarounds...
 */

// Cross-browser element opacity
function setOpacity(element, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  element.opacity = element.style.opacity = element.style.MozOpacity = element.style.KHTMLOpacity = element.style.KhtmlOpacity = opacity / 100;
  element.style.filter = 'alpha(opacity=' + opacity + ')';
}

// Show or hide all swfobject embedded objects on the page
// Needed due to plugin content stacking browser bugs
function showFlash(show)
{
  // Special var created in modified swfobject.js
  if(!swfobject_id_reg || !swfobject_id_reg.length) {
    return;
  }
  var el;
  for(var i = 0; i < swfobject_id_reg.length; i++) {
    el = document.getElementById(swfobject_id_reg[i]);
    if(el) {
      el.style.visibility = show ?'visible' :'hidden';
      if(show) {
        el.Rewind();
        el.Play();
      }
    }
  }
}

// Wait for some Flash objects to be embedded
// We need this because onload is sometimes fired before the mootools domready,
// which CC hook for their swfobject code
var waitForFlash_start = null;
var waitForFlash_action = null;
function waitForFlash(action, params) {
  if(!waitForFlash_start) {
    waitForFlash_start = (new Date()).getTime();
    waitForFlash_action = action;
  }
  var elapsed = (new Date()).getTime() - waitForFlash_start;

  if(elapsed > 2000 || (swfobject_id_reg && swfobject_id_reg.length)) {
    waitForFlash_action.apply(this, params);
    waitForFlash_start = null;
    waitForFlash_action = null;
    return;
  }

  setTimeout(waitForFlash, 10);
}

function rebrandNotifyStage1()
{
  var tmp = document.location.href.split('?');
  if(tmp.length < 2) {
    return;
  }
  tmp.shift();
  var qstr = tmp.join('?');

  if(qstr.match(/from_mobillcash=1/)) {
      waitForFlash(rebrandNotifyStage2, ["Looking for Mobillcash? You're in the right spot.", "Mobillcash has been acquired by BOKU. We're still the easiest, safest mobile payments service out there. "]);  
      return;
  }
  if(qstr.match(/paymo=contact/) || qstr.match(/paymo=publishersupport/)) {
      rebrandShowBox("Trying to contact Paymo? You're in the right place.", "BOKU and Paymo have joined forces to provide the safest and best mobile payments solution. ");  
      return;
  }
  if(qstr.match(/paymo=publishersignup/)) {
      rebrandShowBox("Want to become a Paymo merchant? You're in the right place.", "BOKU and Paymo have joined forces to provide the safest and best mobile payments solution. ");
      return;
  }
  // We don't want to have to support < IE7, so they don't get the popup at all.
  // Conditional compilation :(
  /*@cc_on
    /*@if (@_jscript_version < 5.7)
      return;
    @*/
    /*@end
  @*/

}

function rebrandNotifyStage2(heading, content) {
  showFlash(false);
  rebrandShowBox(heading, content);
}

function rebrandShowBox(heading, content) {
  var bg = document.createElement('div');
  bg.id = 'rebrand_bg';
  setOpacity(bg, 40);

  var box = document.createElement('div');
  box.id = 'rebrand_box';

  var header = document.createElement('div');
  header.id = 'rebrand_header';
  var header_logo = document.createElement('div');
  header_logo.id = 'rebrand_header_logo';
  header.appendChild(header_logo);
  box.appendChild(header);

  var close = document.createElement('div');
  close.id = 'rebrand_close';
  var close_link = document.createElement('a');
  close_link.href = '#';
  close_link.appendChild( document.createTextNode('Thanks, got it') );
  close.appendChild(close_link);
  box.appendChild(close);

  var head = document.createElement('h1');
  var head_text = document.createTextNode(heading);
  head.appendChild(head_text);
  box.appendChild(head);

  var p = document.createElement('p');
  p.appendChild( document.createTextNode(content) );
  var link = document.createElement('a');
  link.href = 'http://www.boku.com/press';
  link.appendChild( document.createTextNode('Learn more') );
  p.appendChild(link);
  box.appendChild(p);


  var cbk_close = function (e) {
    var pn = bg.parentNode;
    pn.removeChild(bg);
    pn.removeChild(box);
    showFlash(true);
    return true;
  };

  close_link.onclick = cbk_close;
  close.onclick = cbk_close;
  //bg.onclick = cbk_close;

  var body = document.getElementsByTagName('body');
  if(!body.length) return; //wut
  body[0].appendChild(bg);
  body[0].appendChild(box);
}

Core.addEventListener('load', rebrandNotifyStage1);

