function Radio(id,title,stream,site,logo){    
		this.id = id;
		this.title = title;
		this.stream = stream;
		this.site = site;
		this.logo = logo;
}

radios = new Array() ;

function get_radios_feed(url) {
	$.getJSON(url, function(json){
		radios = json.Radio;
		radioinit();
		initfunction();
	});

	/*
	$.get(url, function(d) {
	var htmlStr= '';
	iterator =0;
	$(d).find('LINK').each(function(i) {
			newRadio = null;
			var $item = $(this);
			if ($item.attr('type') == 'radio') {
				newRadio = new Radio(
					$item.find('ZLOSTATID').text(),
					$item.find('TITLE').text(),
					$item.find('STREAM').text(),
					$item.find('URL').text(),
					"startpaginaradio/radio_files/" + $item.find('LOGO').text()
				);
				radios[iterator] = newRadio;
				iterator++;
			}
		});
		radioinit();
		initfunction();
	});
	*/
}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "IE"
else if (!checkIt('compatible'))
{
	browser = "Netscape"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "unknown OS";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

// Check Plugins
var detectableWithVB = false;
var pluginFound = false;

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
		goURL(redirectURL);
		return pluginFound;
    } else {
		return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
		return true;
    } else {
		return false;
    }
}



volume=100; //dummy value in case Player object not set.
volume_inc= 10;

function softer(){
	if (volume <=0) return;
	volume -=volume_inc;
	showVolumeslider(volume);
	if (window.myPlayer){
		if (myPlayer.settings)myPlayer.settings.volume -= volume_inc;
	}
}
function harder(){
	if (volume >=100) return;
	volume +=volume_inc;
	showVolumeslider(volume);
	if (window.myPlayer){
		if (myPlayer.settings)myPlayer.settings.volume += volume_inc;
	}
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    if(!pluginFound && detectableWithVB) {
		pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    var daPlugins = detectPlugin.arguments;
    var pluginFound = false;
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    numFound++;
		}   
	    }
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		break;
	    }
	}
    }
    return pluginFound;
} 


if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('</scr' + 'ipt>');
}

function loadMusic(media,newpause){
	if (newpause){
		$('#playpause').attr('src','startpaginaradio/radio_files/play.jpg');
	} else {
		$('#playpause').attr('src','startpaginaradio/radio_files/pause.jpg');
	}
	initiateStation(media);
	myPlayer = document.getElementById('Player');
	if (browser != 'IE') myPlayer = document.getElementById('PlayerEmd');
	pause=newpause;
	if(media!=''){
		currentstream = media;
	}
	if (window.myPlayer && myPlayer.settings)
		myPlayer.settings.volume = volume;
}
function updatetime()  
{  
 CurPos= '';
 Status='';
 $('#loadingtext').html('Loading:'); 
 if(window.myPlayer && myPlayer.controls && myPlayer.controls.currentPositionString)CurPos= myPlayer.controls.currentPositionString;
 if(window.myPlayer && myPlayer.status)Status= myPlayer.status;
 if (window.myPlayer && myPlayer.status)
 if (CurPos == '') {
		Status = Status.replace("voltooid","");
		Status = Status.replace("Opslaan ","");
		Status = Status.replace(" met media","");
		Status = Status.replace("...","");
		Status = Status.replace("Afspelen","");
		Status = Status.replace(":","");
		Status = Status.replace("zoeken naar media","Loading");
		$('#statustext').html(Status + ": " + medianame );  
		state = setTimeout ( "updatetime()", 100 );
	} else {
		$('#statustext').html(medianame);  
		$('#loadingtext').html('je luistert naar:');  
	}
} 
state='';
medianame='';
function initiateStation(media){
	if (media==''){
		$('#radiohidden').html('');
		return;
	}
	newRadio = "";
	newRadio += "<OBJECT ID='Player' height='0' width='0' CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'>"
	newRadio += "<PARAM name='URL' value='" + media + "' id='insert_1'>"
	newRadio += "<PARAM name='uiMode' value='none'>"
	newRadio += "<PARAM name='mute' value='false'>"
	newRadio += "<PARAM name='ShowControls' value='0'>"
	newRadio += "<PARAM name='ShowStatusBar' value='0'>"
	newRadio += "<PARAM name='ShowDisplay' value='0'>"
	newRadio += "<EMBED type='application/x-mplayer2' "
	newRadio += "pluginspage = 'http://www.microsoft.com/Windows/MediaPlayer/' "
	newRadio += "SRC='" + media + "' "
	newRadio += "name='Player' "
	newRadio += "id='PlayerEmd' "
	newRadio += "width='0' "
	newRadio += "height='0' "
	newRadio += "AutoStart='true' "
	newRadio += "showcontrols='0' "
	newRadio += "showstatusbar='0' "
	newRadio += "showdisplay='0' "
	newRadio += "id='insert_2'>"
	newRadio += "</EMBED>"
	newRadio += "</OBJECT>"
	$('#radiohidden').html(newRadio);
	if (state!='') clearTimeout(state);
	state = setTimeout ( "updatetime()", 1000 );
 
}

function showVolumeslider(x){
		x =Math.round(((x/2) * 53) /50);
		var pos = 0;//$('#volume').offset();    
		var width = 0;//$('#volume').width();  
		$("#volumeindicator").css( { 
			"z-Index": 100, 
			"left": ((189) + x) + "px", 
			"width":(53-x) + "px",
			"background":"#EBF0F4"
			} );  
		$("#volumeindicator").show();
}

function radioinit(){
	middle = false;
	pause=false;
	currentstream='';
	initiateStation('');
	for (i=0;i<radios.length-1;i++){
		$('#image_container').html($('#image_container').html()
		+"<div class=\"radiologowrap\"><div class=\"radiologo\" >"
		+"<img height=\"46px\" src=\""+
		radios[i].logo+"\" class=\"radiologoimg\" alt=\""+radios[i].title+"\"/></div><div class=\"radio_border\" rs=\""
		+i+"\"></div></div>");
		if (!middle && i >= (radios.length-2)/2)  {
			$('#image_container').html($('#image_container').html()+"");
			middle = true;
		}
	}
	showVolumeslider(100);
	$('.radio_border').hover(
		
		function(){
			if ($(this).attr('activestr') == 'true') return;
			$(this).css('background','url(startpaginaradio/radio_files/radiotabSelect.gif) no-repeat');
		},
		function(){
			if ($(this).attr('activestr') == 'true') return;
			$(this).css('background','url(startpaginaradio/radio_files/radiotab.gif) no-repeat');
		}
	);
	$('.radio_border').click(
		function(){
			$('#loadingtext').html('Loading:'); 
			loadMusic(radios[parseInt($(this).attr('rs'))].stream,false);
			$('#statustext').html("" + radios[parseInt($(this).attr('rs'))].title );  
			medianame = radios[parseInt($(this).attr('rs'))].title;
			arnostatDemo('uberblok-radio-' + medianame);
			$('.radio_border').each(function(){
				$(this).css('background','url(startpaginaradio/radio_files/radiotab.gif) no-repeat');
				$(this).attr('activestr','');
			});
			$(this).css('background','url(startpaginaradio/radio_files/radiotabSelect.gif) no-repeat');
			$(this).attr('activestr','true');		
		});
	$('#playpause').click(
		function(){
		if (pause){
			loadMusic(currentstream,false);
			} else {
			if (myPlayer.settings)myPlayer.controls.stop();
			loadMusic('',true);
			}
		});
};
// JavaScript Document
$move_by = 80;
$frame_left = 0;
$frame_no = 0;
$start_middle = 0;

function checkBoundaries() {
	if($frame_no >= ($max_clicks-4))	{		
		$("#rightbutton").hide();
	} else {
		$("#rightbutton").show();
	}
	if($frame_no <= 0){
		$("#leftbutton").hide();
	} else {
		$("#leftbutton").show();
	}
}

function initfunction()
{
	
	$max_clicks = ($("#image_container").children().size())/2; 	
	/* Kudos to Rob MacKay [http://www.twitter.com/svgrob] for suggesting that we don't have to put a static style="width: 3960px" attribute in the div tag */
	$imgCont = ($move_by * ($max_clicks+1)); 
	 
	$("#image_container").css({width : $imgCont});
	checkBoundaries();
	if($start_middle == 1)
		{
			// Get the middle frame, according to the $max_clicks
			$new_frame_no = ($max_clicks/2).toFixed(0)
			
			// Adjust the frame position
			$new_left = -($new_frame_no * $move_by);						
			$new_left_attr = $new_left+"px";
			
			// Do the move
			$("#image_container").animate({left: $new_left_attr}, 800 );
			
			// Save the new values
			$frame_left = $new_left;
			$frame_no = ($new_frame_no/1 + 1);
		}
	
	
	
	$("#leftbutton").click(function()
		{
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)-1);
			$new_left = (($frame_left/1) + $move_by);
			/* Check if we're moving too far over */
			$new_left_attr = $new_left+"px";
			$("#image_container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
			checkBoundaries();
		});
	$("#rightbutton").click(function()
		{
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)+1);
			$new_left = (($frame_left/1) - $move_by);
			/* Check if we're moving too far over */
			$new_left_attr = $new_left+"px";
			$("#image_container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
			checkBoundaries();
		});	
};
