// JavaScript Document
var section = 'toptengames';

var topten_titles = [];
var topten_images = [];
var topten_descriptions = [];
var topten_urls = [];

var domainpath = '';

function parse_topten_xml() {

	$.ajax({
		type: "GET",
		url: ""+domainpath+"/xml/" + section + ".xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('game').each(function(){
				var title = $(this).find('title').text();
				var image = $(this).find('image').text();
				var desc = $(this).find('desc').text();
				var url = $(this).find('url').text();
				topten_titles.push(title);
				topten_images.push(image);
				topten_descriptions.push(desc);
				topten_urls.push(url);
				
			});
			
			build_topten_list(topten_titles, topten_images, topten_descriptions, topten_urls);
			
		}
	});
	
};

function build_topten_list(titles, images, descriptions, urls){
	
	for (i = 0; i < titles.length; i++) {		
		//add each tooltip to the body for proper scope
		
		$('.tabs').append('<li><a href="#tab'+i+'"><p>'+ titles[i] +'</p></a></li>');
		
		$('.tabs_container').append('<div id="tab'+ i +'" class="tab_content"><div class="game_display"><a href="'+urls[i]+'"><img src="'+domainpath+'/images/topten/'+images[i]+'" width="115" height="87" /></a><h2><a href="#">'+titles[i]+'</a></h2><p>'+descriptions[i]+'</p><p><a href="'+urls[i]+'">Play Now!</a></p></div></div>');
		
    }
	
	activateTabs();
	
}

function activateTabs(){

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ol.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ol.tabs li").click(function() {
		$("ol.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	
}


