/* Sunes custom script*/
$(document).ready(function(){
	$("#lid_1, #lid_3, #lid_4").hide();
	//$("#trid_32, #trid_34, #trid_35").show(); //Show season4
	$("#trid_40, #trid_41").show();	// Show season 5 (Simons s�son 2)
	
	$("table.boxTable tbody tr:nth-child(odd)", "div.main_rcol").css({
		"background-color" : "#ddd"
	});
	
	//$("table.sort tbody tr:nth-child(even) td").each(function(){});
});


/* Initialize dataTable for the team overview table */
$(function() {
  
  $("#teamTable").dataTable({
  	//"sPaginationType": "full_numbers",		//no need to turn on paging
  	"iDisplayLength" : -1,			//-1 shows all entries, no pagination
  	"bLengthChange" : false			//disable the 10, 20, 50 a page dropdown
  });
});

/**
 * Adds description of all skills to a Javascript variable
 */
var skillsObj;

$(function(){
		
	//Load data into the var
	$.ajax({
		"url" : "/js/skills.json",
		"datatype" : "json",
		"success" : function( data ){

            skillsObj = $.parseJSON( data );
			
			var selector = "#teamRoster .skillContainer small",
				skillArr = [],
				i,
				len,
				thisSkill,
				tmpElm,
				tmp,
				skillName;
			
			//Loop through each set of skills (small tag)
			$(selector).each(function(index, item){
				skillArr = $(item).html().split(",");		//split each tag into an array with the skills
				
				//New small element that we append each skill to
				tmpElm = $("<small>");
				
				//Loop through the array
				for ( i = 0, len = skillArr.length; i < len; i += 1 ){
					
					//lookup the skill in the skillsObj
					thisSkill = skillsObj.skill[ $.trim(skillArr[i]) ];
					
					//Do we find a match?
					if ( typeof thisSkill === "object" ){
						
						//Add comma after the skill name, unless the skill is the last one
						if ( i !== (skillArr.length -1) ){
							skillName = skillArr[i] + ",";
						} else {
							skillName = skillArr[i];
						}
					
						//Wrap the skill name in a spantag
						tmp = $("<span>" + skillName + "</span>");
						
						
						//TODO: Make a template and feed it with correct data, and use that as content
						tmp.qtip({
							content : {
								text 	: thisSkill.description,
								title 	: {
									text : skillArr[i]
								}
							}

						});
						
						//Append the spantag to the tmp small tag
						tmpElm.append(tmp);
					} else {
						tmpElm.append(skillArr[i]);
					}
				}
				//Replace the small tag in the document, with the created one
				$(item).replaceWith(tmpElm);
				
			});		
		}
	});
	
});



