var DEBUG = false;  // LIVE ... TRUE for TESTING

var DISABLE_BANNERS = false;
var DISABLE_VIDEOBANNERS = false;
var random = Math.round(Math.random()*100000000);

var DISABLE_DART = false; // LIVE ... TRUE to REMOVE ALL BANNERS

function topLevelDir(fullpath)
{
   topleveldir=fullpath;
   if (typeof fullpath != 'undefined') {
      firstslash=fullpath.indexOf('/');
      if (firstslash!=-1) {
        secondslash=fullpath.substring(firstslash+1).indexOf('/');
        if (secondslash != -1) {
           topleveldir=fullpath.substring(firstslash+1,secondslash+1);
        }
      }
   }
   return topleveldir;
}

function getParameter ( queryString, parameterName ) {
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		begin = queryString.indexOf ( parameterName );
		if ( begin != -1 ) {
			begin += parameterName.length;
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			return unescape ( queryString.substring ( begin, end ) );
		}
		return "null";
	}
}

function showBanner(size) {

  if (DISABLE_BANNERS == true)
  {
    return;
  }
  
  if (DISABLE_DART == false)
  {
     showDartBanner(size);
     return;
  }
}

var tilecounter = 0;

function showDartBanner(size) {

    var prefix = "http://ad.nl.doubleclick.net/";
    var domain = "Skyradio.nl/";

    if (typeof usezone == 'undefined') {
      //var zone = getZoneFromPath(location.pathname);
      var zone = getZoneFromPath(location.href);
    } else {
       var zone = usezone;
    }

    if (typeof segQS == 'undefined') { segQS = ''; }

    var specific = zone + ";sz=" + size + ";" + segQS + ";tile=" + (++tilecounter) + ";ord=" + random + "?";

    size = size.toLowerCase();

    var xIndex = size ? size.indexOf("x") : '';
    var imgSize = '';
    var width;
    var height;
    if(size &&  xIndex != -1) {
        width = size.substr(0, xIndex);
        height = size.substr(xIndex+1, size.length);
        imgSize = 'width="' + width + '" height="' + height + '"';
    }

    if (DEBUG == false) {
    var tag = '<script language="JavaScript" src="' + prefix + 'adj/' + domain + specific + '" type="text/javascript"></script>\n';
    document.write(tag);
    document.write("<!--" + prefix + 'adj/' + domain + specific+"-->");
    } else {
    var mytag = 'zone=' + zone ;
    document.write("<div style=\"width: "+width+"px; height: "+height+"px; border: 1px solid black; background-color: #cccccc; color: #777777; font-family:Arial; text-align: center;\">"
      +mytag+"</div>");
    }
}

function stringEndsWith(str, strmatch) {
  return str.lastIndexOf(strmatch)==str.length-strmatch.length;
}

// translate the current path to a configured zone

function getZoneFromPath(path) {

  var zone = 'home';
  var originalPath = path;
  
  zone = matchZoneWithPath(path);

  while (path!= "" && path!="/" && zone=="home") {
    xIndex = path.substring(0, path.length-1).lastIndexOf("/");
    path = path.substring(0, xIndex+1);
    
    zone = matchZoneWithPath(path);
    if (path=="/")
    {
      zone='home';
    }
  }
  return zone;
}

function matchZoneWithParam(newPath) {
  var zone="home";
  if (newPath.indexOf("index.php?") >-1)
  {
    if (newPath.indexOf("=") >-1)
    {
      zone = newPath.substring(newPath.lastIndexOf("?")+1, newPath.indexOf("="));
    } else {
      zone = newPath.substring(newPath.lastIndexOf("?")+1, newPath.length);
    }
  }
  return zone;
}

//match the path with the corresponding zone

function matchZoneWithPath(newPath) {
	var zone = 'home';
	if (newPath.indexOf("skyradio.nl") >-1) {
		switch(getParameter(newPath, "page")) { // matched /page=ZONE/XXX
			case 'skyradio/frequenties_zoeken':			zone = 'skyradio_frequenties';			break;
			case 'skyradio/online_mobile':				zone = 'skyradio_onlinemobile';			break;
			case 'skyradio/nieuwsbrief':				zone = 'skyradio_nieuwsbrief';			break;
			case 'skyradio/cd_dvd_boeken':				zone = 'skyradio_shop';					break;
			case 'skyradio/over_sky_radio':				zone = 'skyradio_overskyradio';			break;
			case 'skyradio/vacatures':					zone = 'skyradio_vacatures';			break;
			case 'skyradio/contact':					zone = 'skyradio_contact';				break;
			case 'muziek/music_panel':					zone = 'muziek_musicpanel';				break;
			case 'muziek/concertagenda':				zone = 'muziek_concertagenda';			break;
			case 'muziek/sky_radio_hits':				zone = 'muziek_skyradiohits';			break;
			case 'muziek/popquiz':						zone = 'muziek_popquiz';				break;
			case 'muziek/reviews':						zone = 'muziek_reviews';				break;
			case 'entertainmentnieuws':					zone = 'skyradio_entertainmentnieuws';	break;
			case 'entertainment/stelling_van_de_dag':	zone = 'entertainment_stelling';		break;
			case 'entertainment/filmagenda':			zone = 'entertainment_filmagenda';		break;
			case 'entertainment/filmrecensies':			zone = 'entertainment_filmrecensies';	break;
			case 'entertainment/fotoboeken':			zone = 'entertainment_fotoboeken';		break;
			case 'entertainment/games':					zone = 'entertainment_games';			break;
			case 'entertainment/wallpapers':			zone = 'entertainment_wallpapers';		break;
			case 'acties/actie_overzicht':				zone = 'acties_actieoverzicht';			break;
			case 'acties/cd_van_de_week':				zone = 'acties_cdvandeweek';			break;
			case 'acties/dvd_van_de_week':				zone = 'acties_dvdvandeweek';			break;
			case 'acties/prijswinnaars':				zone = 'acties_prijswinnaars';			break;
			case 'acties/actievoorwaarden':				zone = 'acties_actievoorwaarden';		break;
			case 'acties/this_cadeaubon':				zone = 'acties_thiscadeaubon';			break;
			case 'downloadshop':     	                zone = 'downloadshop';					break;
			case 'actie_overzicht/win_een_avontuurlijk_dagje_in_ouwehands_dierenpark':  zone = 'ouwehand';	break;
		}
		switch (matchZoneWithParam(newPath)) { // matches /index.php?XXX=bla
			case 'playlist':                    		zone = 'skyradio_playlist';				break;
			case 'artiesten':         		            zone = 'muziek_artiesten';				break;
		}
		switch (newPath) { // matches /player.php
			case 'http://skyradio.nl/player.php':							zone = 'player';			break;
			case 'http://www.skyradio.nl/player.php':						zone = 'player';			break;
			case 'http://skyradio.nl/player_nl.php':						zone = 'NL';				break;
			case 'http://www.skyradio.nl/player_nl.php':					zone = 'NL';				break;
			case 'http://skyradio.nl/player_lovesongs.php':					zone = 'Lovesongs';			break; 
			case 'http://www.skyradio.nl/player_lovesongs.php':				zone = 'Lovesongs';			break;
			case 'http://skyradio.nl/player_summerhits.php':				zone = 'Summer Hits';		break;
			case 'http://www.skyradio.nl/player_summerhits.php':			zone = 'Summer Hits';		break;
// Nieuwe players
			case 'http://skyradio.nl/player/skyradio.html':					zone = 'player';			break;
			case 'http://www.skyradio.nl/player/skyradio.html':				zone = 'player';			break;
			case 'http://skyradio.nl/player/skyradio_nl.html':				zone = 'NL';				break;
			case 'http://www.skyradio.nl/player/skyradio_nl.html':			zone = 'NL';				break;
			case 'http://skyradio.nl/player/skyradio_lovesongs.html':		zone = 'Lovesongs';			break; 
			case 'http://www.skyradio.nl/player/skyradio_lovesongs.html':	zone = 'Lovesongs';			break;
			case 'http://skyradio.nl/player/skyradio_seasonal.html':		zone = 'Summer Hits';		break;
			case 'http://www.skyradio.nl/player/skyradio_seasonal.html':	zone = 'Summer Hits';		break;
			//
			case 'http://skyradio.nl/specials/2010_hollandcasino/':		zone = 'holland_casino';		break;
			case 'http://www.skyradio.nl/specials/2010_hollandcasino/':	zone = 'holland_casino';		break;
			
		}
switch (newPath) { 
			case 'http://www.babyvanhetjaar.nl':		zone = 'babyvanhetjaar';				break;
			case 'http://www.babyvanhetjaar.nl/':		zone = 'babyvanhetjaar';				break;	
			
			case 'http://skyradio.nl/specials/2010_martinair/':			zone = 'martinair';				break;
			case 'http://www.skyradio.nl/specials/2010_martinair/':		zone = 'martinair';				break;
		}
	}
	return zone;
}
