$(document).ready(function()
{
	selection(1);
	
	$('.imwd').click(function(){ selection(1); });
	$('.mvs').click(function(){ selection(2); });
	$('.ri').click(function(){ selection(3); });
	$('.hs').click(function(){ selection(9); });
	$('.donation').click(function(){ selection(4); });
	$('.lnews').click(function(){ selection(10); });
	$('.resources').click(function(){ selection(5); });
	$('.ad').click(function(){ selection(7); });
	$('.support').click(function(){ selection(8); });
	
	
	$('#left-mvs').click(function(){
		selection(2);
		$(document).scrollTop(700);
	});
	
	
	$('#donation-left').click(function(){
		selection(4);
		$(document).scrollTop(750);
	});
	
	$('#left-history').click(function(){
		selection(9);
		$(document).scrollTop(750);
	});
	
	$('#left-ri').click(function(){
		selection(3);
		$(document).scrollTop(653);
	});
	
	$('#news-btn').click(function(){
		selection(10);
		$(document).scrollTop(653);
	});
	
	$('#left-iwdm').click(function(){
		selection(1);
		$(document).scrollTop(653);
	});
	
	$('#advertise').click(function(){
		selection(7);
		$(document).scrollTop(653);
	});
	
	$('#backtotop').click(function(){
		$(document).scrollTop(0);	
	});
	
	$('#search-button').click(function(){
		search($("#search-box input").val());	
	});
	
	$('#video-current').click(function(){ $('#video-player').toggle(); $('#video-archive').toggle(); });

	$.ajax({
	  	dataType: "xml",
	  	url: 'com/salat.php',
	  	datatype: 'xml',
	  	success: function(xml) {

		$(xml).find('prayer').each(function(){ 
			var fajr = $(this).find('fajr').text();
			var sunrise = $(this).find('sunrise').text();
			var dhuhr = $(this).find('dhuhr').text();    
			var asr = $(this).find('asr').text();    
			var maghrib = $(this).find('maghrib').text();  
			var isha = $(this).find('isha').text();
			var tday = $(this).find('date').text();
			
			$('#fajr_time').html(fajr);
			$('#sunrise_time').html(sunrise);
			$('#dhuhr_time').html(dhuhr);
			$('#asr_time').html(asr);
			$('#maghrib_time').html(maghrib);
			$('#isha_time').html(isha);
			$('#tday').html(tday);
		});

		}
	});

	$.ajax({
	  	dataType: "xml",
	  	url: 'com/xml.php',
	  	datatype: 'xml',
	  	success: function(data) {
		$(data).find('f').each(function(){ 
			var title = $(this).find('x').text();
			var post = "<img src='inc/images/ico-bulletin.png' class='ico-vbox' /><span onclick='window.location.href=\"bulletins/"+title+".pdf\"'>Latest Bulletin</span>";
			
			$("#latest-b-right").html(post);
		 });
		}
		
	 });

});
 
function selection(itemnum)
{
	switch(itemnum) 
	{
		case 1:
			$('#content-right').load('content/iwdm.php');
			break;
		case 2:
			$('#content-right').load('content/mvs.php');
			break;
		case 3:
			$('#content-right').load('content/ri.php');
			break;
		case 4:
			$('#content-right').load('content/donations.php');
			break;
		case 5:
			$('#content-right').load('content/resources.php');
			break;
		case 6:
			$('#content-right').load('content/calendar.php');
			break;
		case 7:
			$('#content-right').load('content/advertising.php');
			break;
		case 8:
			$('#content-right').load('content/support.php');
			break;
		case 9:
			$('#content-right').load('content/history.php');
			break;
		case 10:
			$('#content-right').load('content/news.php');
			break;
		default:
			break;
	}
}

function search(term)
{
	
	$.ajax({
	  	dataType: "xml",
	  	url: 'com/search.php',
	  	datatype: 'xml',
		success: function(data) {
		$(data).find('item').each(function(){ 
			
			var title = $(this).find('came').text();
			var clink = $(this).find('clink').text();
			var cd = $(this).find('cd').text();
			var cname = $(this).find('cn').text();
			
				if(cname != "")
				{
					addition += "<li onclick='parent.location.href=\"index.php?v="+clink+"\"'>"+title+" | Speaker: "+ cname;
	
					addition +=	"</li>";
				}
				else
				{
					addition +="<li onclick='parent.location.href=\"index.php?v="+clink+"\"'>"+title;
		
					addition +=	"</li>";
				}
				
			$("#results").html(addition);
			
		 });
		}
	 });
	 
}
