function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function popBox(u,h,w){
	window.open(u,"player","toolbar=no,location=no,menubar=no,directories=no,resizable=no,scrollbars=no,innerWidth="+w+",innerHeight="+h+",width="+w+",height="+h+",top=25,left=25").focus();
}


setInterval('doStuff(0)',7000);
setInterval('doStuff(1)',600000);

function doStuff(i)
{
	$.getJSON('radio/getusers.php?i=' + randomString(), function(data)
	{
		if( data.count > 0 ) $('#nrhlust').html('<p>Fj&ouml;ldi hlustenda &aacute; netinu n&uacute;na: ' + data.count + '</p>');
		else $('#nrhlust').html('');
		$('#artist').html(data.artist);
		$('#songname').html(data.song);
		$('#nartist').html(data.nartist);
		$('#nsongname').html(data.nsong);
		
	});
	if( i==1 )
	{
		$.ajax({
			url: "rss/get-rss.php",
			cache: true,
			success: function(html){
				$("#rss").html(html);
				
				// setup tooltip for a single DIV element
				$(".rsstable a").tooltip({
			
					// custom positioning
					position: 'top right',
			
					// move tooltip a little bit to the right
					offset: [-150, 10],
			
					// do not initialize tooltips until they are used
					lazy: true,
					effect: 'fade'
			
				});
			}
		});


		$.ajax({
			url: "get-right.php",
			cache: true,
			success: function(html){
				$("#right").html(html);			
			}
		});
		
		$.ajax({
			url: "get-cal.php",
			cache: true,
			success: function(html){
				$("#calendar").html(html);			
			}
		});
		
		$.getJSON("get-stat.php?i=" + randomString(), function(dat)
		{
			$("#footer").html(dat.footer);	
			setTimeout('placeFooter()',3000);

		});
		
		setInterval('getFaerd()',300000);
	}
}

function placeFooter()
{
	var _offs = $('#last').offset();
	var _offs2 = $('#footrow').offset();
	if(_offs.top > _offs2.top)
	{
		$('#footer').offset({top: _offs.top+10, left:10});
	}else
	{
		$('#footer').offset({top: _offs2.top+10, left:10});
	}
}

function getFaerd()
{
	$('#faerd').css({'background' : 'url(http://www3.vegag.is/faerd/nordurl1.gif?r='+randomString()+')','background-position' : '-260px -120px'});
}
