var MusicForLifeSplash = {};
MusicForLifeSplash.overlay = null;

/**
 * Init the splash page. Load overlay
 */
MusicForLifeSplash.init = function() {

  if (!MusicForLifeSplash.getCookie('mfl-' + mflSplashTitle)) {
    document.title = mflSplashTitle + ' leent zijn homepagina uit aan Music for Life.';
    MusicForLifeSplash.showOverlay();  
  }
  
}

/**
 * Show the overlay
 */
MusicForLifeSplash.showOverlay = function() {
  
  MusicForLifeSplash.overlay = document.getElementById('splash-overlay'); 
  MusicForLifeSplash.content = document.getElementById('splash-content');
  MusicForLifeSplash.overlay.onclick = MusicForLifeSplash.closeOverlay;  
  //MusicForLifeSplash.content.onclick = MusicForLifeSplash.gotoStubru;
  
  var url = 'http://be.sitestat.com/vrt/sandbox1/s?clickout.VAN.leenjehomepage.' + mflSplashTitle + '.NAAR.stubru-be&amp;ns_type=clickout&amp;ns_url=http://www.stubru.be/programmas/musicforlife';
  var donate_url = 'http://be.sitestat.com/vrt/sandbox1/s?clickout.VAN.leenjehomepage.' + mflSplashTitle + '.NAAR.musicforlifedonate-be&amp;ns_type=clickout&amp;ns_url=http://www.musicforlifedonate.be';
  
  var html = '<a href="#" onclick="MusicForLifeSplash.closeOverlay(); return false;" id="mflSiteUrl">';
  html += 'Ga naar ' + mflSplashTitle + ' >></a>';

  html += '<span id="mflSplashUrl" onclick="MusicForLifeSplash.closeOverlay();">' + mflSplashUrl + '</span>';
  
  html += '<div id="mflSplash-intro-tekst">';
  html += '<p>Voor de vijfde keer organiseert Studio Brussel Music For Life, een 7 dagen durende radiomarathon vanuit het glazen huis, dat dit jaar op de Groenplaats in Antwerpen staat van 18 tot en met 24 december.</p>';
  html += '<p>Music for Life wil dit jaar het lot van weeskinderen, die hun ouders hebben verloren aan aids, in de kijker zetten en geld inzamelen voor de wereldwijde projecten van het Rode Kruis, waar er dagelijks wordt gestreden om het leven van kwetsbare weeskinderen te verbeteren.</p>';
  html += '</div>';
  
  html += '<div id="mflSplash-buttons">';
  /*html += '<a id="mfl-vraag-plaat" class="mfl-button" href="' + donate_url + '">Vraag je plaat aan</a>';
  html += '<a id="mfl-live-stream" class="mfl-button" href="' + url + '/livestream">Volg live het glazen huis</a>';*/
  
  html += '<a id="mfl-alles-over" class="mfl-button" href="' + url + '">Alles over Music For Life</a>';
  html += '<a id="mfl-neem-homepage" class="mfl-button" href="' + url + '/leenjehomepageuitaanmusicforlife">Leen ook jouw homepage uit</a>';
  
  html += '<div class="a2a_kit a2a_default_style">';
  html += '<a class="a2a_dd" href="http://www.addtoany.com/share_save">Share</a><span class="a2a_divider"></span>';
  html += '<a class="a2a_button_facebook"></a><a class="a2a_button_twitter"></a><a class="a2a_button_email"></a>';
  html += '</div>';

  html += '<img src="http://be.sitestat.com/vrt/sandbox1/s?leenjehomepage' + mflSplashTitle + '&amp;behoefte=overige&amp;category=standaard&amp;mediatype=overige&amp;doelgroep=none&amp;marketing=none&amp;waar=intern&amp;productiehuis=prodnone" width="1" height="1" alt=""/>';
  
  html += '</div>';
  
  MusicForLifeSplash.content.innerHTML = html;
  a2a.init();
  
  MusicForLifeSplash.overlay.style.display = 'block';
  MusicForLifeSplash.content.style.display = 'block';  
  
  MusicForLifeSplash.setCookie('mfl-' + mflSplashTitle, 'showed', '/', 1);
  
}

/**
 * Close the overlay
 */
MusicForLifeSplash.closeOverlay = function() {
  MusicForLifeSplash.overlay.style.display = 'none';
  MusicForLifeSplash.content.style.display = 'none';
}

/**
 * Go to music for life
 */
MusicForLifeSplash.gotoStubru = function() {
  document.location = "http://www.stubru.be/programmas/musicforlife";
}

/**
 * Set a cookie key-value pair with optional expiration date
 */
MusicForLifeSplash.setCookie = function (c_name, value, path, expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  var cookie_string = c_name+ "=" + escape(value);
  cookie_string += "; path=/";
  cookie_string += ((expiredays==null) ? "" : "; expires=" + exdate.toGMTString());
  document.cookie = cookie_string;
}

/**
 * Get a cookie value from give key
 */
MusicForLifeSplash.getCookie = function (c_name) {
  if (document.cookie.length>0) {
    var c_start = document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) {
      c_start = c_start + c_name.length + 1;
      var c_end = document.cookie.indexOf(";",c_start);
      if (c_end==-1) {
        c_end=document.cookie.length;
      }
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

window.onload = MusicForLifeSplash.init;
