 var overlayOpen = false;

  function closeOverlay() {
    if (overlayOpen) {
      new Effect.toggle('overlay_window', 'appear', {duration:0.3});
      new Effect.toggle('message', 'appear', {delay:0.4, duration:0.1});
    }
    overlayOpen = false;
    var obj = document.getElementById('ply2');
    if (obj) {
      try { obj.sendEvent('STOP'); }
      catch (e) { }
    }
    //$('input[type=radio]').attr('checked', false);
    //closeOverlay radio
  }

  function showOverlay() {
    if (!overlayOpen) {
      new Effect.toggle('message', 'appear', {duration:0.1});
      new Effect.toggle('overlay_window', 'appear', {delay:0.2, duration:0.3});
      var obj = document.getElementById('ply');
      if (obj) {
        try { obj.sendEvent('STOP'); }
        catch (e) { }
      }
    }
    overlayOpen = true;
  }

  function overlayTitle(str) {
    $('overlay_title').innerHTML = str;
  }

  function overlayLoading() {
    $('overlay_content').innerHTML = '<div id="overlay_loading">&nbsp;</div>';
  }

  function wizardStep1(id) {
    overlayLoading();
    overlayTitle('Add us now');
    showOverlay();
    // load content
    new Ajax.Updater( { success:'overlay_content'},
                        '/widget/whitelist-wizard/step-2/?email_provider_id=' + id,
                      { asynchronous: true,
                        evalScripts: false
                      }
                    );
    return false;
  }

  function howTo(obj, id, type) {
    if ((id == null || id == undefined) && obj != null) {
      id = obj.value;
    }
    if (id) {
      if (type != 'text' && type != 'video') {
        type = 'video';
      }
      if (obj != null)
        document.getElementById('email_provider_id_text').text = obj.text;
      overlayLoading();
      overlayTitle('How to add us');
      showOverlay();

      new Ajax.Updater( { success:'overlay_content'},
                        '/widget/how-to/' + type + '/?email_provider_id=' + id,
                      { asynchronous: true,
                        evalScripts: true
                      }
                    );
    }
    return false;
  }
  
    function clipboard() {
        //Create a new clipboard client
        var clip = new ZeroClipboard.Client();

        clip.glue(document.getElementById('copy_to_clipboard'));

        clip.setText(document.getElementById('address_to_copy').innerHTML);

        //Add a complete event to let the user know the text was copied
        clip.addEventListener('complete', function(client, text) {
            alert("Copied text to clipboard:\n" + text);
        });
    }

  function showFreeGift() {
    if (navigator.appName == "Microsoft Internet Explorer") {
      if (document.getElementById('free_gift_container').style.display == 'block')
          document.getElementById('free_gift_container').style.display = 'none';
      else
          document.getElementById('free_gift_container').style.display = 'block';
    }
    else { 
      new Effect.toggle('free_gift_container', 'appear', {duration:0.1});
    }
  }

  function hideFreeGift() {
    if (document.getElementById('free_gift_container')){
    if (navigator.appName == "Microsoft Internet Explorer") {
      document.getElementById('free_gift_container').style.display = 'none';
    }
    else {
      new Effect.Fade('free_gift_container', {duration:0.1});
    }
    }
  }

  function hideFreeGift1() {
    if (document.getElementById('free_gift_container1')){
    if (navigator.appName == "Microsoft Internet Explorer") {
      document.getElementById('free_gift_container1').style.display = 'none';
    }
    else {
      new Effect.Fade('free_gift_container1', {duration:0.1});
    }
    }
  }

