// JavaScript Document


//http://localhost/doRevamp/design/php/eagetmod.php?command=feature&subcommand=features&hot_today=1&section_id=2&offset=0&amount=6
var eafeedurl = "http://www.do.co.za/broadband/eafeeds/",
	doMusicUrl = "http://www.do.co.za/broadband/entertainment/music/news/#/feature/",
	doMoviesUrl = "http://www.do.co.za/broadband/entertainment/movie/news/#/feature/",
	doGamingUrl = "http://www.do.co.za/broadband/entertainment/gaming/news/#/feature/",
	ajaxParams = {
					"command" : "feature",
					"subcommand" : "features",
					"hot_today" : 1,
					"section_id" : 2,
					"offset" : 0,
					"amount" : 6	
					};

$(document).ready(function(){
	$.ajax({
		url: eafeedurl,
		type: "GET",
		dataType: 'json',
		data: ajaxParams,
		success: function(jsonData){displayInfo(jsonData, $("#container_scroll_music ul"), doMusicUrl)},
		error : function(jsonData){displayError($("#container_scroll_music ul"))}
	})

	// change params to access MOVIES : 
	ajaxParams.section_id = 3;

	$.ajax({
		url: eafeedurl,
		type: "GET",
		dataType: 'json',
		data: ajaxParams,
		success: function(jsonData){displayInfo(jsonData, $("#container_scroll_movies ul"), doMoviesUrl)},
		error : function(jsonData){displayError($("#container_scroll_movies ul"))}
	})
	
	// change params to access MOVIES : 
	ajaxParams.section_id = 4;
	
	$.ajax({
		url: eafeedurl,
		type: "GET",
		dataType: 'json',
		data: ajaxParams,
		success: function(jsonData){displayInfo(jsonData, $("#container_scroll_gaming ul"), doGamingUrl)},
		error :  function(jsonData){displayError($("#container_scroll_gaming ul"))}
	})


});

function displayInfo(jArr, elem, url){
	for (var i=0; i <jArr.length; i++) {
		var gotoUrl = url + jArr[i].article_id;
		elem.append("<li><a href='"+gotoUrl+"'><img src='"+jArr[i].img_feature+"' />"+jArr[i].title+"</a></li>")
	}
}


function displayError(elem){
	elem.append("<li>Error Loading Feed</li>")
	
}
