function switchState(index)
{
	for(var i = 0; i < 4; i++)
	{
		var id = "volume" + (i+1);
		var obj = document.getElementById(id);
		
		var x = (2 - ( i * 10) ) + "px ";
		var y = "-21px";
		
		if (obj) obj.style.backgroundPosition = x + y;
		
	}
	for(var i = 0; i < index; i++)
	{
		var id = "volume" + (i+1);
		var obj = document.getElementById(id);
		
		var xy = 2 - ( i * 10) + "px 0";
		if (obj) obj.style.backgroundPosition = xy;
	}	
}


//===========================================================//
// SLAMFM Media Player                                       // 
// Developed by Dave Smits (Email: dave@familie-smits.com)   //
//===========================================================//


if (!window.SlamFM_SlamTV)
	SlamFM_SlamTV= {};

SlamFM_SlamTV.Player = function() 
{
}

SlamFM_SlamTV.Player.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		this.rootElement = rootElement;
		this.counter = 0;
		
		//Media Events
		rootElement.findName("player").addEventListener("MediaEnded", Silverlight.createDelegate(this, this.handleMediaEnded));
		rootElement.findName("player").addEventListener("MediaFailed", Silverlight.createDelegate(this, this.handleMediaEnded));
		rootElement.findName("player").addEventListener("CurrentStateChanged", Silverlight.createDelegate(this, this.handleCurrentStateChanged));
		rootElement.findName("player").AddEventListener("BufferingProgressChanged",  Silverlight.createDelegate(this, this.handleBufferingProgressChanged));
	},
	
	// MediaEnded en restart player
	handleMediaEnded: function(sender, eventArgs) 
	{
		// Restart media player
		//this.control.content.findName("player").play();
	},
	
	handleCurrentStateChanged: function(sender, eventArgs) 
	{
		//Get player and ready to do something
		player = this.control.content.findName("player");
	},
	
	// Handle buffer change
	handleBufferingProgressChanged: function(sender, eventArgs) 
	{
		var process = this.control.content.findName("player").bufferingProgress;
		elm =  this.control.content.findName("bufferTxt");
		elm.Visibility = "Collapsed";
		if (process < 1)
		{
			elm.Visibility = "Visible";
			
			bufferTxt =  ""+ ((process * 1000) / 10);
			if (bufferTxt.length > 2) bufferTxt = bufferTxt.substring(0, 2);
			if (bufferTxt.indexOf('.') > 0) bufferTxt = bufferTxt.substring(0, bufferTxt.indexOf('.') - 1);
			elm.Text = "LOADING: "+bufferTxt + '%';
		}
	},
	
	Play :  function()
	{
		this.control.content.findName("player").Source = 'http://true.nl/streams/dynamic/slamtv.asx';
		this.control.content.findName("player").play();
	},
	
	Stop : function()
	{
		this.control.content.findName("player").stop();
	},
	
	Mute: function()
	{
		if (this.control.content.findName("player").Volume != 0)
		{
			this.oldVolume = this.control.content.findName("player").Volume;
			this.control.content.findName("player").Volume = 0;
		} else
		{
			this.control.content.findName("player").Volume = this.oldVolume;
		}
		
	},
	
	Volume1: function()
	{
		this.control.content.findName("player").Volume = 0.25;
	},
	
	Volume2: function()
	{
		this.control.content.findName("player").Volume = 0.5;
	},
	Volume3: function()
	{
		this.control.content.findName("player").Volume = 0.75;
	},
	Volume4: function()
	{
		this.control.content.findName("player").Volume = 1;
	}
	
}