var mynews=new Array();
var newsmp3=new Array();
var newsphoto=new Array();
var newsphotourl=new Array();
var weather=new Array();
var weather1=new Array();
var weather2=new Array();
var worldnews=new Array();

$.get('/counter/news.xml', function(thexml) {
	var k=0;
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
	
			mynews[k]=new Object();
			mynews[k]._url=url;
			mynews[k]._title=title;
			mynews[k]._date=date;
			mynews[k]._desc=desc;
			k++;
	});
});

$.get('/counter/worldnews.xml', function(thexml) {
	var k=0;
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
	
			worldnews[k]=new Object();
			worldnews[k]._url=url;
			worldnews[k]._title=title;
			worldnews[k]._date=date;
			worldnews[k]._desc=desc;
			k++;
	});
});

var k=0;
$.get('/counter/photo2.xml', function(thexml) {
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var urllink=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			var author=$(this).find('author').text();
			
			
			title=$.trim(title);
			desc=$.trim(desc);
			
			newsphoto[k]=new Object();
			newsphotourl[k]=new Object();
		
			var url=$(this).find('guid').text();	
			var pos=url.indexOf('?');
			url=url.substring(0,pos);
			newsphotourl[k].url=url;
			newsphotourl[k].duration=5;
			newsphoto[k].title=title;
			newsphoto[k].date=date;
			newsphoto[k].desc=desc;
			newsphoto[k].author=author;
		
	
			k++;
	});
});


$.get('/counter/photo.xml', function(thexml) {
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var urllink=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			var author=$(this).find('author').text();
			
			
			title=$.trim(title);
			desc=$.trim(desc);
			
			newsphoto[k]=new Object();
			newsphotourl[k]=new Object();
		
			var url=$(this).find('guid').text();	
			var pos=url.indexOf('?');
			url=url.substring(0,pos);
			newsphotourl[k].url=url;
			newsphotourl[k].duration=5;
			newsphoto[k].title=title;
			newsphoto[k].date=date;
			newsphoto[k].desc=desc;
			newsphoto[k].author=author;
		
	
			k++;
	});
});


function displaynewsphoto()
{
	var str='';
	var qty=0;
	str+='<center><div id="phototitle" class="title"></div>';
	str+='<div id="qty" class="subtitle"></div>';
	str+='<div id="newsplayer" style="width:500px; height:450px;"></div>';
	str+='<div id="fly"></div>';
	str+='<div id="author"></div></center>';
	$('#listphoto').html(str);
	
	
	$f("newsplayer", "/flowplayer/flowplayer.commercial-3.1.1.swf", {
	        key: '#$7b8b4d930c6debe77df',
			clip: {
					scaling: 'fit',
					onBegin:function(clip) {
						var i=clip.index;
						$('#phototitle').html(newsphoto[i].title);
						$("#fly").html(newsphoto[i].desc);
						$('#fly').find('img').remove();
						$('#fly').find('a').remove();
						qty=i+1;
						$('#qty').html(qty+' of ' + newsphotourl.length + ' pictures ');	
						$('#author').html('Author : '+newsphoto[i].author + ' Date : ' + newsphoto[i].date);
					}
			  },
			playlist: newsphotourl,
			plugins: { 
				 controls:{ playlist: true,                                
				 url:"/flowplayer/flowplayer.controls-3.1.1.swf",              
				 backgroundColor: "#000000"}         
			}
	});
   
}

function getnews()
{

	var str='<ul>';
	for(var i=0; i < mynews.length; i++)
	{
		str+='<li><a href="'+mynews[i]._url+'" target="_blank">'+mynews[i]._title+'</a>&nbsp;&nbsp;'+mynews[i]._date;
		str+='<p>'+mynews[i]._desc+'</p></li>';
	}
	str+='</ul>';
	$('#mymenux').html(str);																				

}


function headline()
{
	var str='';
	str+='<fieldset><legend class="subtitle">News from Cambodia</legend>';
	str+='<ul>';
	for(var i=0; i < mynews.length; i++)
	{
		str+='<li><a href="'+mynews[i]._url+'" target="_blank">'+mynews[i]._title+'</a>&nbsp;&nbsp;'+mynews[i]._date;
		str+='<p>'+mynews[i]._desc+'</p></li>';
	}
	str+='</ul>';
	str+='</fieldset>';
	$('#listnews').html(str);																				

}

function getworldnews()
{
	var str='';
	str+='<fieldset><legend class="subtitle">World news</legend>';
	str+='<ul>';
	for(var i=0; i < worldnews.length; i++)
	{
		str+='<li><a href="'+worldnews[i]._url+'" target="_blank">'+worldnews[i]._title+'</a>&nbsp;&nbsp;'+worldnews[i]._date;
		str+='<p>'+worldnews[i]._desc+'</p></li>';
	}
	str+='</ul>';
	str+='</fieldset>';
	$('#listworld').html(str);																				

}

function getweather()
{
	var suid=profile._uid;
	var zipcode=profile._zipcode;
	var city=profile._city;
	var country=profile._country;
	$.get('/lib/weather.php',{zipcode:zipcode,uid:suid,id:Number(new Date),city:city,country:country}, function(data) {
		displayweather();															  
	});
}

function displayweather()
{
	var suid=profile._uid;
	var zipcode=profile._zipcode;
	var url='/users/'+suid+'/weather.xml';
	var str='';
	str+='<br><fieldset class="width210"><legend class="subtitle">Weather</legend>';
	$.get(url,{id:1}, function(thexml) {
		$('item',thexml).each(function() {
			var image=$(this).find('image').text();
			var src=$(this).find('link').text();
			var title=$(this).find('title').text();
			var desc=$(this).find('description').text();
			str+=title;
			str+='<p>'+desc+'</p>';
		});
		str+='</fieldset>';
		$('#weather').html(str);
		$('#weather').find('a').remove();
	});
}


$.get('/counter/newsmp3.xml', function(thexml) {
	var k=0;
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
	
			newsmp3[k]=new Object();
			newsmp3[k].url=url;
			newsmp3[k].title=title;
			newsmp3[k].date=date;
			newsmp3[k].desc=desc;
			k++;
	});
});

function getnewsmp3()
{
	var str='';
	var k=1;
	str+='<center>';
	str+='<table border="1" cellpadding="5" cellspacing="0">';
	for(var i=0; i < newsmp3.length; i++)
	{
		str+='<tr><td>'+k+'</td>';
		str+='<td align="left"><a onclick="playnews('+i+');">'+newsmp3[i].title+'</a>';
		str+='</td>';
		var date=newsmp3[i].date;
		var len=date.length - 5;
		date=date.substring(0,len);
		str+='<td>'+date+'</td></tr>';
		k++;
	}
	str+='</table></center>';

	$('#mp3').html(str);
}

function playnews(i)
{
	var date=newsmp3[i].date;
	var url=newsmp3[i].url;
	var title=newsmp3[i].title;
	
	strmsg='<center><table border="1" cellpadding="5" cellspacing="0" width="500">';
	strmsg+='<tr><td align="left">Title</td><td align="left">'+ title+'</td></tr>';
	strmsg+='<tr><td align="left">Date</td><td align="left">'+date+'</td></tr>';
	strmsg+='<tr><td align="left">Owner</td><td align="left">Radio Free Asia</td></tr>';
	strmsg+='</table></center>';
	$('#fly').html(strmsg);
					
	$f("player", "/flowplayer/flowplayer.commercial-3.1.1.swf", {
	   key: '#$7b8b4d930c6debe77df',
	    clip: {
				scaling: 'fit',
				onStart: function(clip) {
					$('#prod').html('');
				
				}
			},
		playlist: ['/image/rfa.jpg',url],
		plugins: { 
				 	controls:{ playlist: true,                                
				 	url: "/flowplayer/flowplayer.controls-3.1.1.swf",              
				 	backgroundColor: "#000000"}         
				 } 
	});
}



$.get('/counter/siemreap.xml', function(thexml) {
	var k=0;
	
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
			if(i < 3)
			{
				weather[k]=new Object();
				weather[k]._url=url;
				weather[k]._title=title;
				weather[k]._date=date;
				weather[k]._desc=desc;
				k++;
			}
	});
	
});


$.get('/counter/phnompenh.xml', function(thexml) {
	var k=0;
	
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
			if(i < 3)
			{
				weather1[k]=new Object();
				weather1[k]._url=url;
				weather1[k]._title=title;
				weather1[k]._date=date;
				weather1[k]._desc=desc;
				k++;
			}
	});
	
});


$.get('/counter/kampongcham.xml', function(thexml) {
	var k=0;
	
	$('item',thexml).each(function(i) {
			var title=$(this).find('title').text();
			var url=$(this).find('link').text();
			var desc=$(this).find('description').text();
			var date=$(this).find('pubDate').text();
			title=$.trim(title);
			desc=$.trim(desc);
			if(i < 3)
			{
				weather2[k]=new Object();
				weather2[k]._url=url;
				weather2[k]._title=title;
				weather2[k]._date=date;
				weather2[k]._desc=desc;
				k++;
			}
	});
	
});

function getsiemreap()
{
	var str='';
	str+='<fieldset><legend class="subtitle">Siem Reap</legend>';
	str+='<ul>';
	for(var i=0; i < weather.length; i++)
	{
		str+='<li>'+weather[i]._title;
		str+='<p>'+weather[i]._desc+'</p>';
		str+='<p>Date : '+weather[i]._date+'</p></li>';
	}
	str+='</ul>';
	str+='</fieldset>';
	$('#siemreap').html(str);																				

}


function getphnompenh()
{
	var str='';
	str+='<fieldset><legend class="subtitle">Phnom Penh</legend>';
	str+='<ul>';
	for(var i=0; i < weather1.length; i++)
	{
		str+='<li>'+weather1[i]._title;
		str+='<p>'+weather1[i]._desc+'</p>';
		str+='<p>Date : '+weather1[i]._date+'</p></li>';
	}
	str+='</ul>';
	str+='</fieldset>';
	$('#phnompenh').html(str);																				

}


function getkampongcham()
{
	var str='';
	str+='<fieldset><legend class="subtitle">Kampong Cham</legend>';
	str+='<ul>';
	for(var i=0; i < weather2.length; i++)
	{
		str+='<li>'+weather2[i]._title;
		str+='<p>'+weather2[i]._desc+'</p>';
		str+='<p>Date : '+weather2[i]._date+'</p></li>';
	}
	str+='</ul>';
	str+='</fieldset>';
	$('#kampongcham').html(str);																				

}

function getweathers()
{
	getphnompenh();
	getsiemreap();	
	getkampongcham();
}



