var speler = null;
var sb_actie = null;
var interval_aantal_bezoekers = null;
var oude_aantal_online;
var aantal_online_is_geladen = 0;

$(document).ready(function() {

  $("#bp-externe-link, #doi-externe-link").click(function() {
	var url = $(this).attr("href");	
	trackGAExterneLinks(url);
  });

  if (document.getElementById("map")) {
    gMapLaden();
  }

  $("#link-focus-zoekbox").click(function() {
										  
    var t = $("#target-404").html();										  
	$("#s").val(t);								   
    $("#s").focus();
    $("#s").select();
  
  });

  $("#link-add-to-favs").click(function() {
	var url = escape($(this).attr("rel"));
	setFav(url);
  });

  $(".ngg-gallery-thumbnail-box a img").click(function() {
													   
	var doel = $(this).attr("src");
	
	if ( doel.indexOf("/wallpapers/") > 0 ) {
      sb_actie = "<a id='shadowbox_nav_save' title='Klik om op te slaan' onclick='opslaanWallpaper()'></a>";
	}
	else {												   
      sb_actie = "<a id='shadowbox_nav_print' title='Klik om te printen' onclick='printPlaatje()'></a>";
	}

	$("#custom_actie_sploeng").html(sb_actie);

  });


  $(".ngg-album, .menu-tab span, .hyve-home, #nieuw-op-de-site").mouseover(function() {
	$(this).css( { cursor: "hand" } );
	
  });

  $("#nieuw-op-de-site").mouseover(function() {
    $(this).css( { cursor: "hand", backgroundImage: "url('/img/stijlen/bg-nieuw-op-de-site-focus.png')" } );											
  });

  $("#nieuw-op-de-site").mouseout(function() {
    $(this).css( { backgroundImage: "url('/img/stijlen/bg-nieuw-op-de-site.png')" } );											
  });

  $("#container-home a").mouseover(function() {
	$(this).css( { cursor: "hand" } );
	
	if ($(this).attr("id") == "link-sh") {
	  $("#txt-info-sh").css( { background: "#018373" } );
	}

	else if ($(this).attr("id") == "link-kb") {
	  $("#txt-info-kb").css( { background: "#018373" } );
	}

  });
 
  $("#container-home a").mouseout(function() {
	
	if ($(this).attr("id") == "link-sh") {
	  $("#txt-info-sh").css( { background: "#ff6f00" } );
	}
	else if ($(this).attr("id") == "link-kb") {
	  $("#txt-info-kb").css( { background: "#ff6f00" } );
	}

  }); 
  
  $(".hs-radio").click(function() {
    var station = $(this).attr("id");
	var starten = $(this).attr("starten");
	radioStreamLaden(station,starten);
	return false;
  });
 
   $("#lees-mop").click(function() {
    $("#tekst-mop").toggle();
	$("#lees-mop").css( { display: "none" } );
	return false;
  });
 
    
  interval_aantal_bezoekers = setInterval(bezoekersOnline, 30000);
  
});

function initRondeHoeken() {
	
  settings = {
  tl: { radius: 5 },
  tr: { radius: 5 },
  bl: { radius: 5 },
  br: { radius: 5 },
  antiAlias: true,
  autoPad: true,
  validTags: ["div","p"]
  }


  if ( document.getElementById("post-meta") ) {

    var post_meta_ronde_hoeken = new curvyCorners(settings, "post-meta");
    post_meta_ronde_hoeken.applyCornersToAll();

  }

}

function printPlaatje() {

  var plaatje = $("#shadowbox_content").attr("src");  
  var titel = $("#shadowbox_title_inner").html();
  //location.href="/wp-content/themes/sploeng/print-kleurplaat.php?img="+plaatje+"&titel="+escape(titel);
  location.href="/print-kleurplaat.php?img="+plaatje+"&titel="+escape(titel);

}

function opslaanWallpaper() {

  var plaatje = $("#shadowbox_content").attr("src");  
  var titel = $("#shadowbox_title_inner").html();
  //location.href="/wp-content/themes/sploeng/save-wallpaper.php?img="+plaatje+"&titel="+escape(titel);
  location.href="/save-wallpaper.php?img="+plaatje+"&titel="+escape(titel);

}

function radioStreamLaden(welk_station,starten) {
	
  if ( document.getElementById("radio-speler") ) {
	  
	if (welk_station) { 
	  
	  var station = welk_station;
	  if ( station == "juize" ) {
        var a_juize = "http://streamers.at.sara.garnierprojects.com/juizefm_high"; // juize FM
        //var muziek = "http://streamers.at.sara.garnierprojects.com/juizefm_high"; // juize FM	
		var muziek = "mms://clusterstreamhobo.telenet-ops.be/Plopsa_high";
	  }
	  else if ( station == "funx" ) {
        var a_funx = "mms://funx.xs4all.nl/funx"; // fun x
        var muziek = "mms://funx.xs4all.nl/funx"; // fun x		
	  }
	  else if ( station == "veronicafm" ) {	  
        var a_veronicafm = "http://www.garnierstreamingmedia.com/asx/streamerswitch.asp?stream=4";
        var muziek = "http://www.garnierstreamingmedia.com/asx/streamerswitch.asp?stream=4";		
	  }
	  else if ( station == "caz" ) {
        var a_caz = "http://www.garnierstreamingmedia.com/asx/caz_audio_01.asp";
        var muziek = "http://www.garnierstreamingmedia.com/asx/caz_audio_01.asp";
      }
	  else if ( station == "qmusic" ) {
        var a_qmusic = "http://live1.prostream.nl/qmusic";
		var muziek = "http://live1.prostream.nl/qmusic";
	  }
	  
	  else {
        var a_funx = "mms://funx.xs4all.nl/funx"; // fun x
        var muziek = "mms://funx.xs4all.nl/funx"; // fun x	
	  }

     //var a_slamfm = "http://www.slamfm.nl/stream/slamfm.asx"; // slam fm ** check op 2000220 = dood **

     //var a_plopsa = "mms://clusterstreamhobo.telenet-ops.be/Plopsa_high"

      var cnt = document.getElementById("radio-speler");
      var src = '/scripts/js/wmvplayer.xaml';
      var cfg = { 
	    height:'20',
	    width:'250',
	    //duration:'0',
	    file:muziek,
	    usefullscreen:'false',
	    //start:'0',
	    autostart: starten,
	    bufferlength:'15',
	    volume:'30' 
	  };
	
      speler = new jeroenwijering.Player(cnt,src,cfg);
	  
	  
	/*
	var s1 = new SWFObject('/img/player.swf','ply','250','20','9','#ffffff'); // 253 pixel breed 20 pixels hoog
    s1.addParam('allowfullscreen','false');
    s1.addParam('allowscriptaccess','always');
	s1.addParam('flashvars','file=" + muziek + "&autostart=' + autostarten);
    s1.addParam('wmode','opaque');
    s1.write('radio-speler');
	*/
	  
	}

  }
  
}

function setFav(url) {
  var url = unescape(url);	
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
	  window.external.AddFavorite(url,'Leuk voor Kids / Sploeng - print kleurplaten. Download wallpapers. Lees knutseltips.');
  }
  else {
	if (window.sidebar&&window.sidebar.addPanel) {
	  window.sidebar.addPanel("Leuk voor Kids / Sploeng - print kleurplaten. Download wallpapers. Lees knutseltips.",url,""); 
	}
	else { 
	  alert("Om Leuk voor Kids | Sploeng! te bookmarken gebruik je de toestcombinatie CTRL+D");
   }
  }
}

function bezoekersOnline() {
  
  if (aantal_online_is_geladen == 0) {
	  
	//$("img[@src$=bg-container-online-bezoekers.png], #container-bezoekers-online").ifixpng();
	$("img[@src$=bg-container-online-bezoekers.png],#container-img").ifixpng();
	$("img[@src$=bg-container-online-bezoekers-halloween.png],#container-img").ifixpng();	
    $("#container-bezoekers-online").fadeIn("fast");
    $("#container-bezoekers-online div").fadeIn("slow");
	aantal_online_is_geladen = 1;
	
  }

  var url = "/online-gebruikers.php";

  $.ajax({
		 
    type: "GET",
    url: url,
    cache: false,
    dataType: "text",
    success: function(text){
		
	  var aantal_online = text;
	  oude_aantal_online = $("#container-bezoekers-online div span#aantal-online").html();
	  	  
	  if (aantal_online !== oude_aantal_online) {
		var leeg = "";
		$("#container-bezoekers-online div span#aantal-online").css( { display: "none" } ); //fadeOut("slow");
		$("#container-bezoekers-online div span#aantal-online").html(leeg);
		updateBezoekersOnline(aantal_online);  
	  }
	}

  });

  //interval_aantal_bezoekers = setInterval(bezoekersOnline, 30000);

}

function updateBezoekersOnline(aantal) {
  $("#container-bezoekers-online div span#aantal-online").html(aantal);	
  $("#container-bezoekers-online div span#aantal-online").fadeIn("slow");			
}

function trackGAExterneLinks(url) {	
  pageTracker._trackPageview(url);  
}
