/***********************
* Adobe Edge Animate Composition Actions
*
* Edit this file with caution, being careful to preserve 
* function signatures and comments starting with 'Edge' to maintain the 
* ability to interact with these actions from within Adobe Edge Animate
*
***********************/
(function($, Edge, compId){
var Composition = Edge.Composition, Symbol = Edge.Symbol; // aliases for commonly used Edge classes

   //Edge symbol: 'stage'
   (function(symbolName) {
      
      
      Symbol.bindElementAction(compId, symbolName, "document", "compositionReady", function(sym, e) {
         var gnYear=2014;
         var gn=31938;
         var startWC= Date.parse("August 16, 2014, 15:59 UTC");
         //var startR2= Date.parse("June 27, 2014, 23:59 UTC");
         var endWC = Date.parse("May 24, 2015, 23:59 UTC");
         var gmtStart = Date.parse("October 26, 2014, 01:59 UTC");
         var gmtEnd = Date.parse("March 29, 2014, 00:59 UTC");
         var oneDay = 86400000;
         var todayDate = new Date();
         var todayTime = todayDate.getTime();
         var localOffset=todayDate.getTimezoneOffset()*60000;
         var dataURL = ('http:'==document.location.protocol?"http://www2.graphicnews.com/":"https://www.graphicnews.org/")+ "infostradasports/api.php";
         var dateFormat;
         var showLocal=0;
         var teamSelect;
         //GET QUERY STRING PARAMETERS TO SHOW MATCH
         var get = [];
         location.search.replace('?', '').split('&').forEach(function (val) {
           split = val.split("=", 2);
           get[split[0]] = split[1];
         });
         
         //REFRESH RATES
         var fixtureInterval;
         var groupInterval;
         var matchInterval;
         var playInterval;
         
         var screenArr=['latest','fixtures','matchtracker','team'];
         for (var i=0; i<2; i++){
         	sym.getSymbol("menuBtns").getSymbol("menuBtn"+i).$("icon").attr('src','images/menuIcon'+i+'.png');
         }
         var menuTxtArr=[];
         var headlinetext=sym.getSymbol("styleMc").$("headlinetxt").css("pointer-events","none");
         var sourcetxt=sym.getSymbol("styleMc").getSymbol("styleBase").$("sourceTxt").css("pointer-events","none");
         var menuTxt=sym.getSymbol("styleMc").$("menuTxt").css("pointer-events","none");
         var text=[];
         text[0]=sym.getSymbol("team").$("txt0").css("pointer-events","none");
         text[1]=sym.getSymbol("team").$("txt1").css("pointer-events","none");
         
         var txtArr=[];
         var teamArr=[];
         var tableCaps=[];
         var months=[];
         var key=[];
         var timetxt=[];
         //Start July 31
         function loadMatch(match){
         		resetmenu();
         		clearInterval(matchInterval);
         		clearInterval(playInterval);
         		matchInterval = setInterval(function() { getMatchInfo(match); }, 60000);
         		playInterval = setInterval(function() { getMatch(match); }, 60000);
         		getMatchInfo(match);
         		getMatch(match);
         		sym.$("matchtracker").fadeIn(400);
         		sym.$("fixtures").fadeOut(400);
         		sym.$("latest").fadeOut(400);
         		sym.$("team").fadeOut(400);
         		sym.getSymbol("matchtracker").$("preloaderh").fadeIn(0);
         		sym.getSymbol("matchtracker").$("preloadera").fadeIn(0);
         		showguide=0;
         		sym.getSymbol("matchtracker").$("guide").fadeOut(0)
         }
         var showMatch = function(match){ //to handle lexical scope
         	return function (e) {
         		loadMatch(match);
         		e.preventDefault();
         		e.stopPropagation();
         	};
         };
         function openMatch(){
         	 if (get["match"] + "" != "undefined"){// Check if there is a matchID
         				var startMatch=parseInt(get["match"],10);
         				loadMatch(startMatch);
         				sym.$("cup").animate({opacity:0.3},1000);
         				sym.$("bg").animate({opacity:0.25},1000);
         	}else{
         		sym.play();
         	}
         }
         //End July 31
         var showTeam = function(team){ //to handle lexical scope
         	return function (e) {
         		resetmenu();
         		teamSelect=team;
         		getTeamFixtures(team);
         		getSquad(team);
         		for (var n=0;n<20;n++){
         			if (teamIDs[n]==team){
         				sym.getSymbol('team').$('teamTxt0').html(teamArr[n]);
         			}
         		}
         		sym.getSymbol('team').$('crest').attr('src','crests/'+team+'.png');
         		clearInterval(fixtureInterval);
         		fixtureInterval = setInterval(function(){ getTeamFixtures(teamSelect); },600000);
         		sym.$("matchtracker").fadeOut(400);
         		sym.$("fixtures").fadeOut(400);
         		sym.$("latest").fadeOut(400);
         		sym.$("team").fadeIn(400);
         		e.preventDefault();
         		e.stopPropagation();
         	};
         };
         var teamIDs =[4007,4010,4486,4034,100094,4047,102813,4693,4075,4222,4080,4087,4098,4874,4286,4906,4908,4129,4972,4144];
         var venueID=[10438,15899,26737,35238,35239,36882,37425,49670,49671,49672,49673,49674];
         
         //AJAX gets data from xml source  --------------------------------------------
         $.ajax({	
         	type: "GET",
         	url: "GN"+gn+".xml",
         	dataType: "xml",
         	success: function(xml) {
         		var headline=$(xml).find('headline').text();
         		headlinetext.html(headline);
         		var source=$(xml).find('source').text();
         		sourcetxt.html(source);
         		dateFormat=$(xml).find('dateformat').text();//for different date formats
         		for (var m=0;m<2;m++){
         			menuTxtArr[m]= $(xml).find('menuTxt'+m).text();
         		}
         		for  (var i=0;i<34;i++){
         			txtArr[i]= $(xml).find('txt'+i).text(); //fixed text captions
         			if(i<text.length){
         				text[i].html(txtArr[i]);
         			}
         		}
         		//instruction page
         		sym.getSymbol("matchtracker").getSymbol("guide").$("txt2").html(txtArr[2]);	
         		var timerTxt="<div class='action period4'>";//style by period
         		timerTxt+="<div class='personh'>"+txtArr[3]+"</div>";
         		timerTxt+="<div class='type'><img src='images/goal.png'></div>";	
         		timerTxt+="<div class='actiontime'>"+txtArr[4]+"</div>";
         		timerTxt+="<div class='type'></div>";
         		timerTxt+="<div class='persona'></div>";
         		timerTxt+="</div>";
         		timerTxt+="<div class='action period4'>";
         		timerTxt+="<div class='personh'></div>";
         		timerTxt+="<div class='type'></div>";	
         		timerTxt+="<div class='actiontime'>"+txtArr[5]+"</div>";
         		timerTxt+="<div class='type'><img src='images/sub.png'></div>";
         		timerTxt+="<div class='persona'>"+txtArr[6]+"</div>";
         		timerTxt+="</div>";
         		timerTxt+="<div class='action period4'>";
         		timerTxt+="<div class='personh'></div>";
         		timerTxt+="<div class='type'></div>";	
         		timerTxt+="<div class='actiontime'>"+txtArr[9]+"</div>";
         		timerTxt+="<div class='type'><img src='images/yellow.png'></div>";
         		timerTxt+="<div class='persona'>"+txtArr[10]+"</div>";
         		timerTxt+="</div>";
         		timerTxt+=txtArr[11];
         		timerTxt+="<img src='images/samplestats.png'>";
         		timerTxt+=txtArr[20]+", "+txtArr[21]+", "+txtArr[22]+", "+txtArr[23];
         		sym.getSymbol("matchtracker").getSymbol("guide").$("txt2").append(timerTxt);
         		$('.action').css({'display':'inline-table','height':'20px','width':'100%','font-size':'12px','font-family':'pragmatica-web, sans-serif','text-align':'left','border-bottom':'solid 1px rgb(150,150,150)','border-top':'solid 1px rgba(255,255,255,0.6)'});
         		$(".period4").css({'background-color':'rgba(255,170,50,0.1)'});
         		$('.personh').css({'text-align':'right','display':'table-cell','width':'37%'});
         		$('.actiontime').css({'background-color':'rgba(100,100,100,0.6)','text-align':'center','display':'table-cell','width':'12%','color':'rgb(255,255,255)'});
         		$('.type').css({'display':'table-cell','width':'7%','text-align':'center'});
         		$('.persona').css({'text-align':'left','display':'table-cell','width':'37%'});
         		$(".action img").css({'width':'20px'});
         
         		sym.getSymbol("matchtracker").$("h2hTxt0").html(txtArr[24]);
         		sym.getSymbol("matchtracker").$("txt16").html(txtArr[17]);
         		sym.getSymbol("matchtracker").$("txt17").html(txtArr[17]);
         		sym.getSymbol("matchtracker").getSymbol("matchStats").$("txt18").html(txtArr[20]);
         		sym.getSymbol("fixtures").$("txt0").html(txtArr[33]);
         		sym.getSymbol("latest").$("txt0").html(menuTxtArr[0]);
         		var tableHeadCaps = $(xml).find('table0').text();
               tableCaps=tableHeadCaps.split(";");
               var tableHead = "<table style='width:55%; position:left; margin-left:45%; font-family:pragmatica-web, sans-serif; font-weight:700; border:none; border-collapse:collapse; font-size:12px; text-align:center'>";
         		tableHead += "<tr><td width='13%'><center id='tp'></center></td><td width='13%'><center id='tw'></center></td><td width='13%'><center id='td'></center></td><td width='13%'><center id='tl'></center></td><td width='17%'><center id='tf'></center></td><td width='17%'><center id='ta'></center></td><td width='14%'><center id='tpts'></td></tr>";
         		tableHead += "</table>";
               sym.getSymbol("latest").$("tableHead").append(tableHead);
               $("#tp").text(tableCaps[0]);
               $("#tw").text(tableCaps[1]);
               $("#td").text(tableCaps[2]);
               $("#tl").text(tableCaps[3]);
               $("#tf").text(tableCaps[4]);
               $("#ta").text(tableCaps[5]);
               $("#tpts").text(tableCaps[6]);
               var tooltipCaps = $(xml).find('table1').text();//tool tip for group table
         		sym.getSymbol("latest").$("tooltip0").html(tooltipCaps);
         		sym.getSymbol("latest").$("tooltip0").css({'background-color':'rgb(255,235,165)','border':'solid 1px rgb(0,0,0)','border-radius':'2px','display':'none'});
               var monthsArr = $(xml).find('months').text();
                  months=monthsArr.split(";");
               var keyArr = $(xml).find('key').text();
                  key=keyArr.split(";");
               var timeArr = $(xml).find('time').text();
                  timetxt=timeArr.split(";");
               sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[0]); 
               var teamLongArr= $(xml).find("teams").text();
               teamArr=teamLongArr.split(";");
               var teamShortNameArr= $(xml).find("teamShort").text();
               teamShortArr=teamShortNameArr.split(";");
               var iconTable="<table class='fixtable'>";
               iconTable+="<tr class='fixHead'><td class='fixName'></td>";
              	for (var c=0; c<teamArr.length; c++){
                  iconTable+="<td class='matchBox fixHead'>"+teamShortArr[c]+"<br/><img src='crests/"+teamIDs[c]+".png' id='teamBtn"+c+"'></td>";
                  var tableTxt="<table class='fixtable'>";
         			tableTxt+="<tr class='fixHead'><td class='fixName' id='fixName"+c+"'></td>";
         			for(var t=0;t<20; t++){
         				if(t==c){
         				tableTxt+="<td class='matchBox noMatch' id='m"+c+"_"+t+"'>";	
         				}else{
         					if((c%2==0&&t%2==0)||(c%2>0&&t%2>0)){
         						tableTxt+="<td class='matchBox green' id='m"+c+"_"+t+"'>";	
         					}else{
         						tableTxt+="<td class='matchBox white' id='m"+c+"_"+t+"'>";	
         					}	
         				}				
         			}
         			tableTxt+="</tr>";
         			tableTxt+="</table>";
         			sym.getSymbol("fixtures").$('table').append(tableTxt);
         			$("#fixName"+c).html(teamShortArr[c]);
               }
               iconTable+="</tr></table>";
               	sym.getSymbol("fixtures").$('teamBtns').append(iconTable);
         			$(".fixtable").css({'width':'100%','font-size':'11px', 'font-family':'pragmatica-web,sans-serif','border':'none','border-collapse':'collapse'});
         			$(".fixName").css({'width':'5%','padding-left':'4px'});
         			$(".matchBox").css({'width':'4.75%','font-size':'10px','text-align':'center'});
         			$(".noMatch").css({'background-color':'rgba(0,0,0,0.4)'});
         			$(".green").css({'background-color':'rgba(202,232,226,0.6)'});
         			$(".white").css({'background-color':'rgba(255,255,255,0.8)'});
         			$(".matchBox img").css({'width':'35px'});
         			$(".matchBox.fixHead").css({'font-weight':700})
         	},
         	complete:function(){//July 31
         		setTimeout(openMatch,400);
         	}
         });
         sym.getSymbol("latest").$("tipBtn0").on('click',showTip); //to show tool tip for group table
         var showtip=0;
         function showTip(){
         	if (showtip==0){
         		sym.getSymbol("latest").$("tooltip0").fadeIn(0);
         		showtip=1;
         	}else{
         		sym.getSymbol("latest").$("tooltip0").fadeOut(0);
         		showtip=0	
         	}
         }
         function rowColOver(e){
         	$(this).css({'background-color':'rgba(255,0,0,1.0)','color':'rgba(255,255,255,1.0)','font-weight':700,'font-size':'90%'});
         	var row = (e.data.row);
         	var col = (e.data.col);
         	for(var c=0;c<teamArr.length; c++){
         			if(row==teamIDs[c]){
         				var x=c;
         			}
         			if(col==teamIDs[c]){
         				var y=c;
         			}
         			for(var t=0;t<teamArr.length;t++){
         				$("#m"+x+"_"+t).addClass("view");
         				$("#m"+t+"_"+y).addClass("view");
         			}
         		}
         	$(".view").css({'background-color':'rgba(255,200,0,0.2)'});
         }
         function rowColOut(e){
         	$(this).css({'background-color':'rgba(255,255,255,0)','color':'rgba(0,0,0,1.0)','font-weight':400,'font-size':'100%'});
         	var row = (e.data.row);
         	var col = (e.data.col);
         	for(var c=0;c<teamArr.length; c++){
         		if(row==teamIDs[c]){
         				var x=c;
         		}
         		if(col==teamIDs[c]){
         				var y=c;
         		}
         		for(var t=0;t<teamArr.length;t++){
         			$("#m"+x+"_"+t).removeClass("view");
         			$("#m"+t+"_"+y).removeClass("view");
         		}
         	}		
         	$(".green").css({'background-color':'rgba(202,232,226,0.6)'});
         	$(".white").css({'background-color':'rgba(255,255,255,0.8)'});
         	$(".noMatch").css({'background-color':'rgba(0,0,0,0.4)'});
         }
         // MENU BUTTONS --------------------------------------------	
                  menuArray = []; //the array that will hold references to the buttons.
                  for (var m = 0; m < 2; m++){
                  		var menuBtnSymbols = sym.getSymbol("menuBtns").getSymbol("menuBtn" +m); // Create an instance element of a symbol as a child of the given parent element
                  		menuBtnSymbols.setVariable("menuId", m); //set the value of a Symbol variable
                  		menuArray.push(menuBtnSymbols); //push it into the array
                  	}
                  $.each(menuArray, function( count, menuInTheArray ){ //a 'for each' loop through the newly populated array
                  		var menuBtnItem = $(menuInTheArray); //create jQuery reference to the item
                  		var menuBtnElement = menuInTheArray.getSymbolElement(); //create a jQuery reference to the DIV element inside the symbol
                  		menuBtnElement.on ("click", {menuId:count}, menuBtnClick);
                  		menuBtnElement.on ("touchstart click", {menuId:count}, menuBtnClick);
                  		menuBtnElement.on ("mouseover", {menuId:count}, menuShow);
                  		menuBtnElement.on ("mouseout", {menuId:count}, menuHide);
                  		menuBtnElement.css({"cursor":"pointer"});
                  })
                  function resetmenu(){
                  		for (var m=0; m<menuArray.length; m++){	
                           menuArray[m].$("menuBg").fadeOut(0);
                  		}
                  		menuTxt.fadeOut(0);
                  }
                  resetmenu();
                  function menuBtnClick (e){
                  		e.preventDefault();
                  		e.stopPropagation();
                  		resetmenu(); //set them all back to normal state
                  		sym.$("latest").animate({opacity:1.0},0);//July 31
                  		clearInterval(matchInterval);
         					clearInterval(playInterval);
                  		var menuMenu_id = (e.data.menuId); //get the id of the clicked item
         					for (var i=0;i<5;i++){
         						if (menuMenu_id==i){
         							sym.$(screenArr[i]).fadeIn(400);
         							sym.getSymbol("menuBtns").getSymbol("menuBtn" + i).$("menuBg").fadeIn(0);
         							menuTxt.html(menuTxtArr[i]);
         							menuTxt.fadeIn(0);
         							if(menuMenu_id==0){
         								getTeamFixtures();
         								clearInterval(fixtureInterval);
         								fixtureInterval = setInterval(getTeamFixtures,600000);
         							}
         						}else{
         							sym.$(screenArr[i]).fadeOut(400);
         						}						 
         					}
                  }
                  function menuShow (e){
                  		var menuMenu_id = (e.data.menuId); //get the id of the over button
                  		//sym.$('handMc').hide();
                  		menuTxt.html(menuTxtArr[menuMenu_id]);
         					menuTxt.fadeIn(0);
                  }
                  function menuHide (e){
                  		var menuMenu_id = (e.data.menuId); //get the id of the out button
                  		menuTxt.fadeOut(0);
                  }
         sym.getSymbol("menuBtns").getSymbol("menuBtn0").$("menuBg").fadeIn(0);			
         sym.getSymbol("matchtracker").$("statsBtn").on('click',matchStats);
         sym.getSymbol("matchtracker").$("statsBtn").on('mouseover',statsOver);
         sym.getSymbol("matchtracker").$("statsBtn").on('mouseout',statsOut);
         sym.getSymbol("matchtracker").$("statsBtn").css({'cursor':'pointer'});
         var showStats=0;
         sym.getSymbol("matchtracker").$("statTxt").fadeOut(0);
         sym.getSymbol("matchtracker").$("statsBtn").fadeIn(0);
         function matchStats(){
         	if (showStats==0){
         		sym.getSymbol("matchtracker").$("timer").animate({'width':0,'left':'397px','opacity':0},200);
         		sym.getSymbol("matchtracker").$("statsBtn").attr('src','images/clockbtn.png');
         		sym.getSymbol("matchtracker").$("statTxt").html(txtArr[31]);
         		sym.getSymbol("matchtracker").$("statTxt").fadeIn(0);
         		showStats=1;
         	}else{
         		sym.getSymbol("matchtracker").$("timer").animate({'width':391,'left':'201px','opacity':1.0},200);
         		sym.getSymbol("matchtracker").$("statsBtn").attr('src','images/stats.png');
         		sym.getSymbol("matchtracker").$("statTxt").html(txtArr[32]);	
         		sym.getSymbol("matchtracker").$("statTxt").fadeIn(0);
         		showStats=0	
         	}
         }
         function statsOver(){
         	if (showStats==0){
         		sym.getSymbol("matchtracker").$("statTxt").html(txtArr[32]);
         		sym.getSymbol("matchtracker").$("statTxt").fadeIn(0);
         	}else{
         		sym.getSymbol("matchtracker").$("statTxt").html(txtArr[31]);		
         		sym.getSymbol("matchtracker").$("statTxt").fadeIn(0);
         	}
         }
         function statsOut(){
         		sym.getSymbol("matchtracker").$("statTxt").fadeOut(0);
         }
         var showguide=0;
         function showGuide(){
         	if(showguide==0){
         		sym.getSymbol("matchtracker").$("guide").fadeIn(600);
         		showguide=1;
         	}else{
         		sym.getSymbol("matchtracker").$("guide").fadeOut(600);
         		showguide=0;
         	}
         }
         sym.getSymbol("menuBtns").$("timezone").on("click",function(){
         		if(showLocal==0){ showLocal=1; getTeamFixtures(teamSelect); }else{ showLocal=0;getTeamFixtures(teamSelect); } sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[showLocal]); });
         sym.getSymbol("menuBtns").$("timezone").on("mouseover",function(){ 
         	if (showLocal==0){  sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[1]);  }else{  sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[0]);  }});
         sym.getSymbol("menuBtns").$("timezone").on("mouseout",function(){ 
         	if (showLocal==0){  sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[0]);  }else{  sym.getSymbol("menuBtns").$("timezoneTxt").html(timetxt[1]);  }});
         sym.getSymbol("menuBtns").$("timezone").css({'cursor':'pointer'});	
         //DATE FUNCTIONS --------------------------------------------
         function getDDMMYY(thisDateStr) {
                     var dateTxt = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
                     //var thisDate = new Date(parseInt(dateTxt, 10));
                     var thisDate = new Date(parseInt(dateTxt, 10)+oneDay);
                     var mm = thisDate.getMonth() + 1;
                     var dd = thisDate.getDate();
                     mm = ((mm < 10) ? '0' : "") + mm;
                     dd = ((dd < 10) ? '0' : "") + dd;
                     return dd + "/" + mm + "/" + (thisDate.getFullYear()).toString();
                 }
         function getDDmonthYY(thisDateStr) {
         	var dateTxt = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
         	var thisDate = new Date(parseInt(dateTxt, 10));
         	var matchDate=thisDate.getTime() +localOffset;
         	var matchTime=new Date(matchDate);
         	var mm = matchTime.getMonth();
         	var dd = matchTime.getDate();
         	if (dateFormat=="dayMonth"){ //allows different date formats
         		return dd.toString() +months[mm];
         	}else{
         		return months[mm] + " " + dd.toString();
         	}
         } 
         function getDateLocal(thisDateStr) {
         	var dateTxt = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
         	var thisDate = new Date(parseInt(dateTxt, 10));
         	var mm = thisDate.getMonth();
         	var dd = thisDate.getDate();
         	//return months[mm] + " " + dd +", "+ (thisDate.getFullYear()).toString();
         	if (dateFormat=="dayMonth"){ //allows different date formats
         		return dd.toString() +months[mm];
         	}else{
         		return months[mm] + " " + dd.toString();
         	}
         }
         function getMatchTime(thisDateStr,braziltime){
         	var timeTxt = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
         	var thisDate = new Date(parseInt(timeTxt, 10));
         	var thisTime = thisDate.getTime()+localOffset-braziltime;//localOffset to UTC - offset to Brazil
         	var matchTime = new Date(thisTime);
         	var hh = matchTime.getHours();
         	var mm = parseInt(matchTime.getMinutes(),10);
         	mm=(mm<10)?"0"+mm:mm;
         	return hh+":"+mm;
         	//return hh+":00";	
         }
         function getMatchLocal(thisDateStr){
         	var timeTxt = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
         	var thisDate = new Date(parseInt(timeTxt, 10));
         	var hh = thisDate.getHours();
         	var mm = parseInt(thisDate.getMinutes(),10);
         	mm=(mm<10)?"0"+mm:mm;
         	return hh+":"+mm;
         }
         function parsedDate(thisDateStr){
         	var matchRndDate = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf(')'));
         	//var dDate = parseInt(matchRndDate,10);
         	var dDate = parseInt(matchRndDate,10)+localOffset;
         	return dDate;
         } 
         var offsetBrazil;//Offset between time at venue and UTC
         function getDST(thisDateStr){
         	var thisDate = thisDateStr.substring(thisDateStr.indexOf('(') + 1, thisDateStr.indexOf('+'));
         	if(thisDate<gmtStart||thisDate>gmtEnd){
         		var offsetUTC = -3600000;
         	}else{
         		var offsetUTC = 0;
         	}
         	return offsetUTC;
         }
         //LIVE DATA --------------------------------------
                  function getTable() {           
                   var tableData;
                   $.ajax({ type: "GET", url: dataURL,
                                  data: "gn="+gn+"&phaseID=109331&yr=2014",
                                  contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                                  async: true,
                                  crossDomain: true,
                                  success: function (data) {
                                      tableData = data;
                                      for (var i = 0; i < tableData.length; i++) {
                                     		if (i==0){
                  		sym.getSymbol('latest').$("pltable").empty();
                  		//sym.getSymbol('panel01').$('topteam').attr('src','crests/'+tableData[0].n_TeamID+'.png');
                  		}			
         							var tableTxt = "<table class='pltable'>";
                  				if (i==0){
                  				tableTxt += "<tr class='first'>";//first place
                  				}else if (i< 5){
                  				tableTxt += "<tr class='euq'>";//cl and el qualifier
                  				}else if (i>16){
                  				tableTxt += "<tr class='releg'>";//relagation places
                  				}else{
                  				tableTxt += "<tr class='mid'>";
                  				}
                  				tableTxt +="<td class='rank' id='rank" + i + "'></td>";
                  				tableTxt +="<td class='team' id='team" + i + "'></td>";
                  				tableTxt +="<td class='play' id='p" + i + "'></td>";
                  				tableTxt +="<td class='won' id ='w" + i + "'></td>";
                  				tableTxt +="<td class='draw' id ='d" + i + "'></td>";
                  				tableTxt +="<td class='lost' id ='l" + i + "'></td>";
                  				tableTxt +="<td class='for' id ='f" + i + "'></td>";
                  				tableTxt +="<td class='against' id ='a" + i + "'></td>";
                  				tableTxt +="<td class='pts' id ='pts" + i + "'></td>";
                  				tableTxt +="</tr></table>";
         			sym.getSymbol('latest').$("pltable").append(tableTxt);
         			$('#team' + i).text(tableData[i].c_Team);
         			$('#rank' + i).text(i+1);
         			$('#p' + i).text(tableData[i].n_Matches);
         			$('#w' + i).text(tableData[i].n_MatchesWon);
         			$('#d' + i).text(tableData[i].n_MatchesDrawn);
         			$('#l' + i).text(tableData[i].n_MatchesLost);
         			$('#f' + i).text(tableData[i].n_GoalsFor);
         			$('#a' + i).text(tableData[i].n_GoalsAgainst);
         			$('#pts' + i).text(tableData[i].n_Points);
         			$('.pltable').css({'width':'100%','font-size':'13px','font-family':'pragmatica-web,sans-serif','border-collapse':'collapse','border-top':'solid 1px rgba(100,100,100,0.5)','border-bottom':'solid 1px rgba(255,255,255,1.0)'});
         			$('.rank').css({'width':'5%'});
         			$('.team').css({'width':'40%'});
         			$('.play').css({'width':'7%','text-align':'center'});
         			$('.won').css({'width':'7%','text-align':'center'});
         			$('.draw').css({'width':'7%','text-align':'center'});
         			$('.lost').css({'width':'7%','text-align':'center'});
         			$('.for').css({'width':'10%','text-align':'center'});
         			$('.against').css({'width':'10%','text-align':'center'});
         			$('.pts').css({'width':'7%','text-align':'right','font-weight':700});
         			$('tr.first').css({'background-color':'rgba(245,230,140,0.5)'});
                  $('tr:odd.euq').css({'background-color':'rgba(230,230,190,0.5)'});
                  $('tr:even.euq').css({'background-color':'rgba(250,250,220,0.5)'});
         			$('tr:even.releg').css({'background-color':'rgba(255,190,160,0.5)'});
         			$('tr:odd.releg').css({'background-color':'rgba(255,220,205,0.5)'});
         			$('tr:even.mid').css({'background-color':'rgba(215,230,245,0.5)'});
         			$("#teamBtn"+i).on("click",showTeam(teamIDs[i]));//team buttons on fixture table
         			$("#teamBtn"+i).css({'cursor':'pointer'});
         			} 
         		}
         	});
         }
         var fixtureData;
         function getTeamFixtures(teamID){
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&editionID=21183",
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			sym.getSymbol("team").$("table").empty();
         			sym.getSymbol("latest").$('table').empty();
         			fixtureData = data;
         			var teamHome;var teamAway;
         			for (var i = 0; i < fixtureData.length; i++) {				
         				//var matchesRnd = parsedDate(fixtureData[i].d_DateUTC);
         								var matchesRnd = (fixtureData[i].d_DateUTC!=null)?parsedDate(fixtureData[i].d_DateUTC):endWC;//Jan 28
         				var matchDay = fixtureData[i].n_PhaseID;
         				var phaseLevel = fixtureData[i].n_PhaseLevel;
         				var matchNo = fixtureData[i].n_MatchNr;
         				var city=fixtureData[i].c_City
         				var stad=fixtureData[i].c_Stadium
         				//var matchDate = getDDmonthYY(fixtureData[i].d_DateUTC);
         					var matchDate = (fixtureData[i].d_DateUTC!=null)?getDDmonthYY(fixtureData[i].d_DateUTC):"TBC";//Jan 28
         				//var offsetBrazil = getDST(fixtureData[i].d_DateUTC);
         								var offsetBrazil = (fixtureData[i].d_DateUTC!=null)?getDST(fixtureData[i].d_DateUTC):"TBC";//jan 28
         				var matchID = fixtureData[i].n_MatchID;
         				var homeTeamID=fixtureData[i].n_HomeTeamID;
         				var awayTeamID=fixtureData[i].n_AwayTeamID;
         				if (fixtureData[i].d_DateUTC!=null){//Jan 28
         					if(showLocal==0){
         						var matchTime = getDDmonthYY(fixtureData[i].d_DateUTC)+", "+getMatchTime(fixtureData[i].d_Date,offsetBrazil);
         					}else{
         						var matchTime = getDateLocal(fixtureData[i].d_Date)+", "+getMatchLocal(fixtureData[i].d_Date);
         					}
         				}else{
         					var matchTime = "TBC";//Jan 28
         				}
         				var matchddmm= (fixtureData[i].d_Date!=null)?getDDMMYY(fixtureData[i].d_Date):"TBC";//Jan 28
         				for(var c=0;c<20;c++){
         					if (fixtureData[i].n_HomeTeamID>0){
         						if (fixtureData[i].n_HomeTeamID==teamIDs[c]){
         							teamHome=teamArr[c];
         						}
         					}else{
         						teamHome=fixtureData[i].c_HomeTeam;
         					}
         					if (fixtureData[i].n_AwayTeamID>0){
         						if (fixtureData[i].n_AwayTeamID==teamIDs[c]){
         							teamAway=teamArr[c];
         						}
         					}else{
         						teamAway=fixtureData[i].c_AwayTeam;
         					}
         				}
         				if (i%2 == 0){
         					var fixtureTxt = "<table class='fixtxt even' id='matchf" + i + "'>";
         				}else{
         					var fixtureTxt = "<table class='fixtxt' id='matchf" + i + "'>";
         				}
         				fixtureTxt += "<tr>";
         				fixtureTxt += "<td class='crestf' style='crest' id='homecrestf" + i + "'></td>";
         				fixtureTxt += "<td class='teamf' style='padding-left:3px' id='homef" + i + "'></td>";
         				fixtureTxt += "<td style='width:32%;text-align:center' id='scoref" + i + "'></td>";
         				fixtureTxt += "<td class='teamf away' style='text-align:right' id ='awayf" + i + "'></td>";
         				fixtureTxt += "<td class='crestf away' id='awaycrestf" + i + "'></td>";
         				fixtureTxt += "</tr></table>";
         				if (typeof teamID!="undefined"){//get team fixtures
         					if (fixtureData[i].n_HomeTeamID==teamID||fixtureData[i].n_AwayTeamID==teamID){
         						sym.getSymbol("team").$("table").append(fixtureTxt);
         					}
         				}else{//get all fixtures
         					//SHOW LATEST MATCHES ONLY
         					if ((todayTime<startWC&&i<10)||(todayTime>endWC&&i>fixtureData.length-10)||(matchesRnd>todayTime-(oneDay*2)&&matchesRnd<todayTime+(oneDay*15))){
         						sym.getSymbol("latest").$('table').append(fixtureTxt);
         					}//closes if parsedate
                  	}
                  	var fixtBox = "<div id='match"+i+"'></div>";
         				for (var t=0; t<20;t++){
         					if (homeTeamID==teamIDs[t]){
         						for (var c=0;c<20;c++){
         							if(awayTeamID==teamIDs[c]){
         								$("#m"+c+"_"+t).html(fixtBox);
         							}
         						}
         					}
         				}
         				$('.even').css({'background-color':'rgba(215,230,245,0.5)'});
         				$('.fixtxt').css({'font-size':'12px', 'font-family':'pragmatica-web,sans-serif', 'width':'100%'});
         				$('.teamf').css({'width':'27%','font-weight':700});
         				$(".crestf").css({'width':'7%'});
         				$(".away").css({'text-align':'right'});
         				var crestH = ((fixtureData[i].n_HomeTeamID)<=0)?'<img src="crests/null.png">':'<img src="crests/'+ fixtureData[i].n_HomeTeamID +'.png">';
         				var crestA = ((fixtureData[i].n_HomeTeamID)<=0)?'<img src="crests/null.png">':'<img src="crests/'+ fixtureData[i].n_AwayTeamID +'.png">';
         				$('#homecrestf' + i).html(crestH);
         				$('#awaycrestf' + i).html(crestA);
         				$(".crestf img").css({'border':'none','width':'35px','height':'35px'});
         				$('.match').css({'margin-left':'2px','cursor':'pointer','height':'32px','font-size':'12px', 'font-family':'pragmatica-web,sans-serif','border-collapse':'collapse', 'width':'100%'});
         				$("#match"+i).on('click',showMatch(matchID));
         				$("#match"+i).on('mouseover',{'row':awayTeamID,'col':homeTeamID},rowColOver);
         				$("#match"+i).on('mouseout',{'row':awayTeamID,'col':homeTeamID},rowColOut);
         				$("#match"+i).css({'cursor':'pointer'});
         				$("#matchf"+i).css({'cursor':'pointer'});
         				$("#matchf"+i).on('click',showMatch(matchID));
         				$("#matchf"+i).on('mouseover',function(){ $(this).css({'background-color':'rgba(220,155,0,0.2)','font-weight':700});});
         				$("#matchf"+i).on('mouseout',function(){ 
         					if(this.className=="fixtxt even"){ 
         						$(this).css({'background-color':'rgba(215,230,245,0.5)','font-weight':400});
         					}else{
         						$(this).css({'background-color':'rgba(255,255,255,0)','font-weight':400});
         					}
         				});
         				$('#homef' + i).text(teamHome);
         				$('#awayf' + i).text(teamAway);
         				var score =(fixtureData[i].n_HomeGoals!=null||fixtureData[i].n_HomeGoals!=undefined)?'<b>' + (fixtureData[i].n_HomeGoals)+ '-' + (fixtureData[i].n_AwayGoals)+'</b>':matchDate;
         				var scoref =(fixtureData[i].n_HomeGoals!=null||fixtureData[i].n_HomeGoals!=undefined)?'<b>' + (fixtureData[i].n_HomeGoals)+ '-' + (fixtureData[i].n_AwayGoals)+'</b>':'<i>'+matchTime+'</i>';//June 17
         				$("#match"+i).html(score);
         				$('#scoref' + i).html(scoref+"<br/><i>"+stad+"</i>");
         			}//end for
         		}//end success
         	});
         }
         
         getTable();
         getTeamFixtures();
         if(todayTime>startWC-(oneDay*3)&&todayTime<endWC+(oneDay*3)){
         	groupInterval = setInterval(getTable,600000);
         	fixtureInterval = setInterval(getTeamFixtures,600000);
         }
         // LIVE MATCH 			
         function getMatchInfo(matchID){
         	var infoData;
         	sym.getSymbol("matchtracker").$("penaltiesTxt").fadeOut(0);
         	sym.getSymbol("matchtracker").$("statsBtn").off('click',showGuide);
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&match="+matchID+"&q=info",
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			infoData = data;
         			var matchteam1;
         			var matchteam2;
         			getTeams(matchID,infoData[0].n_HomeTeamID,infoData[0].n_AwayTeamID);
         			for(var c=0;c<20;c++){
         				if (infoData[0].n_HomeTeamID>0){
         					if (infoData[0].n_HomeTeamID==teamIDs[c]){
         						matchteam1=teamArr[c];
         					}
         				}else{
         					matchteam1=infoData[0].c_HomeTeamShort;
         				}
         				if (infoData[0].n_AwayTeamID>0){
         					if (infoData[0].n_AwayTeamID==teamIDs[c]){
         						matchteam2=teamArr[c];
         					}
         				}else{
         					matchteam2=infoData[0].c_AwayTeamShort;
         				}
         			}
         			var score1;
         			var score2;
         			var notStarted=['h2hmatch','h2h','h2hgoals'];
         			var showStarted=['matchStats','timer','timeTxt','clock'];
         			if(infoData[0].b_Started==false){
         				score1="0";
         				score2="0";
         				for(var n=0;n<notStarted.length;n++){
         					sym.getSymbol("matchtracker").$(notStarted[n]).fadeIn(600);
         				}
         				for(var m=0;m<showStarted.length;m++){
         					sym.getSymbol("matchtracker").$(showStarted[m]).fadeOut(0);
         				}
         				clearInterval(playInterval);
         				sym.getSymbol("matchtracker").$("statsBtn").on('click',showGuide);
         				getH2H(matchID);	
         			}else{
         				if(infoData[0].b_Live==true){
         					clearInterval(matchInterval);
         					clearInterval(playInterval);
         					matchInterval = setInterval(function() { getMatchInfo(matchID); }, 60000);
         					playInterval = setInterval(function() { getMatch(matchID); }, 60000);
         				}
         				score1=infoData[0].n_HomeGoals;
         				score2=infoData[0].n_AwayGoals;
         				for(var n=0;n<notStarted.length;n++){
         					sym.getSymbol("matchtracker").$(notStarted[n]).fadeOut(0);
         				}
         				for(var m=0;m<showStarted.length;m++){
         					sym.getSymbol("matchtracker").$(showStarted[m]).fadeIn(600);
         				}
         				getmatchStats(matchID);
         				sym.getSymbol("matchtracker").$("statsBtn").off('click',showGuide);
         			}
         			//var offsetBrazil = 0;
         			var offsetBrazil = (infoData[0].d_DateUTC!=null)?getDST(infoData[0].d_DateUTC):"TBC";//Jan 28
         			if(infoData[0].b_Finished==true){
         				clearInterval(matchInterval);
         				matchInterval = setInterval(function() { getMatchInfo(matchID); }, 300000);
         				clearInterval(playInterval);
         				var matchTime = (infoData[0].d_DateUTC)?getDDmonthYY(infoData[0].d_DateUTC):"TBC";//Jan 28
         			}else{
         				if(infoData[0].d_DateUTC!=null){//Jan 28
         					if(showLocal==0){
         						var matchTime = getMatchTime(infoData[0].d_Date,offsetBrazil)+" "+getDDmonthYY(infoData[0].d_DateUTC);
         					}else{
         						var matchTime = getMatchLocal(infoData[0].d_Date)+" "+getDateLocal(infoData[0].d_Date);
         					}
         				}else{
         					var matchTime = "TBC";//Jan 28
         				}
         			}
         			var matchRef=(infoData[0].c_Referee==null)?"":txtArr[18] + infoData[0].c_Referee + " <i>" + infoData[0].c_RefereeNatioShort+"</i>";
         			var spectators=(infoData[0].n_Spectators==null)?"":txtArr[19] + infoData[0].n_Spectators;
         			var matchscore = score1 + "-" + score2;
         			var imgH = "crests/"+ infoData[0].n_HomeTeamID + ".png";
         			var imgA = "crests/"+ infoData[0].n_AwayTeamID + ".png";
         			var matchStatus = infoData[0].n_MatchStatusCode;
         			var tacticsH =(infoData[0].c_HomeTactics==null)?"":infoData[0].c_HomeTactics;
         			var tacticsA = (infoData[0].c_AwayTactics==null)?"":infoData[0].c_AwayTactics;
         			var matchDate = (infoData[0].d_DateUTC)?getDDmonthYY(infoData[0].d_DateUTC):"TBC";
         			//var matchInfo = infoData[0].c_Stadium + ", " + infoData[0].c_City + "<br />" + matchDate + ", 2014<br />" + matchRef + "<br />" + spectators ;
         			var matchInfo = infoData[0].c_Stadium + ", " + infoData[0].c_City + "<br />" + matchTime + "<br />" + matchRef + "<br />" + spectators ;//Jan 28
         			sym.getSymbol("matchtracker").$("matchcrest1").attr("src",imgH);				
         			sym.getSymbol("matchtracker").$("matchcrest2").attr("src",imgA);				
         			sym.getSymbol("matchtracker").$("matchteam1Txt").text(matchteam1);
         			sym.getSymbol("matchtracker").$("matchteam2Txt").text(matchteam2);
         			sym.getSymbol("matchtracker").$("matchscoreTxt").text(matchscore);
         			sym.getSymbol("matchtracker").$("matchinfoTxt").html(matchInfo);
         			//matchStatus 8 (in progress), 128 (finished)
         			//PENALTY SHOOTOUT ONLY
         			if (infoData[0].n_PeriodSort>=10&&infoData[0].n_HomeGoalsShootout!=null){
         				//if (lastPeriod==10){	
         				var pensH=(infoData[0].n_HomeGoalsShootout>=0)?infoData[0].n_HomeGoalsShootout:"";
         				var pensA=(infoData[0].n_AwayGoalsShootout>=0)?infoData[0].n_AwayGoalsShootout:"";
         				var penalties= txtArr[30]+" (" +pensH+ "-" +pensA+ ")";
         				if (infoData[0].n_HomeGoalsShootout>=0||infoData[0].n_AwayGoalsShootout>=0){
         						sym.getSymbol("matchtracker").$("penaltiesTxt").html(penalties);
         						sym.getSymbol("matchtracker").$("penaltiesTxt").fadeIn(0);
         					}
         			}	               							
         		}
         	});
         }
         
         var matchData;
         var lastAction;
         var lastTime;
         var lastPeriod;
         function getMatch(matchID) { 
         	var minutes = sym.getSymbol("matchtracker").$("timeTxt");
         	minutes.text("0"); 
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&match="+matchID,
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			matchData = data;
         				if(matchData){
         					lastAction = matchData[0].n_ActionTime;
         					lastPeriod = matchData[0].n_PeriodSort;
         					var lastTimetxt;
         					var minutes = sym.getSymbol("matchtracker").$("timeTxt");
         					sym.getSymbol("matchtracker").$("timer").empty();
         					//create display for each action	
         					var actionTxt;
         					var penTxt;
         					var HorA;
         					var actionSet;
         					var actionType;
         					var action;
         					var actionTime;
         					var actionMs;
         					var actionPeriod;
         					var keyTxt="<div class='action'>";
         					keyTxt+="<div class='key'><img src='images/goal.png' style='width:15px'> "+key[0]+"</div>";
         					keyTxt+="<div class='key'>"+"<img src='images/pen.png' style='width:15px'> "+key[1]+"</div>";
         					keyTxt+="<div class='key'>"+"<img src='images/sub.png' style='width:15px'> "+key[2]+"</div>";
         					keyTxt+="<div class='key'>"+"<img src='images/yellow.png' style='width:15px'> "+key[3]+"</div>";
         					keyTxt+="</div>";
         					sym.getSymbol("matchtracker").$("timer").append(keyTxt)
         					for (var i = 0; i <= matchData.length; i++) {
         						if (matchData[i].n_ActionTime>lastAction){
         							lastAction=matchData[i].n_ActionTime;
         						}
         						if (matchData[i].n_PeriodSort>lastPeriod){
         							lastPeriod=matchData[i].n_PeriodSort;
         						}         		        
         						actionSet = matchData[i].n_ActionSet;
         						actionType = matchData[i].n_ActionCode;
         						actionTime = (matchData[i].c_ActionMinute==null)?"":matchData[i].c_ActionMinute;
         						var HorA = (matchData[i].n_HomeOrAway==1)?"h":"a";
         						if (actionSet==1||actionSet==2||actionSet==3||actionSet==5){
         							actionMs = matchData[i].n_ActionTime;
         							actionPeriod = matchData[i].n_PeriodSort;
         							var actionTxt="<div class='action period"+actionPeriod+"' id=action"+i+"'>";//style by period
         							actionTxt+="<div class='personh' id='person"+i+"h'></div>";
         							actionTxt+="<div class='type' id='type"+i+"h'></div>";	
         							actionTxt+="<div class='actiontime' id='actionMins"+i+"'></div>";
         							actionTxt+="<div class='type' id='type"+i+"a'></div>";
         							actionTxt+="<div class='persona' id='person"+i+"a'></div>";
         							actionTxt+="</div>";
         							//then append each action (latest at top)
         							sym.getSymbol("matchtracker").$("timer").prepend(actionTxt);
         							var player=matchData[i].c_PersonShort;     
         							if (matchData[i].n_ActionSet==5){
         								var sub=" (" + matchData[i].c_SubPersonShort + ")";
         							}else{
         								var sub="";
         							}
         							$('#person' + i + HorA).text(player+sub);
         							//$('#actionMins' + i).text(matchData[i].c_ActionMinute);
         							$('#actionMins' + i).text(actionTime);
         							//create icons for each action
         							switch (actionSet){
         								case 1:
         								if(actionType==12){
         									action= "pen";
         								}else{
         									action= "goal";
         								}
         								break;
         								case 2:
         								if (actionType==12){
         									action="pen";
         								}else{
         									action="miss";
         								}
         								break;
         								case 3:
         								if (actionType==2048){
         									action="yellow";
         								}else{
         									action="red";
         								}
         								break;
         								case 5:
         								action="sub";
         								break;
         							}
         							var imgHTML="<img src='images/"+action +".png' height='20px' width='20px'>";
         							$('#type' + i + HorA).html(imgHTML);
         							$('.key').css({'display':'table-cell','font-style':'italic','padding-left':'5px'});
         							$('.action').css({'display':'inline-table','height':'20px','width':'100%','font-size':'12px','font-family':'pragmatica-web, sans-serif','text-align':'left','border-bottom':'solid 1px rgb(150,150,150)','border-top':'solid 1px rgba(255,255,255,0.6)'});
         							$(".period4").css({'background-color':'rgba(255,170,50,0.1)'});
         							$(".period6, .period8").css({'background-color':'rgba(255,0,0,0.1)'});
         							$(".period10").css({'background-color':'rgba(255,40,0,0.3)'});
         							$('.personh').css({'text-align':'right','display':'table-cell','width':'37%'});
         							$('.actiontime').css({'background-color':'rgba(100,100,100,0.6)','text-align':'center','display':'table-cell','width':'12%','color':'rgb(255,255,255)'});
         							$('.type').css({'display':'table-cell','width':'7%','text-align':'center'});
         							$('.persona').css({'text-align':'left','display':'table-cell','width':'37%'});
                  			} //close if
         						if (lastAction>7200000){					//if after 120 mins but before penalties
         							lastTime=7200000;
         						}else if ((lastAction>6300000)&&(lastPeriod<7)){					//if after 105 mins but before second period
         							lastTime=6300000;
         						}else if ((lastAction>5400000)&&(lastPeriod==11)){					//if after 90 mins match has finished
         							lastTime=5400000;
         						}else if ((lastAction>5400000)&&(lastPeriod<5)){					//if after 90 mins but before extra time
         							lastTime=5400000;
         						}else if((lastAction>2700000)&&(lastPeriod<4)){ 		// if match is in 1st half but > 45 mins
         							lastTime=2700000;
         						}else{
         							lastTime=lastAction;
         						}
         						//display latest time
         						if (lastPeriod==11){
         							lastTimetxt=Math.round(lastTime/60000);
         						}else if (lastPeriod<9){ //before penalty shootout
         							if(lastAction > 0){	
         								lastTimetxt=Math.round(lastAction/60000);
         							}
         						}else{
         							lastTimetxt="120";
         						}
                  			minutes.text(lastTimetxt); //SHOW LATEST TIME
         					} //close for 
         					if (lastPeriod>5){ //extra time draw line at ht/ft
         					}
         				}
         		},//close success 
         		error: function(){ 
         			console.log("Match not started");
         		}  	                                                  	           
         	}); //close ajax
         }
         function getTeams(matchID,home,away) {           
                  	sym.getSymbol("matchtracker").$("matchSquadh").empty(); //PASS teamIDs to teamInterval
                  	sym.getSymbol("matchtracker").$("matchSquada").empty();
                     var teamData;
                  	$.ajax({ type: "GET", url: dataURL,
                  		data: "gn="+gn+"&yr="+gnYear+"&q=teams&match="+matchID,
                  		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                  		async: true,
                  		crossDomain: true,
                  		success: function (data) {
                  			teamData = data;
                  			if (!teamData){
         							getSquad(home,"home");
         							getSquad(away,"away");
         							sym.getSymbol("matchtracker").$("txt16").html(txtArr[17]);
         							sym.getSymbol("matchtracker").$("txt17").html(txtArr[17]);
                  			}else{
         							var coach;
         							var teamlist;
         							var team;
         							var hORa;
         							sym.getSymbol("matchtracker").$("txt16").html(txtArr[16]);
         							sym.getSymbol("matchtracker").$("txt17").html(txtArr[16]);
         							sym.getSymbol("matchtracker").$("preloaderh").fadeOut(0);
         							sym.getSymbol("matchtracker").$("preloadera").fadeOut(0);
         							for (var i = 0; i < teamData.length; i++) {		
         								if (teamData[i].n_HomeOrAway==1){
         									teamlist = "matchSquadh";
         									hORa='h';
         								}else if (teamData[i].n_HomeOrAway==-1){
         									teamlist = "matchSquada";
         									hORa='a';
         								}
         								if (teamData[i].n_ActionSet<8){
         									if (teamData[i].n_ActionSet==4){
         										var lineupTxt = "<div class='lineup' id='lineup" + i + "'>";
         									} else if (teamData[i].n_ActionSet==5||teamData[i].n_ActionSet==6){
         										var lineupTxt = "<div class='substitute' id='lineup" + i + "'>";
         									}	
         										lineupTxt += "<div class='shirtNr' id='teamShirt" + i + "'></div>";
         										lineupTxt += "<div class='playerNm' id='teamPerson" + i + "'></div>";
         										lineupTxt += "</div>";
         										sym.getSymbol("matchtracker").$("matchSquad"+hORa).append(lineupTxt);
         								}
         								if (teamData[i].n_FunctionType==16){
         									coach = "<div style='padding-left:3px'><b>" + teamData[i].c_Person + "</b> <span style='text-align:right; font-style:oblique; font-size:12px'>" + teamData[i].c_PersonNatioShort + "</span></div>";
         									sym.getSymbol("matchtracker").$("matchSquad"+hORa).prepend(coach);
         								}
         								sym.getSymbol("matchtracker").$("matchSquad"+hORa).css({'font-family':'pragmatica-web,sans-serif','font-size':'13px'}); 
         								$('.lineup').css({'width':'100%','display':'inline-table'});
         								$('.substitute').css({'width':'100%','display':'inline-table','font-style':'oblique'});
         								$('.shirtNr').css({'width':'10%','display':'table-cell','text-align':'left','padding-left':'3px'});  
         								$('.playerNm').css({'width':'90%','display':'table-cell','text-align':'left','padding-left':'5px'});                        
         								var actionMins;	                
         								if (teamData[i].c_ActionMinute==null){
         									actionMins="";
         								}else{
         									actionMins=" ("+ teamData[i].c_ActionMinute + ")";
         								}			
         								$('#teamShirt' + i).text(teamData[i].n_ShirtNr);
         								$('#teamPerson' + i).html(teamData[i].c_Person + actionMins);
         								$('#subPerson' + i).text(teamData[i].c_SubPersonShort);
         								var posn = teamData[i].n_Position;			
         							}
         						}
         
                  		}
                  	});
         }
         function getSquad(team,homeOrAway){
         	sym.getSymbol("team").$("squadTable").empty();
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&squad="+team,
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			squadData=data;
         			for (var i = 0; i <squadData.length; i++) {
         				var shirtNr = (squadData[i].n_ShirtNr!=null)?squadData[i].n_ShirtNr:"";
         				var player = squadData[i].c_Person+" <span style='text-align:right; font-style:oblique; font-size:11px'>" + squadData[i].c_PersonNatioShort + "</span>";
         				var ycards = squadData[i].n_CardsYellow;
         				var rcards = squadData[i].n_CardsRed;
         				var cards = ycards + "/" + rcards;
         				var goals = squadData[i].n_Goals;
         				var starts = squadData[i].n_MatchesStart;
         				var goals = squadData[i].n_Goals;
         				var date = getDDMMYY(squadData[i].d_BirthDate);
         				var position=squadData[i].n_FunctionCode;
         				var contractEnd=(squadData[i].d_ContractEndDate==null)?endWC:parsedDate(squadData[i].d_ContractEndDate);//Jan 29
         				if(todayTime<contractEnd){
         					if(homeOrAway){
         								var hORa=(homeOrAway=="home")?"h":"a";
         										if (position>0&&position<16){
         											var squadlist = "<div id='"+hORa+"player"+i+"'>";
         											squadlist += "<div class='squadCol1' id='"+hORa+"sqdshirt"+i+"'></div>";
         											squadlist += "<div class='squadCol2' id='"+hORa+"sqdplayerName"+i+"'></div>";
         											squadlist += "</div>";
         										}
         										sym.getSymbol("matchtracker").$("matchSquad"+hORa).append(squadlist);  
         										sym.getSymbol("matchtracker").$("preloader"+hORa).fadeOut(0);              
         										$('#'+hORa+'player'+i).css({'width':'100%','font-size':'12px','font-family':'pragmatica-web, sans-serif', 'display':'inline-table'});
         										$('.squadCol1').css({'width':'10%', 'color':'rgb(0,156,178)','padding-left':'3px', 'text-align':'right','display':'table-cell'});
         										$('.squadCol2').css({'width':'90%', 'padding-left':'3%','display':'table-cell'});
         										$('#'+hORa+'sqdplayerName'+i).css({'font-weight':400});
         										$('#'+hORa+'sqdshirt'+i).text(shirtNr);
         										$('#'+hORa+'sqdplayerName'+i).html(player);
         					}else{
         						if (position>0&&position<16){
         							var squadlist = "<div id='player"+i+"'>";
         							squadlist += "<div class='squadCol1' id='sqdshirt"+i+"'></div>";
         							squadlist += "<div class='squadCol2' id='sqdplayerName"+i+"'></div>";
         							squadlist += "<div class='squadCol5' id='sqddate"+i+"'></div>";
         							squadlist += "<div class='squadCol3' id='sqdmatches"+i+"'></div>";
         							squadlist += "<div class='squadCol3' id='sqdcards"+i+"'></div>";
         							squadlist += "<div class='squadCol4' id='sqdgls"+i+"'></div>";
         							squadlist += "</div>";
         						}else if(position==16){
         							sym.getSymbol("team").$("teamTxt1").html(txtArr[15]+player);
         						}
         						sym.getSymbol("team").$("squadTable").append(squadlist);
         										$('#player'+i).css({'width':'100%','font-size':'12px','font-family':'pragmatica-web, sans-serif', 'display':'inline-table','border-bottom':'solid 1px rgba(100,100,100,0.5)','border-top':'solid 1px rgba(255,255,255,0.8)'});
         										$('.squadCol1').css({'width':'5%', 'color':'rgb(0,156,178)','padding-left':'3px', 'text-align':'right','display':'table-cell'});
         										$('.squadCol2').css({'width':'50%', 'padding-left':'3%','display':'table-cell'});
         										$('#sqdplayerName'+i).css({'font-weight':400});
         										$('.squadCol5').css({'width':'25%', 'display':'table-cell', 'text-align':'center','font-style':'italic'});
         										$('.squadCol3').css({'width':'10%', 'display':'table-cell', 'text-align':'center'});
         										$('.squadCol4').css({'width':'10%', 'display':'table-cell', 'text-align':'right'});
         						$('#sqdshirt'+i).text(shirtNr);
         						$('#sqdplayerName'+i).html(player);
         						$('#sqddate'+i).text(date);
         						$('#sqdmatches'+i).text(starts);
         						$('#sqdcards'+i).text(cards);
         						$('#sqdgls'+i).text(goals);
         					}
         				}
         			}
         		}
         	});
         }
         //PIE CHART
         function pieChart(hwins,awins,draws,placeHolder){			
              var canvasWidth = 145, //width
               canvasHeight = 90,   //height
               outerRadius = 45,   //radius
               //color = d3.scale.category20(); //builtin range of colors
         		color = d3.scale.ordinal().range(["#006666","#4e9799","#33c5cc","#FF6666"]);
             var dataSet = [
               {"legendLabel":"Won", "magnitude":awins},  
               {"legendLabel":"Drawn", "magnitude":draws}, 
               {"legendLabel":"Won", "magnitude":hwins}];
             var vis = d3.select(placeHolder)
               .append("svg:svg") //create the SVG element inside the <body>
                 .data([dataSet]) //associate our data with the document
                 .attr("width", canvasWidth) //set the width of the canvas
                 .attr("height", canvasHeight) //set the height of the canvas
                 .append("svg:g") //make a group to hold our pie chart
         			.attr("transform", "translate("+canvasWidth/2+","+canvasHeight/2+")") //move centre of pie chart from 0, 0 to middle of placeholder
         			//	.attr("viewBox", +canvasWidth/2+"px",+canvasHeight/2+"px",90,90)
         				.style("-webkit-transform", "translate("+canvasWidth/2+"px,"+canvasHeight/2+"px)");
             // This will create <path> elements for us using arc data...
             var arc = d3.svg.arc()
               .outerRadius(outerRadius)
         		.innerRadius(outerRadius-30); //donut chart
             var pie = d3.layout.pie() //this will create arc data for us given a list of values
               .value(function(d) { return d.magnitude; }) // Binding each value to the pie
               .sort( function(d) { return null; } );
             // Select all <g> elements with class slice (there aren't any yet)
             var arcs = vis.selectAll("g.slice")  // Associate the generated pie data (an array of arcs, each having startAngle, endAngle and value properties) 
               .data(pie) // This will create <g> elements for every "extra" data element that should be associated with a selection. The result is creating a <g> for every object in the data array
               .enter() // Create a group to hold each slice (we will have a <path> and a <text> element associated with each slice)
               .append("svg:g")
               .attr("class", "slice");    //allow us to style things in the slices (like text)
             arcs.append("svg:path")
               //set the color for each slice to be chosen from the color function defined above
               .attr("fill", function(d, i) { return color(i); } ) //this creates the actual SVG path using the associated data (pie) with the arc drawing function
               .attr("d", arc);
         }
         function getH2H(match){
         	sym.getSymbol("matchtracker").$("h2hmatch").html("<div style='font-family:pragmatica-web;text-align:center;font-size:14px'>"+txtArr[29]+"</div>");
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&q=h2hsum&match="+match,
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			sym.getSymbol("matchtracker").$("h2hgoals").empty();
         			sym.getSymbol("matchtracker").$("h2hTxt1").empty();
         			sym.getSymbol("matchtracker").$("h2hTxt2").empty();
         			sym.getSymbol("matchtracker").$("h2hTxt3").empty();
         			sym.getSymbol("matchtracker").$("h2hmatch").empty();
         			sym.getSymbol("matchtracker").$("h2hTxt4").fadeIn(0);
         			h2hData = data;
         			if(h2hData.length>0&&h2hData[0].n_Matches>0){			
         				var hwins=h2hData[0].n_MatchesWonHome;
         				var awins=h2hData[0].n_MatchesWonAway;
         				var draws=h2hData[0].n_MatchesDrawn;
         				var hgoals=h2hData[0].n_GoalsForHome;
         				var agoals=h2hData[0].n_GoalsForAway;
         				var placeHolder="#Stage_matchtracker_h2hmatch";
         				pieChart(hwins,awins,draws,placeHolder);
         				sym.getSymbol("matchtracker").$("h2hTxt1").html(txtArr[25]+": <b>"+hwins+"</b>");
         				sym.getSymbol("matchtracker").$("h2hTxt2").html(txtArr[26]+": <b>"+awins+"</b>");
         				sym.getSymbol("matchtracker").$("h2hTxt3").html(txtArr[27]+": <b>"+draws+"</b>");
         				sym.getSymbol("matchtracker").$("h2hTxt4").html(txtArr[14]);
         				var barTxt="<div class='barGraph'>";
         					barTxt+="<div id='capGoals'></div>";
         				barTxt+="<div id='hbarGoals'></div>";
         				barTxt+="<div id='abarGoals'></div>";
         				barTxt+="</div>";
         				sym.getSymbol("matchtracker").$("h2hgoals").append(barTxt);
         				var hwidth=(hgoals/(hgoals+agoals)*100)+"%";
         				var awidth=(agoals/(hgoals+agoals)*100)+"%";
         				$("#hbarGoals").text(hgoals);
         				$("#abarGoals").text(agoals);
         				var acolor=(agoals==0)?'#33c5cc':'#006666';
         				var hcolor=(hgoals==0)?'#006666':'#33c5cc';
         				$("#capGoals").html(txtArr[28]);
         				$(".barGraph").css({'font-family':'pragmatica-web,sans-serif','width':'100%','height':'20px','font-size':'13px','font-weight':700, 'display':'inline-table'});
         				$("#capGoals").css({'text-align':'center','width':'100%','display':'table-caption'});
         				$("#hbarGoals").css({'background-color':hcolor,'color':'#ffffff','padding-left':'5px','padding-top':'2px','text-align':'left', 'display':'table-cell','width':hwidth});
         				$("#abarGoals").css({'background-color':acolor,'color':'#ffffff','padding-right':'5px','padding-top':'2px','text-align':'right','width':awidth,'display':'table-cell'});
         			}else{
         				sym.getSymbol("matchtracker").$("h2hTxt4").fadeOut(0);
         				sym.getSymbol("matchtracker").$("h2hmatch").append("<div style='font-family:pragmatica-web;text-align:center;font-size:14px'>"+txtArr[29]+"</div>");
         			}
         		}
         	});
         }
         function getmatchStats(match){
         	$.ajax({ type: "GET", url: dataURL,
         		data: "gn="+gn+"&yr="+gnYear+"&q=stats&match="+match,
         		contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
         		async: true,
         		crossDomain: true,
         		success: function (data) {
         			sym.getSymbol("matchtracker").getSymbol("matchStats").$("chartHolder").empty();
         			sym.getSymbol("matchtracker").getSymbol("matchStats").$("barCharts").empty();
         			matchData = data;
         			var bar;
         			var placeHolder="#Stage_matchtracker_matchStats_chartHolder";
         			if (matchData.length>0){
         				function drawBar(){
                  			var barTxt="<div class='barGraph'>";
                  			barTxt+="<div id='cap"+bar+"'></div>";
                  			barTxt+="<div id='hbar"+bar+"'></div>";
                  			barTxt+="<div id='abar"+bar+"'></div>";
                  			barTxt+="</div>";
         						sym.getSymbol("matchtracker").getSymbol("matchStats").$("barCharts").append(barTxt);
                  	}
         				for (var i = 0; i < matchData.length; i++) {
         					if(matchData[i].n_ActionSet==13&&matchData[i].c_ActionShort=="BP"){//possession
         						var hPoss=matchData[i].n_HomePoints;
         						var aPoss=matchData[i].n_AwayPoints;
         						pieChart(hPoss,aPoss,0,placeHolder);
         						sym.getSymbol("matchtracker").getSymbol("matchStats").$("hpiTxt").html(hPoss+"%");
         						sym.getSymbol("matchtracker").getSymbol("matchStats").$("apiTxt").html(aPoss+"%");
         					}else if(matchData[i].n_ActionSet==12){
         						if(matchData[i].n_ActionSort==104){//on target
         							var hPts=matchData[i].n_HomePoints;
         							var aPts=matchData[i].n_AwayPoints;
         							bar="shots";
         							drawBar();
         						}
         						if(matchData[i].n_ActionSort==106){//saves
         							var hPts=matchData[i].n_HomePoints;
         							var aPts=matchData[i].n_AwayPoints;
         							bar="saves";
         							drawBar();
         						}
         						if(matchData[i].n_ActionSort==112){//fouls against
         							var hPts=matchData[i].n_HomePoints;
         							var aPts=matchData[i].n_AwayPoints;
         							bar="fouls";
         							drawBar();
         						}
         						var hwidth=(hPts/(hPts+aPts)*100)+"%";
         						var awidth=(aPts/(hPts+aPts)*100)+"%";
         						$("#hbar"+bar).text(hPts);
         						$("#abar"+bar).text(aPts);
         						$(".barGraph").css({'margin':'10px 0px','font-family':'pragmatica-web,sans-serif','width':'100%','height':'20px','font-size':'13px', 'display':'inline-table'});
         						$("#cap"+bar).css({'text-align':'center','width':'100%','display':'table-caption','font-weight':700});
         						$("#hbar"+bar).css({'background-color':'#33c5cc','color':'#ffffff','padding-left':'5px','text-align':'left', 'display':'table-cell','width':hwidth});
         						$("#abar"+bar).css({'background-color':'#006666','color':'#ffffff','padding-right':'5px','text-align':'right','width':awidth,'display':'table-cell'});
         					}
         						$("#capshots").html(txtArr[21]);
         						$("#capsaves").html(txtArr[22]);
         						$("#capfouls").html(txtArr[23]);
         				}
         			}
         		}
         	});
         }
         $('img').on('dragstart',function(e){ e.preventDefault(); }); //make images undraggable

      });
      //Edge binding end

      

   })("stage");
   //Edge symbol end:'stage'

   //=========================================================
   
   //Edge symbol: 'StyleMc'
   (function(symbolName) {   
   
   })("StyleMc");
   //Edge symbol end:'StyleMc'

   //=========================================================
   
   //Edge symbol: 'StyleBase'
   (function(symbolName) {   
   
   })("StyleBase");
   //Edge symbol end:'StyleBase'

   //=========================================================
   
   //Edge symbol: 'Match'
   (function(symbolName) {   
   
   })("Match");
   //Edge symbol end:'Match'

   //=========================================================
   
   //Edge symbol: 'Overview'
   (function(symbolName) {   
   
   })("Team");
   //Edge symbol end:'Team'

   //=========================================================
   
   //Edge symbol: 'menuBtn'
   (function(symbolName) {   
   
   })("MenuBtn");
   //Edge symbol end:'MenuBtn'

   //=========================================================
   
   //Edge symbol: 'MenuBtns'
   (function(symbolName) {   
   
   })("MenuBtns");
   //Edge symbol end:'MenuBtns'

   //=========================================================
   
   //Edge symbol: 'Latest'
   (function(symbolName) {   
   
   })("Latest");
   //Edge symbol end:'Latest'

   //=========================================================
   
   //Edge symbol: 'TableHead'
   (function(symbolName) {   
   
   })("TableHead");
   //Edge symbol end:'TableHead'

   //=========================================================
   
   //Edge symbol: 'BarGraph'
   (function(symbolName) {   
   
   })("BarGraph");
   //Edge symbol end:'BarGraph'

   //=========================================================
   
   //Edge symbol: 'MatchStats'
   (function(symbolName) {   
   
   })("MatchStats");
   //Edge symbol end:'MatchStats'

   //=========================================================
   
   //Edge symbol: 'Preloader'
   (function(symbolName) {   
   
   })("Preloader");
   //Edge symbol end:'Preloader'

   //=========================================================
   
   //Edge symbol: 'fixtures'
   (function(symbolName) {   
   
   })("fixtures");
   //Edge symbol end:'fixtures'

   //=========================================================
   
   //Edge symbol: 'example'
   (function(symbolName) {   
   
   })("example");
   //Edge symbol end:'example'

})(jQuery, AdobeEdge, "GraphicNews31938");