// Standard vars
var FO_Webcam = { movie:"flash/mediaplayer.swf", flashvars:"controlbar=none&bufferlength=4&showdigits=false&autostart=true&file=http://webplayer.studio040.nl/stream.php?type=webcam.flv", width:"440", height:"330", majorversion:"8", build:"0", id:"myUFO", name:"myMp3Player", swliveconnect:"false", play:"true", loop:"true", menu:"false", quality:"best", scale:"showall", wmode:"transparent", bgcolor:"#ffffff", allowscriptaccess:"samedomain" };

$(document).ready(function(){
	$('#tabs div.tab').hide(); // Hide all divs
	$('#tabs div:first').show(); // Show the first div
	$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
	$('#tabs ul li a').click(function(){ //When any link is clicked
		$('#tabs ul li').removeClass('active'); // Remove active class from all links
		$(this).parent().addClass('active'); //Set clicked link class to active
	
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		
		// Internet Explorer doesn't stop the flash stream, so we need to do it!
		//(currentTab == '#webcam') ? UFO.create(FO_Webcam, "webcam"):$('#webcam').empty();
		if(currentTab == 'webcam.html') 
		{
			return true;
			exit;
			//// Silverlight Config
			var slCnt = document.getElementById("webcam");
			var slSrc = '/js/wmvplayer.xaml';
			var slCfg = {
				file:'stream.php?type=webcam',
				height:'350',
				width:'440',
				autostart: 'true',
				windowless: 'true'
			};

			var slPlay = new jeroenwijering.Player(slCnt,slSrc,slCfg);
		} 
		else 
		{
			$('#webcam').empty();
		}		
	
		$('#tabs div.tab').hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
});
 

/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
 
(function($) {
/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 4000;
	initTicker = function(el)
	{
		stopTicker(el);
		el.items = $("li", el);
		// hide all items (except first one)
		el.items.not(":eq(0)").hide().end();
		// current item
		el.currentitem = 0;
		startTicker(el);
	};
	startTicker = function(el)
	{
		el.tickfn = setInterval(function() { doTick(el) }, delay)
	};
	stopTicker = function(el)
	{
		clearInterval(el.tickfn);
	};
	pauseTicker = function(el)
	{
		el.pause = true;
	};
	resumeTicker = function(el)
	{
		el.pause = false;
	};
	doTick = function(el)
	{
		// don't run if paused
		if(el.pause) return;
		// pause until animation has finished
		el.pause = true;
		// hide current item
		$(el.items[el.currentitem]).fadeOut("slow",
			function()
			{
				$(this).hide();
				// move to next item and show
				el.currentitem = ++el.currentitem % (el.items.size());
				$(el.items[el.currentitem]).fadeIn("slow",
					function()
					{
						el.pause = false;
					}
				);
			}
		);
	};
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase()!= "ul") return;
			initTicker(this);
		}
	)
	.addClass("newsticker")
	.hover(
		function()
		{
			// pause if hovered over
			pauseTicker(this);
		},
		function()
		{
			// resume when not hovered over
			resumeTicker(this);
		}
	);
	return this;
};

})(jQuery);

var strOldArtist = '';

$(document).ready(function(){
    //$("#tabs").tabs();
    getPlayingInfo();
    getTickerInfo();
       
    $("#reageerForm").validate({
		submitHandler: function(form) {
			$.post("ajax.php",
			{ 	name: 		$("#reageerName").attr('value'), 
			  	email: 		$("#reageerEmail").attr('value'), 
			  	message: 	$("#reageerMessage").attr('value') },
			   	function(data){
					$("#reageerForm").slideUp("normal", function() {
						$("#reageerSucces").html('<h1>Gelukt!</h1><p>Deze reactie is verstuurd en zal binnen een paar minuten bij de DJ arriveren.</p>');
					});
				}
			);
	   		
	 	}
	});
});
  
function getPlayingInfo() {
	$.ajax({
	type: "GET",
	url: strPlayingFeed+'?'+Math.floor(Math.random()*1100),
	dataType: "xml",
		success: function(xml) {
			$(xml).find('title').each(function(){
 				var strArtist 	=	$(this).find('nowArtist').text();
				var strTitle 	= 	$(this).find('nowSong').text();
				var strProgram 	= 	$(this).find('nowProgram').text();
				var strArtistImage 	= 	$(this).find('nowImage').text();
				
				if(strArtist != strOldArtist) {
					strOldArtist = strArtist;
					changeText(strArtist,strArtistImage,strTitle,strProgram);
				}
			});
 		}
	});
   	setTimeout("getPlayingInfo()", 30000);
}

function changeText(strArtist,strArtistImage,strTitle,strProgram) {

	if(strArtist == "-" && $('#nowplayingBox').is(':visible')) {
		$("#nowplayingBox").fadeOut("slow");
	}
	if(strArtist != "-" && !$('#nowplayingBox').is(':visible')) {
		$("#nowplayingBox").fadeIn("slow");
	}
	
	$("#nowplayingArtist").html(strArtist);
	$("#nowplayingTitle").html(strTitle);	
		
	$("#nowplayingProgram").html('Nu op Studio040 <b>'+strProgram+"</b> ");
	$("#nowplaying").css("background-image", "url('"+strArtistImage+"')"); 
}

function getTickerInfo() {
	$.ajax({
		type: "GET",
		url: strNewsFeed,
		dataType: "xml",
		success: function(xmlData)
		{
			xmlDataSet = xmlData;
			parseXmlDataSet();
		}
	});

}

function parseXmlDataSet()
{	
	var newnews = $("<ul>").attr("class", "newsticker");
	$(xmlDataSet).find("item").each(function()
	{
		$("item",xmlDataSet).each(function(i) {
			newnews.append('<li><a href="'+$(this).find('link').text()+'" target="_blank">'+$(this).find('title').text()+'</a></li>');
		});		
	});

	newnews.appendTo("#ticker").newsTicker(8000);
}


