/***********************
* 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) {
                  //Edit for each race
                  var raceRnd=8;
                  var gpHr=10; //time of 1st practice
                  var raceHr=13;//time of race
                  
         //DO NOT CHANGE
         $(".continents").css({"-webkit-border-radius":"50%","-khtml-border-radius":"50%","-moz-border-radius":"50%","border-radius":"50%",
         "-webkit-mask-image": "-webkit-gradient(linear, left top, right top, color-stop(0, rgba(0,0,0,1)), color-stop(1, rgba(0,0,0,1)))"});
         var latitude =[-28,4,31,26,38,43,45,47,52,47,47,50,45,3,33,42,29,19,-10,24];//latitude with adjustments
         var longitude =[145,101,122,50,2,7,-73,14,0,10,19,4,9,103,136,39,-97,-99,-51,54];//longitude
         var y=latitude[raceRnd];
         var x=longitude[raceRnd];
         
         var gpMonth=[2,2,3,3,4,4,5,5,6,6,6,7,8,8,8,9,9,10,10];//start month
         var raceMonth=[2,2,3,3,4,4,5,5,6,6,6,7,8,8,8,9,10,10,10];//month of race
         var gpDay=[13,27,10,17,8,21,5,19,3,17,24,21,4,18,25,9,23,30,13,27];//start day
         var raceDay=[15,29,12,19,10,24,7,21,5,19,26,23,6,20,27,11,25,1,15,29];//day of race
         
         var gn = 32715;//first circuit - do not change
         var yearNo=2015;
         var raceArr = [1077387,1077397,1077481,1077407,1077490,1077499,1077518,1077524,1077534,1077551,1098261,1098274,1098288,1098298,1098304,1098316,1098327,1098344,1098349,1098364];//race ID number
         var raceID = raceArr[raceRnd];
         var gnNo = 32552;//number for live data
         sym.getSymbol("styleHead").$("number").html(raceRnd+1);
         sym.getSymbol("styleHead").$("flag").attr('src','images/flag'+(raceRnd+1)+'.jpg');
         //FILL IN TEXT
         	var headlinetxt = sym.getSymbol("styleHead").$("headlineTxt").css("pointer-events","none");
         	var counterTxt = sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"pointer-events":"none","top":"-2px","box-shadow":"0px 0px 10px 10px rgba(255,255,255,0.2)","padding":"2px 4px","border-radius":"2px","border":"solid 1px rgb(255,255,255)","text-align":"left","right":"3px","left":"auto"});
         	//CREATE ARRAYS FOR TEXT ELEMENTS
         	//KEY START
         		var keyTxt=[];
         	for (var k=0; k<6; k++){
         		keyTxt[k]=sym.getSymbol("circuitMc").getSymbol("keyBase").$("key"+k).css("pointer-events","none");
         	}
         	//MENU START
         	var menuIcon=[];
         	var menuTxt=[]
         	for (var m=0;m<4;m++){
         		menuIcon[m]=sym.getSymbol("styleHead").getSymbol("menuBtn"+m).$("txt").css("pointer-events","none");
         		menuTxt[m]=sym.getSymbol("styleHead").$("menuTxt"+m).css({"pointer-events":"none","left":"auto","right":"0px","height":"28px","line-height":"28px","width":"33.3%"});
         		menuIcon[m].html("<img src='images/menuIcon"+m+".png'/>");
         	}
         	//CAPTIONS START
         	var capsTxt=[];
         		capsTxt[0]=sym.getSymbol("styleHead").$("standTxt").css("pointer-events","none");
         		capsTxt[1] = sym.getSymbol("styleBase").$("sourceTxt").css("pointer-events","none");
         		capsTxt[2] = sym.getSymbol("circuitMc").$("distance").css("pointer-events","none");
         		capsTxt[3] = sym.getSymbol("circuitMc").$("lap").css("pointer-events","none");
         		capsTxt[4] = sym.getSymbol("circuitMc").$("circuit").css("pointer-events","none");
         		capsTxt[5] = sym.getSymbol("circuitMc").$("pit").css("pointer-events","none");
         		capsTxt[6] = sym.getSymbol("circuitMc").getSymbol("recent").$("lastyear").css({"pointer-events":"none","line-height":"18px"});
         
         	//CAPTIONS - LIVE
         	var liveTxt=[];
         	liveTxt[0] = sym.getSymbol("liveMc").getSymbol("latestMc").$("txt0").css("pointer-events","none"); //laps
         	liveTxt[1] = sym.getSymbol("liveMc").getSymbol("latestMc").$("txt2").css("pointer-events","none"); //time
         	liveTxt[2] = sym.getSymbol("liveMc").getSymbol("latestMc").$("txt1").css("pointer-events","none"); //weather
         	liveTxt[3] = sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("pitstop").$("txt").css("pointer-events","none"); //pitstop
         	liveTxt[4] = sym.getSymbol("liveMc").getSymbol("timingMc").$("txt4").css("pointer-events","none"); //time
         
         	liveTxt[5] = sym.getSymbol("liveMc").getSymbol("latestMc").$("driverTxt").css("pointer-events","none");
         	liveTxt[6] = sym.getSymbol("liveMc").getSymbol("latestMc").$("teamTxt").css("pointer-events","none");
         	liveTxt[7] = sym.getSymbol("liveMc").getSymbol("timingMc").$("driverTxt").css("pointer-events","none");
         	liveTxt[8] = sym.getSymbol("liveMc").getSymbol("timingMc").$("teamTxt").css("pointer-events","none");
         	liveTxt[9] = sym.getSymbol("liveMc").getSymbol("latestMc").$("txt3").css("pointer-events","none"); //race session
         	liveTxt[10] = sym.getSymbol("liveMc").getSymbol("timingMc").$("txt5").css("pointer-events","none"); //race session
         	liveTxt[11] = sym.getSymbol("liveMc").getSymbol("phaseBtn2").$("gridTxt").css("pointer-events","none"); //grid text on phase button
         	//CAPTIONS - RESULTS
         	var resTxt=[];
         	for (var n=0;n<6;n++){
         		resTxt[n] = sym.getSymbol("resultsMc").$("resultTxt"+n).css("pointer-events","none");//results
         	}
         	//CORNERS START
         	var corners;
         	var cornerTxt=[];
         	for (var c=0;c<16;c++){
         		cornerTxt[c]= sym.getSymbol("circuitMc").$("corner"+c).css("pointer-events","none");
         	}
         	//RE-USABLE TEXT FROM XML
         	var menuIconArr =[];
         	var keyArr=[];
         	var menuTxtArr=[];
         	var capsArr=[];
         	var txtArr=[];
         	var resArr=[];
         	var stat;
         	var statCap;
         
         function numOrdA(a, b){ return (a-b); }//sort numbers ascending
         function numOrdD(a, b){ return (b-a); }//sort numbers descending
         
         //AJAX retrieves data from xml source specified in url, maps xml variable to DOM object variable
         $.ajax({	
         		type: "GET",
         		url: "GN"+(gn+raceRnd)+".xml",
         		dataType: "xml",
         		success: function(xml) {
         			var headline = $(xml).find('headline').text();
         			headlinetxt.html(headline);
         			var fontSize= $(xml).find('fontSize').text();
         			for (var i=0;i<6;i++){
         					keyArr[i]=$(xml).find('key'+i).text();
         					keyTxt[i].html(keyArr[i]);
         				}
         			for (var i=0; i<12; i++){
         					txtArr[i]=$(xml).find('txt'+i).text();
         				}
         			for (var l=0; l<5; l++){
         				liveTxt[l].html(txtArr[l]);
         			}	
         			var statCapString=$(xml).find('statusCap').text();
         				statCap= statCapString.split(";")
         			for (var m=0; m<menuIcon.length; m++){
         				menuTxtArr[m]=$(xml).find('menuTxt'+m).text();	
         				menuTxt[m].html(menuTxtArr[m]);
         			}
         			for (var i=0; i<3; i++){
         				sym.getSymbol("liveMc").getSymbol("phaseBtn"+i).$("txt").html(statCap[i]);
         			}
         			for (var c=0; c<capsTxt.length; c++){
         				capsArr[c] = $(xml).find('cap'+c).text();
         				capsTxt[c].html(capsArr[c]);
         			}
         			for (var r=0; r<5; r++){
         				resArr[r]=$(xml).find('results'+r).text();
         				resTxt[r].html(resArr[r]);
         			}
         			keyTxt[1].css({"left":"auto","right":"355px"});
         			keyTxt[4].css({"left":"auto","right":"1px"});
         			keyTxt[5].css({"left":"auto","right":"1px"});
         			$(xml).find("previous").each(function(){
         				var $previous = $(this);
         				var pcat = $previous.find('cat').text();
         				var pname=$previous.find('name').text();
         				var pteam=$previous.find('team').text();
         				var ptime=$previous.find('time').text();
         				var prevHtml="<div class='prevrow'><div class='cat'>"+pcat+"</div><div class='name'>"+pname+"</div><div class='team'>"+pteam+"</div><div class='time'>"+ptime+"</div></div>";
         				sym.getSymbol("circuitMc").getSymbol("recent").$("previous").append(prevHtml);
         			});
         			$(".prev").css({"font-family":"pragmatica-web,sans-serif","font-size":"12px","width":"385px","line-height":"14px","color":"rgb(140,140,140)"})
         			$(".prevrow").css({"width":"100%","display":"table","height":"17px","border-bottom":"groove 1px rgb(200,200,200)","background-color":"rgba(255,255,255,0.9)"})
         			capsTxt[6].css({"text-align":"center","font-weight":700,"color":"rgb(255,255,255)","width":"50px"});//lastyear
         			$(".cat").css({"width":"75px","display":"table-cell","padding-left":"5px"});
         			$(".name").css({"width":"125px","display":"table-cell","font-weight":700});
         			$(".team").css({"width":"75px","display":"table-cell","font-style":"oblique"});
         			$(".time").css({"width":"100px","display":"table-cell","font-weight":700,"text-align":"right","padding-right":"5px"});
         			sym.getSymbol("circuitMc").$("recent").css({"right":"-385px","left":"auto","border-left":"solid 1px white","border-bottom":"solid 1px white","border-bottom-left-radius":"10px"});
         			var cornerString=$(xml).find('corners').text();
         					corners= cornerString.split(";");
         					for (var i=0;i<corners.length;i++){
         					cornerTxt[i].html(corners[i]);
         					}
         			var statusString=$(xml).find('status').text();
         					stat= statusString.split(";");
         					liveTxt[11].html(statCap[5]);
         			var winners = $(xml).find('winners').text();
         			sym.getSymbol("winnersMc").$("winnerTxt0").html(winners);
         			sym.getSymbol("winnersMc").$("winnerTxt1").html(txtArr[7]);
         			var timeMs=[];var unSorted=[]; var driverArr=[]; var teamArr=[]; var timeArr=[]; var yearArr=[];
         			for (var n=0;n<11;n++){		//get details for each year
                  				$(xml).find("winner"+n).each(function(){
                  					var $winner = $(this);
                  					driverArr[n]=$winner.find('name').text();
                  					teamArr[n]=$winner.find('team').text();
                  					timeArr[n]=$winner.find('time').text();	
                  					yearArr[n]=$winner.attr('year');			
                  				});
         				timeMs[n]=	parseFloat(timeArr[n]);
         				unSorted.push(timeMs[n]);//store speeds in an unsorted array
         			var winnerTable ="<div class='winners'>";
         				winnerTable += "<div id='winner"+n+"'>";
         				winnerTable += "<table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr>";
         				winnerTable +="<td class='wyear' id='wyear"+n+"'></td>";
         				winnerTable +="<td class='wdriver' id='wdriver"+n+"'></td>";
         				winnerTable +="<td class='wteam' id='wteam"+n+"'></td>";
         				winnerTable +="<td class='wtime' id='wtime"+n+"'></td>";
         				winnerTable +="</tr></table>";
         				winnerTable +="</div>";
         				winnerTable +="</div>";
         				sym.getSymbol("winnersMc").$("graph").append(winnerTable);
         				$('#wyear' + n).text(yearArr[n]);
         				$('#wdriver' + n).text(driverArr[n]);
         				$('#wteam' + n).text(teamArr[n]);
         				$('#wtime' + n).text(timeArr[n]);
         			}
         			var sorted=timeMs.sort( numOrdD );	
         			for (n=0;n<timeMs.length;n++){	
         				var x=timeMs.indexOf(unSorted[n]);
         				if(x==0){
         				scaleWinner=100;
         				}else if(x==timeMs.length-1){
         				scaleWinner=65;
         				}else{
         				scaleWinner=100-((timeMs[x]-timeMs[0])*35/(timeMs[timeMs.length-1]-timeMs[0]));
         				}
         				$("#winner"+n).css({'height':'21px','width':scaleWinner+'%','background-color':'rgb(230,225,215)','box-shadow':'3px 2px 5px rgba(100,100,100,0.75)',});
         			}
         			$(".winners").css({'font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'margin-bottom':'2px'});
         			$(".wyear").css({'width':'50px','font-weight':700,'padding-left':'3px'});
         			$(".wdriver").css({'width':'175px'});
         			$(".wteam").css({'width':'50px','font-style':'italic'});
         			$(".wtime").css({'text-align':'right','padding-right':'5px'});
         			$(".textSize").css({'font-size':fontSize});
         		}
         	}); // END XML
         
         //SPIN THE GLOBE
         function spinGlobe(xTxt){
         		var h=sym.getSymbol("intro").$("logoMc").height();
         		var w=sym.getSymbol("intro").$("logoMc").width();
         		var x=-610-(parseInt(xTxt,10)*100/72);//-610=Greenwich
         		var xBack=-430+(parseInt(xTxt,10)*100/72);
         		sym.getSymbol("intro").getSymbol("globe").getSymbol("continents").$("mapFront").stop().animate ({left:x}, 800, 'easeOutCubic');
         		sym.getSymbol("intro").getSymbol("globe").getSymbol("continents").$("mapBack").stop().animate ({left:xBack}, 800, 'easeOutCubic', function(){sym.getSymbol("intro").play(0);});
         }
         spinGlobe(x,y);
         
         sym.lat = function() {
               var s =Math.round(230-(Math.sin(y*Math.PI*0.95/180)*206));//230=equator, 206=radius of globe
         		sym.getSymbol("intro").$("logoMc").animate({'top':s},200, 'easeOutCubic');
         }
         // STOP ELEMENTS INTERACTING WITH MOUSE
         	sym.$("handMc").css("pointer-events","none");
         
         sym.getSymbol("liveMc").getSymbol("latestMc").$("leadDriver").fadeOut(0);
         
         // MENU BUTTONS --------------------------------------------	
         menuArray = []; //the array that will hold references to the buttons.
         for (var h = 0; h < menuIcon.length; h++){
         		var menuBtnSymbols = sym.getSymbol("styleHead").getSymbol("menuBtn" +h); // Create an instance element of a symbol as a child of the given parent element
         		menuBtnSymbols.setVariable("menuId", h); //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 ("touchstart click", {menuId:count}, menuBtnClick);
         		menuBtnElement.on ("mouseover", {menuId:count}, menuShow);
         		menuBtnElement.on ("mouseout", {menuId:count}, menuHide);
         })
         function resetmenu(){
         		for (var h=0; h<menuIcon.length; h++){
         			$.each(menuTxt, function(index, value) {
         			$(value).fadeOut(0);
         			});
         			for (var i=0;i<3;i++){
         				sym.getSymbol('liveMc').getSymbol('phaseBtn'+i).$('bg').css({'background-color':'rgb(182,175,157)'});
         				sym.getSymbol('liveMc').getSymbol('phaseBtn'+i).$('txt').css({'font-weight':400});
         				sym.getSymbol("liveMc").getSymbol("phaseBtn"+i).$("top").fadeIn(0);
         				sym.getSymbol("liveMc").getSymbol("phaseBtn"+i).$("top").css({"cursor":"pointer"});
         			}		
                  menuArray[h].$("btnClick").fadeOut(0);
                  menuArray[h].$("btnOver").fadeOut(0);
         		}
         }
         resetmenu();
         var showPlay=0;
         var playTime;//
         function menuBtnClick (e){
         		e.preventDefault();
         		e.stopPropagation();
         		resetmenu(); //set them all back to normal state
         		var menuMenu_id = (e.data.menuId); //get the id of the clicked item
         		var menuPhaseLive= (e.data.phaseLive);
         		var sessLive=(e.data.sessionLive);
         		var numPhases;
         		sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnClick").fadeIn(0);
         		menuTxt[menuMenu_id].fadeIn(0);
         		for (var i=0;i<mcArr.length; i++){
         			if (i==menuMenu_id){
         				sym.$(mcArr[i]).fadeIn(1000);
         				showMc=menuMenu_id;
         				if (menuMenu_id==0) {
         				 clearTimeout(playTime);//
         				 if(showPlay==0){
         				 	playTime=setTimeout(playIt,2850);
         				 }
         				}else
         				if (menuMenu_id==1) {
         					sym.getSymbol("liveMc").getSymbol("latestMc").$("leadDriver").delay(500).fadeIn(1000);
         					sym.getSymbol('liveMc').getSymbol('phaseBtn'+menuPhaseLive).$('bg').css({'background-color':'rgb(255,255,255)'});
         					sym.getSymbol('liveMc').getSymbol('phaseBtn'+menuPhaseLive).$('txt').css({'font-weight':700});
         					sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).$("top").fadeOut(0);
         					sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).$("top").css({"cursor":"auto"});
         					sym.getSymbol("liveMc").$("timingMc"). fadeOut(0);
         					sym.getSymbol("liveMc").$("latestMc"). fadeIn(0);
         					sym.getSymbol("liveMc").$("gridMc"). fadeOut(0);
         					if(menuPhaseLive==2){
         						numPhases=2;
         							if(sessLive==0){
         								sym.getSymbol("liveMc").$("latestMc"). fadeOut(0);
         								sym.getSymbol("liveMc").$("gridMc"). fadeIn(0);
         							}
         					}else{
         						numPhases=3;
         					}
         					for (n=0;n<numPhases;n++){	
         							if (menuPhaseLive<2){
         							nos=n+1;
         							}else{
         							nos=n;
         							}
         							if (nos==sessLive){
         							sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).getSymbol(phaseArray[menuPhaseLive]+nos).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(76,129,0) rgb(119,192,61) rgb(119,192,61) rgb(76,129,0)"});
         							sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).getSymbol(phaseArray[menuPhaseLive]+nos).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(134,20,0) rgb(255,180,150) rgb(255,180,150) rgb(134,20,0)"});							
         							}else{
         							sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).getSymbol(phaseArray[menuPhaseLive]+nos).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(119,192,61) rgb(76,129,0) rgb(76,129,0) rgb(119,192,61)"});
         							sym.getSymbol("liveMc").getSymbol("phaseBtn"+menuPhaseLive).getSymbol(phaseArray[menuPhaseLive]+nos).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",																																				"border-color":"rgb(255,180,150) rgb(134,20,0) rgb(134,20,0) rgb(255,180,150)"});
         							}																																												
         					}
         				}else{
         					if (menuMenu_id==2){
         						for (m=0; m<10; m++){
         							var carMove=43+m*420/nRaceDrivers;
         							sym.getSymbol("resultsMc").$("car"+m).animate({'top':carMove}, 1000);
         						}
         					}
         					sym.getSymbol("liveMc").getSymbol("latestMc").$("leadDriver").fadeOut(1000);
         				}
         			}else{
         				sym.$(mcArr[i]).fadeOut(1000);
         			}
         		}
         		sym.getSymbol("circuitMc").$("status").fadeOut(0);
         }
         
         function menuShow (e){
         		var menuMenu_id = (e.data.menuId); //get the id of the over button
         		sym.$('handMc').hide();
         		sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeIn(0);
         		menuTxt[menuMenu_id].fadeIn(0);
         		sym.getSymbol("circuitMc").$("status").fadeOut(0);
         }
         function menuHide (e){
         		var menuMenu_id = (e.data.menuId); //get the id of the out button
         		sym.getSymbol("styleHead").getSymbol("menuBtn" + menuMenu_id).$("btnOver").fadeOut(0);
         		menuTxt[menuMenu_id].fadeOut(0);
         		sym.getSymbol("circuitMc").$("status").fadeIn(0);
         }
         // DISABLE MENU BUTTONS THAT ARE ONLY AVAILABLE AFTER RACE START
         sym.getSymbol("styleHead").$("menuBtn1").off("touchstart click");
         sym.getSymbol("styleHead").$("menuBtn2").off("touchstart click");
         // MAKE MENU 0 VISIBLE
         sym.getSymbol("styleHead").getSymbol("menuBtn0").$("btnClick").fadeIn(0);
         //RECENT RESULTS
         var inOut=0
         sym.getSymbol("circuitMc").$("recent").css({'cursor':'pointer'});
         sym.getSymbol("circuitMc").$("recent").on('click', function(){
         	if(inOut==0){
         	sym.getSymbol("circuitMc").$("recent").stop().animate({right:0},400,'easeOutCubic');
         	inOut=1;
         	}else{
         	sym.getSymbol("circuitMc").$("recent").stop().animate({right:-385},400,'easeOutCubic');	
         	inOut=0;
         	}
         });
         // PLAY/PAUSE BTN
         var rePlay=0;
         sym.getSymbol("circuitMc").$("playPause").on('click', function(e){
         	e.stopPropagation(); e.preventDefault();
         	playIt();
         });
         sym.fadeIt = function(){
         	sym.$("intro").fadeOut(300);
         }
         function playIt (){
         	sym.$("intro").fadeOut(300);
         	clearTimeout(playTime);
         	console.log(showPlay);
         	if(rePlay==0){
         		if (sym.getSymbol("circuitMc").getPosition()==0||sym.getSymbol("circuitMc").getPosition()==sym.getSymbol("circuitMc").getDuration()){
         			sym.getSymbol("circuitMc").play(1);
         		}else{
         			sym.getSymbol("circuitMc").play();
         		}
         		sym.getSymbol("circuitMc").getSymbol("carMc").play();
         		sym.getSymbol("circuitMc").getSymbol("playPause").$("play").fadeOut();
         		sym.getSymbol("circuitMc").getSymbol("playPause").$("replay").fadeOut();		
         		rePlay=1;	
         	}else if(rePlay==1){
         		sym.getSymbol("circuitMc").stop();
         		sym.getSymbol("circuitMc").getSymbol("playPause").$("play").fadeIn();	
         		rePlay=0;	
         	}
         }
         sym.stopIt = function(){
         	sym.getSymbol("circuitMc").stop();
         	sym.getSymbol("circuitMc").getSymbol("carMc").stop();
         	sym.getSymbol("circuitMc").getSymbol("playPause").$("play").fadeOut();
         	sym.getSymbol("circuitMc").getSymbol("playPause").$("replay").fadeIn();
         	showPlay=1;
         	rePlay=0;	
         }
         //SHOW SESSION BUTTON LABELS
         var sessNo=["-","I","II","III"];
         for (var i=0;i<3;i++){
         	sym.getSymbol("liveMc").getSymbol("phaseBtn0").getSymbol("FP"+(i+1)).$("phaseTxt").html(sessNo[i+1]);
         	sym.getSymbol("liveMc").getSymbol("phaseBtn1").getSymbol("Q"+(i+1)).$("phaseTxt").html(sessNo[i+1]);
         	sym.getSymbol("liveMc").getSymbol("phaseBtn"+i).$("top").css({"cursor":"pointer"});
         }
         for (var r=0;r<2;r++){
         sym.getSymbol("liveMc").getSymbol("phaseBtn2").getSymbol("R"+(r)).$("phaseTxt").html(sessNo[r]);
         }
         //STATUS COUNTDOWN - TIME
         var counter;
         var diff=0;
         var gpDate= Date.UTC(yearNo,gpMonth[raceRnd],gpDay[raceRnd],gpHr,30,00)
         var raceDate= Date.UTC(yearNo,raceMonth[raceRnd],raceDay[raceRnd],raceHr,00,00)
         function countDown(){
         	var todayDate = new Date();
         	diff = raceDate-todayDate;
         	var days = Math.floor(diff/86400000);
         	var hours = Math.floor((diff%86400000)/3600000);
         	var mins = Math.floor((diff%86400000)%3600000/60000);
         	var secs = Math.floor((diff%86400000)%3600000%60000/1000);
         	var dd = leadingZero(days).toString();
         	var hh = leadingZero(hours).toString();
         	var mm = leadingZero(mins).toString();
         	var ss = leadingZero(secs).toString();
         	if(todayDate<gpDate){
         		var gpdiff = gpDate-todayDate;
         		var gpdays = Math.floor(gpdiff/86400000);
         		counterTxt.html(statCap[3]+": "+days+" "+stat[0]+" "+hh+":"+mm+":"+ss);
         		if (gpdays>1){
         			menuTxt[1].html(menuTxtArr[1]+": "+gpdays+" "+stat[0]+" "+stat[4]);
         		}else{
         			menuTxt[1].html(menuTxtArr[1]+": "+gpdays+" "+stat[5]+" "+stat[4]);
         		}
         		menuTxt[2].html(menuTxtArr[2]+": "+days+" "+stat[0]+" "+stat[4]);
         	}
         }
         function leadingZero(time) {
             return (time < 10) ? "0" + time : time;
         }
         counter=setInterval(countDown,1000);
         // PHASE BUTTONS
         var phArr=["F","Q","R"];
         var phaseArray = ["FP","Q","R"];
         
         //LIVE DATA
         var dataURL = ('http:'==document.location.protocol?"http://www2.graphicnews.com/":"https://www.graphicnews.org/")+ "infostradasports/api.php";
         var raceData;  
         var timer;
         var barHeight;
         var order;
         var raceFinished = 0;
         var firstPhase;
         var phase;
         var resultCar;
         var scaleresult;
         var minTime;
         var scale;
         var nRaceDrivers;
         var points;
         var raceStage;
         var phaseNo;
         var showMc=0;
         var gridClicker = function(phaseNo){ //to handle lexical scope
         							return function (e) {
         							getGrid(phaseNo);
         							sym.getSymbol('liveMc').getSymbol('phaseBtn0').$('bg').css({'background-color':'rgb(182,175,157)'});
         							sym.getSymbol('liveMc').getSymbol('phaseBtn1').$('bg').css({'background-color':'rgb(182,175,157)'});
         							sym.getSymbol('liveMc').getSymbol('phaseBtn2').$('bg').css({'background-color':'rgb(255,255,255)'});
         					for (n=0;n<2;n++){	
         							if (n==0){
         								sym.getSymbol("liveMc").getSymbol('phaseBtn2').getSymbol(phaseArray[2]+(n)).$("live").css({"background-color":"rgb(119,192,61)",
         																																					"border-style":"solid",
         																																					"border-width": "2px",
         																																					"border-color":"rgb(76,129,0) rgb(119,192,61) rgb(119,192,61) rgb(76,129,0)"});
         								sym.getSymbol("liveMc").getSymbol('phaseBtn2').getSymbol(phaseArray[2]+(n)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																					"border-style":"solid",
         																																					"border-width": "2px",
         																																					"border-color":"rgb(134,20,0) rgb(255,180,150) rgb(255,180,150) rgb(134,20,0)"});							
         								}else{
         								sym.getSymbol("liveMc").getSymbol('phaseBtn2').getSymbol(phaseArray[2]+(n)).$("live").css({"background-color":"rgb(119,192,61)",
         																																					"border-style":"solid",
         																																					"border-width": "2px",
         																																					"border-color":"rgb(119,192,61) rgb(76,129,0) rgb(76,129,0) rgb(119,192,61)"});
         								sym.getSymbol("liveMc").getSymbol('phaseBtn2').getSymbol(phaseArray[2]+(n)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																					"border-style":"solid",
         																																					"border-width": "2px",
         																																					"border-color":"rgb(255,180,150) rgb(134,20,0) rgb(134,20,0) rgb(255,180,150)"});
         								}					
         						}					
         							sym.getSymbol("liveMc").$("gridMc"). fadeIn(1000);
         							sym.getSymbol("liveMc").$("timingMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("latestMc"). fadeOut(1000);
         								e.preventDefault();
         								e.stopPropagation();
         							};
         						};
         var showPhase = function(phaseNo,stage,session){
         				return function(e){
         				getPhases(phaseNo);
         				var ps = stage.substr(0,1);
         				var nos;
         				for (var i=0;i<3; i++){
         						var button="phaseBtn"+i;
         						if(i==2){
         							var numPhases=2;
         						}else{
         							var numPhases=3;
         						}				
         					if (ps==phArr[i]){
         						sym.getSymbol("liveMc").getSymbol(button).$("top").fadeOut(0);
         						sym.getSymbol('liveMc').getSymbol(button).$('bg').css({'background-color':'rgb(255,255,255)'});
         						sym.getSymbol('liveMc').getSymbol(button).$('txt').css({'font-weight':700});
         						sym.getSymbol("liveMc").getSymbol(button).$("top").css({"cursor":"auto"});
         						liveTxt[10].html(statCap[4] + " "+ sessNo[session]);
         						for (n=0;n<numPhases;n++){	
         							if (i<2){
         							nos=n+1;
         							}else{
         							nos=n;
         							}
         							if (nos==session){
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(76,129,0) rgb(119,192,61) rgb(119,192,61) rgb(76,129,0)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(134,20,0) rgb(255,180,150) rgb(255,180,150) rgb(134,20,0)"});							
         							}else{
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(119,192,61) rgb(76,129,0) rgb(76,129,0) rgb(119,192,61)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(255,180,150) rgb(134,20,0) rgb(134,20,0) rgb(255,180,150)"});
         							}																														
         						}
         						//Show starting grid caption in phasebtn
         				}else{
         						sym.getSymbol("liveMc").getSymbol(button).$("top").fadeIn(0);
         						sym.getSymbol('liveMc').getSymbol(button).$('bg').css({'background-color':'rgb(182,175,157)'});
         						sym.getSymbol('liveMc').getSymbol(button).$('txt').css({'font-weight':400});
         						sym.getSymbol("liveMc").getSymbol(button).$("top").css({"cursor":"pointer"});
         						for (n=0;n<numPhases;n++){	
         							if (i<2){
         							nos=n+1;
         							}else{
         							nos=n;
         							}
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(40,142,86)","border":"solid 2px rgba(182,175,157,1.00)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(216,89,80)","border":"solid 2px rgba(182,175,157,1.00)"});
         						}
         				}
         			}					
         			sym.getSymbol("liveMc").$("gridMc"). fadeOut(1000);
         			sym.getSymbol("liveMc").$("timingMc"). fadeIn(1000);
         			sym.getSymbol("liveMc").$("latestMc"). fadeOut(1000);
         showMc=1;
         			e.preventDefault();
         			e.stopPropagation();
         		}
         }
         var showLive = function(phaseNo,stage){
         				return function(e){
         				var ps = stage.substr(0,1);
         				var session=stage.substr(-1);
         				var nos;
         				for (var i=0;i<3; i++){
         						var button="phaseBtn"+i;
         						if(i==2){
         							var numPhases=2;
         						}else{
         							var numPhases=3;
         						}
         						if (ps==phArr[i]){
         						sym.getSymbol("liveMc").getSymbol(button).$("top").fadeOut(0);
         						sym.getSymbol('liveMc').getSymbol(button).$('bg').css({'background-color':'rgb(255,255,255)'});
         						sym.getSymbol('liveMc').getSymbol(button).$('txt').css({'font-weight':700});
         						sym.getSymbol("liveMc").getSymbol(button).$("top").css({"cursor":"auto"});
         						if(ps=="R"){
         							if(stage.substr(1,1)==1){	//if its the race
         							sym.getSymbol("liveMc").$("gridMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("timingMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("latestMc"). fadeIn(1000);
         							}else{ 							//if its starting grid
         							sym.getSymbol("liveMc").$("gridMc"). fadeIn(1000);
         							sym.getSymbol("liveMc").$("timingMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("latestMc"). fadeOut(1000);					
         							}
         						}else{
         							sym.getSymbol("liveMc").$("gridMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("timingMc"). fadeOut(1000);
         							sym.getSymbol("liveMc").$("latestMc"). fadeIn(1000);
         						}
         						for (n=0;n<numPhases;n++){	
         							if (i<2){
         							nos=n+1;
         							}else{
         							nos=n;
         							}
         						if (nos==session){
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(76,129,0) rgb(119,192,61) rgb(119,192,61) rgb(76,129,0)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(134,20,0) rgb(255,180,150) rgb(255,180,150) rgb(134,20,0)"});							
         							}else{
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(119,192,61)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(119,192,61) rgb(76,129,0) rgb(76,129,0) rgb(119,192,61)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(220,0,0)",
         																																				"border-style":"solid",
         																																				"border-width": "2px",
         																																				"border-color":"rgb(255,180,150) rgb(134,20,0) rgb(134,20,0) rgb(255,180,150)"});
         							}					
         						}
         					}else{
         						sym.getSymbol("liveMc").getSymbol(button).$("top").fadeIn(0);
         						sym.getSymbol('liveMc').getSymbol(button).$('bg').css({'background-color':'rgb(182,175,157)'});
         						sym.getSymbol('liveMc').getSymbol(button).$('txt').css({'font-weight':400});
         						sym.getSymbol("liveMc").getSymbol(button).$("top").css({"cursor":"pointer"});
         						for (n=0;n<numPhases;n++){	
         							if (i<2){
         							nos=n+1;
         							}else{
         							nos=n;
         							}
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("live").css({"background-color":"rgb(40,142,86)","border":"solid 2px rgba(182,175,157,1.00)"});
         							sym.getSymbol("liveMc").getSymbol(button).getSymbol(phaseArray[i]+(nos)).$("fin").css({"background-color":"rgb(216,89,80)","border":"solid 2px rgba(182,175,157,1.00)"}); 
         						}
         					}
         				}
         				showMc=1;										
         				e.preventDefault();
         				e.stopPropagation();
         				}
         }
         function showFinished(latest){//Elements if race finished
         							sym.getSymbol("styleHead").$("menuBtn2").on("touchstart click", {menuId:2}, menuBtnClick); //enable third menu button
         							menuTxt[2].html(menuTxtArr[2]);
         							sym.getSymbol("liveMc").getSymbol("phaseBtn2").$("txt").html(statCap[3]);//Change phaseBtn text to Race
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("pitstop").fadeIn(0);
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("txt0").fadeIn(0);	
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("lapCounter").fadeIn(0);
         							sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"background-color":"rgb(220,0,0)"});
         							sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").html(latest+" "+txtArr[6].toLowerCase());
         							getStandings(); //get latest standings 
         							clearInterval(raceInterval);
         							raceInterval=setInterval(getRace,600000);
         							raceFinished=1;
         }
         function sessLiveOrFin(latest){//Elements to show if live or finished
         						sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").html(latest);
         }
         //GET race weekend data
         function getRace(){
         	sym.getSymbol("styleHead").$("menuBtn1").off("click touchstart");
         	sym.getSymbol("styleHead").$("menuBtn2").off("click touchstart");
         	$.ajax({ type: "GET", 
         				url: dataURL,
                     data: "gn="+gnNo+"&yr="+yearNo+"&q=race&race="+raceID,
                     contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                     async: true,
                     crossDomain: true,
                     success: function (data) {                	
         				for (var z=0;z<3;z++){
         					sym.getSymbol("liveMc").getSymbol("phaseBtn"+z).$('top').unbind("click");
         					sym.getSymbol("liveMc").getSymbol("phaseBtn0").$("FP"+(z+1)).unbind("click");
         					sym.getSymbol("liveMc").getSymbol("phaseBtn1").$("Q"+(z+1)).unbind("click");
         					sym.getSymbol("liveMc").getSymbol("phaseBtn2").$("R"+z).unbind("click");
         				}	
         				var racePhases = data;
         				var n;
         				var latestPhase;
         				var getFunction;
         				var phaseBtnNo;
         				if(racePhases){
         					for (var i = 0; i < racePhases.length; i++) {
         						phase=racePhases[i].n_PhaseID;
         						var sessionNo=(racePhases[i].n_SessionNr>0)?racePhases[i].n_SessionNr:"";
         						var sessLive=(racePhases[i].b_Current==true)?1:0;
         						var sessStarted=(racePhases[i].b_Started==true)?1:0;
         						var sessFin=(racePhases[i].b_Finished==true)?1:0;
         						var nullSession=0;
         						var notStarted;
         						if (racePhases[i].b_FreePractice==true){
         							n = racePhases[i].n_Phase1Nr;
         							phaseBtnNo="0";
         							raceStage = "FP";
         							latestPhase = statCap[0];
         						}else if (racePhases[i].b_Qualifying==true&&racePhases[i].n_Phase2Nr==null){//show nothing
         							sessLive=0;
         							sessFin=0;
         							sessStarted=0;
         							nullSession=1;													
         						}else if (racePhases[i].b_Qualifying==true&&racePhases[i].n_Phase2Nr>0){						
         							n = racePhases[i].n_Phase2Nr;
         							phaseBtnNo="1";						
         							raceStage = "Q";
         							latestPhase = statCap[1];
         						}else if (racePhases[i].b_StartingGrid==true){	
         							n="0";
         							phaseBtnNo="2";
         							raceStage ="R";
         							latestPhase = statCap[2];						
         						}else if (racePhases[i].b_Race==true){
         							n="1";
         							phaseBtnNo="2";
         							raceStage ="R";
         							latestPhase = statCap[3];						
         						}
         						if(nullSession<1){
         							sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).$("top").unbind("click");
         							if(sessLive==1){											
         								sessLiveOrFin(latestPhase);
         								if(sessStarted==1){
         									getInfo(phase);
         									getLive(phase);
         									menuTxt[1].html(menuTxtArr[1]);
         									if(racePhases[i].b_Race==true){
         										sym.getSymbol("liveMc").getSymbol("phaseBtn2").$("txt").html(statCap[3]);
         										getFunction=showLive(phase,raceStage+n);
         									}else if(racePhases[i].b_StartingGrid==true){
         										getFunction=gridClicker(phase); 
         										//show start grid on phase btn
         									}else{
         										getFunction=showPhase(phase,raceStage+n,sessionNo);
         									}
         									if(sessFin==1){	
         										sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).getSymbol(raceStage+n).$("fin").show();
         										if(racePhases[i].b_Race==true){
         											showFinished(latestPhase);									
         										}else if(racePhases[i].b_StartingGrid==true){
         											sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"background-color":"rgb(119,192,61)"});
         										}else{
         											sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"background-color":"rgb(220,0,0)"});
         										}
         									}else{
         										sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).getSymbol(raceStage+n).$("live").show();
         										sym.getSymbol("styleHead").$("menuBtn2").off("touchstart click");
         										sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"background-color":"rgb(119,192,61)"});
         									}
         								}else{
         									if(raceStage == "FP"&&n==1){
         										notStarted=1;
         									}else{
         										getInfo(phase);
         										getLive(phase);
         									}
         								}
         							}else if(sessFin==1){	
         								sessLiveOrFin(latestPhase);
         								sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).getSymbol(raceStage+n).$("fin").show();
         								sym.getSymbol("circuitMc").getSymbol("status").$("statusTxt").css({"background-color":"rgb(220,0,0)"});
         							if (racePhases[i].b_Race==true){
         									showFinished(latestPhase);
         									getInfo(phase);
         									getLive(phase);
         									getFunction=showLive(phase,raceStage+n);
         								}else if(racePhases[i].b_StartingGrid==true){
         									getFunction=gridClicker(phase);
         								}else{
         									liveTxt[4].fadeIn(0);
         									getFunction=showPhase(phase,raceStage+n,sessionNo);
         								}
         							}															
         						sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).$(raceStage+n).css({"cursor":"pointer"});
         						sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).$(raceStage+n).click(getFunction);
         						sym.getSymbol("liveMc").getSymbol("phaseBtn"+phaseBtnNo).$("top").click(getFunction);
         						}
         				}//end for
         				phaseNo=phaseBtnNo;
         				//
         				if (notStarted==1){
         					getInfo(raceID);
         					getStartList();
         				}			
         			}else{
         			getInfo(raceID);
         			getStartList();
         			}
         		}
         	});
         }
         getRace();
         raceInterval=setInterval(getRace,60000);
         
         sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").append('<img src="images/weather0.png" width="27px" height="27px">');
         var gridPhase=0;
         //GET individual phase info for laps/live race conditions
         function getInfo(phaseID){
         $.ajax({ type: "GET", 
         						url: dataURL,
                         data: "gn="+gnNo+"&yr="+yearNo+"&q=info&race="+phaseID,
                         contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                         async: true,
                         crossDomain: true,
                         success: function (data) {
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").empty(); // Empty weather symbol
         							liveTxt[0].fadeOut(0);
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("lapCounter").fadeOut(0);
         						if(data){	
         							if (data[0].n_WeatherConditionType!=null){
         							var weather = '<img src="images/weather'+ data[0].n_WeatherConditionType +'.png" width="24px" height="24px">';
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").append(weather); // Add weather symbol
         							liveTxt[2].fadeIn(0);					
         							}else{
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").empty();
         							liveTxt[2].fadeOut(0);
         							}
         							var sessionNo=(data[0].n_SessionNr>0)?data[0].n_SessionNr:"";
         							//Angle per lap:
         								var laps = data[0].n_LapsScheduled;
         								var lapsDriven = data[0].n_LapsDriven;
         								var lapsAngle = 360*lapsDriven/laps;
         								liveTxt[0].html(txtArr[0]+" <b>"+lapsDriven+"/"+laps+"</b>");
         								if (lapsDriven/laps<0.5){
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps1").animate({rotate:lapsAngle},{
         										step: function(now,fx) {
         										$(this).css('-webkit-transform','rotate('+now+'deg)');
         										$(this).css('-moz-transform','rotate('+now+'deg)'); 
         										$(this).css('-ms-transform','rotate('+now+'deg)'); 
         										$(this).css('-op-transform','rotate('+now+'deg)'); 
         										$(this).css('transform','rotate('+now+'deg)');
         										},duration:'fast'},'linear');
         								}else if (lapsDriven/laps>=0.5){
         										sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps1").animate({rotate:180},{
         										step: function(now,fx) {
         										$(this).css('-webkit-transform','rotate(180deg)');
         										$(this).css('-moz-transform','rotate(180deg)'); 
         										$(this).css('-moz-transform','rotate(180deg)'); 
         										$(this).css('-ms-transform','rotate(180deg)');
         										$(this).css('-op-transform','rotate(180deg)');
         										$(this).css('transform','rotate(180deg)');
         										},duration:'fast'},'linear');
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps2").show();
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps2").animate({rotate:lapsAngle},{
         										step: function(now,fx) {
         										$(this).css('-webkit-transform','rotate('+now+'deg)');
         										$(this).css('-moz-transform','rotate('+now+'deg)'); 
         										$(this).css('-ms-transform','rotate('+now+'deg)'); 
         										$(this).css('-op-transform','rotate('+now+'deg)'); 
         										$(this).css('transform','rotate('+now+'deg)');
         										},duration:'fast'},'linear');
         								}	
         							sym.getSymbol("styleHead").$("menuBtn1").off("touchstart click");
         							clearInterval(raceInterval);
         							if (data[0].b_FreePractice==true){
         								sym.getSymbol("styleHead").$("menuBtn1").on("touchstart click", {menuId:1,"phaseLive":0,"sessionLive":sessionNo}, menuBtnClick);
         								liveTxt[1].html(txtArr[4]);
         								liveTxt[9].html(statCap[0] + " "+ sessionNo);
         								phaseNo=0;	
         								showMc=1;
         							}else if(data[0].b_Qualifying==true){
         								sym.getSymbol("styleHead").$("menuBtn1").on("touchstart click", {menuId:1,"phaseLive":1,"sessionLive":sessionNo}, menuBtnClick);
         								liveTxt[1].html(txtArr[4]);
         								liveTxt[9].html(statCap[1] + " "+ sessionNo);
         								phaseNo=1;
         								showMc=1;
         							}else if(data[0].b_StartingGrid==true){
         								sym.getSymbol("styleHead").$("menuBtn1").on("click touchstart", {menuId:1,"phaseLive":2,"sessionLive":0}, menuBtnClick);
         								phaseNo=2;
         								showMc=1;
         								gridPhase=phaseID;
         							}else if(data[0].b_Race==true){				
         								phaseNo=2;
         								sym.getSymbol("styleHead").$("menuBtn1").on("touchstart click", {menuId:1,"phaseLive":2,"sessionLive":1}, menuBtnClick);
         								liveTxt[1].html(txtArr[1]);
         								liveTxt[11].fadeIn(0);
         								liveTxt[0].fadeIn(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("lapCounter").fadeIn(0);
         								if (data[0].b_Finished==true){
         									liveTxt[9].html(txtArr[6]);
         									showMc=2;
         								}else{
         									liveTxt[9].html(txtArr[5]);
         									showMc=1;
         								}				
         							}else{
         								sym.getSymbol("styleHead").$("menuBtn1").on("touchstart click", {menuId:1,"phaseLive":0,"sessionLive":1}, menuBtnClick);
         								liveTxt[1].html(txtArr[4]);
         								liveTxt[9].html(statCap[0]);
         								liveTxt[0].html(txtArr[0]);
         								liveTxt[0].fadeIn(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").empty(); // Empty weather symbol
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").append('<img src="images/weather1.png" width="24px" height="24px">');	
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("lapCounter").fadeIn(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps1").fadeOut(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps2").fadeOut(0);	
         								showMc=0;
         							}
         							if (data[0].b_Finished==true){
         								raceInterval=setInterval(getRace,300000);
         							}else if (data[0].b_Started==true){
         								raceInterval=setInterval(getRace,45000);
         							}else{
         								raceInterval=setInterval(getRace,300000);
         							}
         			}else{
         								sym.getSymbol("styleHead").$("menuBtn1").on("touchstart click", {menuId:1,"phaseLive":0,"sessionLive":1}, menuBtnClick);
         								liveTxt[1].html(txtArr[4]);
         								liveTxt[9].html(statCap[0]);
         								liveTxt[0].html(txtArr[0]);
         								liveTxt[0].fadeIn(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").empty(); // Empty weather symbol
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("weather").append('<img src="images/weather1.png" width="24px" height="24px">');	
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("lapCounter").fadeIn(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps1").fadeOut(0);
         								sym.getSymbol("liveMc").getSymbol("latestMc").getSymbol("lapCounter").$("laps2").fadeOut(0);	
         								showMc=0;
         			}
         		}
         	});
         }
         
         //GET Start list if race hasn't started
         function getStartList(){
         $.ajax({ type: "GET", 
         						url: dataURL,
                         data: "gn="+gnNo+"&yr="+yearNo+"&q=startlist&race=",
                         contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                         async: true,
                         crossDomain: true,
                         success: function (data) {
         						var startData=data;
         						if(startData.length>0){	
         							 if (startData.length>18){
         								barHeight = Math.floor((420/startData.length)-(40/startData.length)); // to allow for more than 20 starters
         							 }else{
         								barHeight = 21;
         							 }
         							for (var i=0; i<startData.length; i++){
         								if(i==0){ //show lead driver details
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("graph").empty();
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").empty();
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").empty();
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("carPic").empty();
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").empty();
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").empty();
         								var imgHelmet = '<img src="drivers/'+ startData[i].n_PersonID +'.png" width="105px" height="82px">';
         								var imgDriver = '<img src="drivers/'+ startData[i].n_PersonID +'.jpg" width="105px">';
         								var imgCar = '<img src="cars/'+ startData[i].c_TeamShort +'.png" width="330px">';
         								var leadDriver = '<b>' +startData[i].c_Person+ '</b> <span style="font-size:12px"><i>' +startData[i].c_NOCShort+ '</i></span>';
         								liveTxt[5].html(leadDriver);
         								var conText=(startData[i].c_ConstructorTeam=="RedBull - Renault")?"Red Bull - Renault":startData[i].c_ConstructorTeam;
         								liveTxt[6].text(conText);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").append(imgHelmet);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").append(imgDriver);
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("carPic").append(imgCar);
         								}
         								//create graph for each driver and for final results
         								var tableText ="<div class='race'>";
         								tableText += "<div id='driverdata"+i+"'>";
         								tableText += "<table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr>";
         								tableText += "<td id='driverNo"+i+"'></td>";
         								tableText += "<td id='driver"+i+"'width='130px'></td>";
         								tableText += "<td id='team"+i+"' style='font-style:italic' width='35px'></td>";
         								tableText += "<td id='pitstops"+i+"' style='font-weight:bold' width='20px'></td>";
         								tableText += "</tr></table>";
         								tableText += "</div></div>";
         								sym.getSymbol("liveMc").getSymbol("latestMc").$("graph").append(tableText);
         
         								$('#driver' + i).text(startData[i].c_Person);
         								$('#team' + i).text(startData[i].c_TeamShort);
         								$('#pitstops' + i).text("0");
         								$('#pitstops' + i).css({'font-weight':'bold','text-align':'center','color':'rgb(255,255,255)','background-color':'rgba(0,0,0,0.15)'});
         								$('#driverNo' + i).text(startData[i].c_ShirtNr);
         								var fontSize=(barHeight>15)?13:barHeight-3;
         								$(".race").css({'font-size':fontSize+'px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'margin-bottom':Math.round(40/startData.length)});
         								$("#driverNo" + i).css({'width':'10%','padding-right':'5px'});	
         								barHeight=(barHeight>15)?barHeight:fontSize+3;			
         								$("#driverdata" + i).css({'height':barHeight+'px','width':'55%','background-color':'rgb(230,225,215)','padding-left':'5px', 'box-shadow':'3px 2px 5px rgba(100,100,100,0.75)'});
         							}
         						}else{
         							//disable button
         								sym.getSymbol("styleHead").$("menuBtn1").off("touchstart click");
         						}
         		}
         	});
         }
         //GET individual phase data for live and final result
         function getLive(phaseID) { 
          $.ajax({ type: "GET", 
         					 url: dataURL,
                         data: "gn="+gnNo+"&yr="+yearNo+"&race="+phaseID,
                         contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                         async: true,
                         crossDomain: true,
                         success: function (data) {
                           raceData = data;
         					 //Ensure all drivers will fit in graph
         					 nRaceDrivers = raceData.length;
         					 if (raceData.length>18){
         					 barHeight = ((420/raceData.length)-2);
         					 }else{
         					 barHeight = 21;
         					 }
         					 //calculate relative length of each bar
         					if (raceStage =="R"){
         					minTime = raceData[0].n_TimeRel;
         					var mxm = (minTime!=null) ? minTime : 0;
         								var timeRel = 0;	
         								for (var n=0; n<raceData.length; n++) {
         									if (raceData[n].n_TimeRel!=null && raceData[n].n_TimeRel>mxm) {
         									mxm = raceData[n].n_TimeRel;
         									}
         								}
         					}else if (raceData[0].n_TimeAbs!=undefined){//during other phases	
         					minTime = raceData[0].n_TimeAbs; 
         					var mxm = (minTime!=null) ? minTime : 0;
         					var timeRel = 1;
         								for (var n=0; n<raceData.length; n++) {
         									if (raceData[n].n_TimeAbs!=null && raceData[n].n_TimeAbs>mxm) {
         									mxm = raceData[n].n_TimeAbs;									
         									}
         									if (raceData[n].n_TimeAbs!=null && raceData[n].n_TimeAbs<minTime) {
         									minTime = raceData[n].n_TimeAbs;									
         									}
         								}
         					}
         					sym.getSymbol("resultsMc").$("graph").empty();
         					sym.getSymbol("resultsMc").$("helmetPic").empty();					
         					sym.getSymbol("resultsMc").$("driverPic").empty();					
                        for (var i = 0; i < raceData.length; i++) {
         						if(i==0){ //show lead driver details
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("graph").empty();
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").empty();
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").empty();
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("carPic").empty();
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").empty();
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").empty();
         							var imgHelmet = '<img src="drivers/'+ raceData[i].n_PersonID +'.png" width="105px" height="82px">';
         							var imgDriver = '<img src="drivers/'+ raceData[i].n_PersonID +'.jpg" width="105px">';
         							var imgCar = '<img src="cars/'+ raceData[i].c_TeamShort +'.png" width="330px">';
         							var leadDriver = '<b>' +raceData[i].c_Person+ '</b> <span style="font-size:12px"><i>' +raceData[i].c_NOCShort+ '</i></span>';
         							liveTxt[5].html(leadDriver);
         							liveTxt[6].text(raceData[i].c_ConstructorTeam);
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("helmetPic").append(imgHelmet);
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("driverPic").append(imgDriver);
         							sym.getSymbol("liveMc").getSymbol("latestMc").$("carPic").append(imgCar);
         							sym.getSymbol("resultsMc").$("helmetPic").append(imgHelmet);
         							sym.getSymbol("resultsMc").$("driverPic").append(imgDriver);
         							resTxt[5].html(leadDriver);
         						}
         					//create graph for each driver and for final results
         					var tableText ="<div class='race'>";
         					tableText += "<div id='driverdata"+i+"'>";
         					tableText += "<table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr>";
         					tableText += "<td id='driver"+i+"'width='130px'></td>";
         					tableText += "<td id='team"+i+"' style='font-style:italic' width='35px'></td>";
         					tableText += "<td id='pitstops"+i+"' style='font-weight:bold' width='20px'></td>";
         					tableText +="<td id='time"+i+"'></td>";
         					tableText += "</tr></table>";
         					tableText += "</div></div>";
         
         					var resultsText ="<div class='resultrace'>";
         					resultsText += "<div id='resultdata"+i+"'>";
         					resultsText += "<table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr>";
         					resultsText += "<td id='resultorder"+i+"' width='20px'></td>";
         					resultsText += "<td id='resultdriver"+i+"' width='140px'></td>";
         					resultsText += "<td id='resultteam"+i+"' style='font-style:italic' width='30px'></td>";
         					resultsText += "<td id='points"+i+"'></td>";
         					resultsText += "</tr></table>";
         					resultsText += "</div>";
         					resultsText += "</div>";					
         
         					sym.getSymbol("liveMc").getSymbol("latestMc").$("graph").append(tableText);
         					 $('#driver' + i).text(raceData[i].c_Person);
                         $('#team' + i).text(raceData[i].c_TeamShort);
                         if (raceData[i].n_PitStops){
                         $('#pitstops' + i).text(raceData[i].n_PitStops);
                         $('#pitstops' + i).css({'font-weight':'bold','text-align':'center','color':'rgb(255,255,255)','background-color':'rgba(0,0,0,0.15)'});
                         }
         
                        if (timeRel==1){
         						var hrs =(raceData[i].n_TimeAbs>3600000)?Math.floor(raceData[i].n_TimeAbs/3600000)+":":"";
         						var mins=(raceData[i].n_TimeAbs>3600000)?Math.floor((raceData[i].n_TimeAbs%3600000)/60000):Math.floor(raceData[i].n_TimeAbs/60000);
         						if (mins<10){
         							mins="0"+mins+":";
         						}else if(mins<1){
         							mins="00:";
         						}else{
         							mins=mins+":";
         						}
         						var secs=(raceData[i].n_TimeAbs>3600000)?(raceData[i].n_TimeAbs%3600000%60000)/1000:(raceData[i].n_TimeAbs%60000%60000)/1000;
         						if (secs<10){
         							secs="0"+secs;
         						}
         						var timing = hrs+mins+secs;
         						$('#time' + i).text(timing);
         						if (minTime==mxm && raceData[i].n_TimeAbs==mxm) {	//if minTime=mxm=item Time that means that there is just 1 item with valid time. show this graph as max
         							scale=100;
         						}else if(raceData[i].n_TimeAbs==null){
         							scale=57;
         						}else{
         							scale = 100-((raceData[i].n_TimeAbs-minTime)*43/(mxm-minTime));
         						}	
         
         					}else if (timeRel==0){
         						if(raceData[i].n_RankSort==1&&raceData[i].n_TimeAbs==null){
         							scale=100;
         							$('#time' + i).text();
         						}else if(raceData[i].n_TimeRel==null){						
         						scale=57;
         							if (raceData[i].c_ResultSuffix==null){
         							}else{
         								$('#time' + i).text(raceData[i].c_ResultSuffix);
         							}
         						}else{
         						scale = 100-(raceData[i].n_TimeRel*43/mxm);
         						$('#time' + i).text(raceData[i].c_Result);
         						}
         			}
         					$(".race").css({'font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'margin-bottom':'2px'});
         					$("#driverdata" + i).css({'height':barHeight+'px','width':scale+'%','background-color':'rgb(230,225,215)','padding-left':'5px', 'box-shadow':'3px 2px 5px rgba(100,100,100,0.75)'});
         					$("#time" + i).css({'text-align':'right', 'padding-right':'5px'});					
         					if (raceFinished==1){ //final results only
         					sym.getSymbol("resultsMc").$("graph").append(resultsText);	
         					sym.getSymbol("resultsMc").$("car"+i).empty();				
         					resultCar = '<img src="cars/'+ raceData[i].c_TeamShort +'o.png" width="30px">';
         					order = raceData[i].n_RankSort;
         					if (raceData[i].c_ChampionshipPoints!=undefined){
         					points = raceData[i].c_ChampionshipPoints;
         					}else{
         					points=0;
         					}
         					if (order<11){
         						scaleresult= 94-(i*6);
         					}else{
         						scaleresult= 37;						
         					}					
         					$('#resultorder' + i).html("<b>"+order+"</b>");
         					$('#resultdriver' + i).text(raceData[i].c_Person);
                        $('#resultteam' + i).text(raceData[i].c_TeamShort);
         					$('#points' + i).html("<b>"+points+"</b>");
         					$(".resultrace").css({'font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'margin-bottom':'2px'});
         					$("#resultdata"+i).css({'height':barHeight+'px','width':scaleresult+'%','background-color':'rgb(230,225,215)','box-shadow':'3px 2px 5px rgba(100,100,100,0.75)', 'padding-left':'3px'});
         					$("#points" + i).css({'text-align':'right', 'padding-right':'5px'});
         
         					sym.getSymbol("resultsMc").$("car"+i).append(resultCar);
         					}
                      }
         				menuTxt[1].html(menuTxtArr[1]);
                   }			
         		});
         }
         
         var scalePhase;
         function getPhases(phaseID){
         
         sym.getSymbol("liveMc").$("loader-bar").fadeIn(0);				
         
         $.ajax({ type:"GET",
         			url:dataURL,
         			data:  "gn="+gnNo+"&yr="+yearNo+"&race="+phaseID,
                  contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                  async: true,
                  crossDomain: true,
                  success: function (data) {
         					sym.getSymbol("liveMc").$("loader-bar").fadeOut(0);				
         					var phaseData = data;
         					sym.getSymbol("liveMc").getSymbol("timingMc").$("graph").empty();
         					sym.getSymbol("liveMc").getSymbol("timingMc").$("helmetPic").empty();
         					sym.getSymbol("liveMc").getSymbol("timingMc").$("driverPic").empty();
         					sym.getSymbol("liveMc").getSymbol("timingMc").$("carPic").empty();
         					menuTxt[2].html(menuTxtArr[2]);
         					//Ensure all drivers will fit in graph
         					 if (phaseData.length>18){
         					 barHeight = (420/phaseData.length)-2;
         					 }else{
         					 barHeight = 21;
         					 }
         					 minTime = phaseData[0].n_TimeAbs;
         					 var max = (minTime!=null) ? minTime : 0;
         								for (var n=0; n<phaseData.length; n++) {
         									if (phaseData[n].n_TimeAbs!=null && phaseData[n].n_TimeAbs>max) {
         									max = phaseData[n].n_TimeAbs;
         									}
         									if (phaseData[n].n_TimeAbs!=null && phaseData[n].n_TimeAbs<minTime) {
         									minTime = phaseData[n].n_TimeAbs;									
         									}
         								}
                        for (var i = 0; i < phaseData.length; i++) {
         							if(i==0){					
         							var imgHelmet = '<img src="drivers/'+ phaseData[i].n_PersonID +'.png" width="105px" height="82px">';
         							var imgDriver = '<img src="drivers/'+ phaseData[i].n_PersonID +'.jpg" width="105px">';
         							var imgCar = '<img src="cars/'+ phaseData[i].c_TeamShort +'.png" width="330px">';
         							var leadDriver = '<b>' +phaseData[i].c_Person+ '</b> <span style="font-size:12px"><i>' +phaseData[i].c_NOCShort+ '</i></span>';
         							liveTxt[7].html(leadDriver);
         							liveTxt[8].text(phaseData[i].c_ConstructorTeam);
         							sym.getSymbol("liveMc").getSymbol("timingMc").$("helmetPic").append(imgHelmet);
         							sym.getSymbol("liveMc").getSymbol("timingMc").$("driverPic").append(imgDriver);
         							sym.getSymbol("liveMc").getSymbol("timingMc").$("carPic").append(imgCar);
         							}			
         					var phaseText ="<div class='phaserace'>";
           					phaseText += "<div id='phasedriverdata"+i+"'>";
           					phaseText += "<table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr>";
           					phaseText +="<td id='phasedriver"+i+"' style='width:150px'></td>";
         					phaseText +="<td id='phaseteam"+i+"' style='font-style:italic' width='40px'></td>";
           					phaseText +="<td id='phasetime"+i+"'></td>";
           					phaseText +="</tr></table>";
         					phaseText +="</div>";
         					phaseText +="</div>";
         					sym.getSymbol("liveMc").getSymbol("timingMc").$("graph").append(phaseText);
         					$('#phasedriver' + i).text(phaseData[i].c_Person);
                        $('#phaseteam' + i).text(phaseData[i].c_TeamShort);
         
                        var mins=Math.floor(phaseData[i].n_TimeAbs/60000)+":";
         					var secs=(phaseData[i].n_TimeAbs%60000%60000)/1000;
         					if (secs<10){
         						secs="0"+secs;
         					}
         					$('#phasetime' + i).text(mins+secs);
         					if (minTime==max && phaseData[i].n_TimeAbs==max) {	//if minTime=mxm=item Time that means that there is just 1 item with valid time. show this graph as max
         						scalePhase=100;
         					}else if(phaseData[i].n_TimeAbs==null){
         						scalePhase=59;
         					}else{
         						scalePhase = 100-((phaseData[i].n_TimeAbs-minTime)*41/(max-minTime));
         					}
         					$(".phaserace").css({'font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'margin-bottom':'2px'});
         					$("#phasedriverdata"+i).css({'height':barHeight+'px','width':scalePhase+'%','background-color':'rgb(230,225,215)','box-shadow':'3px 2px 5px rgba(100,100,100,0.75)',});
         					$("#phasetime" + i).css({'text-align':'right', 'padding-right':'5px'});
         					}
                     }
         		});
         }
         // GRID BUTTON
         function getGrid(phaseID){
         $.ajax({ type:"GET",
         			url:dataURL,
         			data:  "gn="+gnNo+"&yr="+yearNo+"&race="+phaseID,
                  contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                  async: true,
                  crossDomain: true,
                  success: function (data) {
                  var gridData = data;
         				var gridMove;
         				var go;
         				for (var i = 0; i < gridData.length; i++) {
         					sym.getSymbol("liveMc").getSymbol("gridMc").$("grid"+i).empty();												
         					var gridText ="<div class='gridlist'><table style='width:100%; border:none; border-collapse:collapse; padding:0; margin:0'><tr><td id='gridorder"+i+"' width='10%'></td><td id='griddriver"+i+"' width='62%'></td><td id='gridteam"+i+"' width='28%' font-style:italic'></td></tr></table></div>";
         					if (i<12){
         					sym.getSymbol("liveMc").getSymbol("gridMc").$("grid1txt").append(gridText);
         					}else{
         					sym.getSymbol("liveMc").getSymbol("gridMc").$("grid2txt").append(gridText);
         					}
         					var gridCar = '<img src="cars/'+ gridData[i].c_TeamShort +'o.png" width="24px">';
         					var order = gridData[i].n_RankSort;
         					$('#gridorder' + i).html("<b>"+order+"</b>");
         					$('#griddriver' + i).text(gridData[i].c_Person);
         					$('#gridteam' + i).text(gridData[i].c_TeamShort);
         					$(".gridlist").css({'font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%', 'height':'35px'});
         					sym.getSymbol("liveMc").getSymbol("gridMc").$("grid"+i).append(gridCar);
         					if (i<12){
         					go = i;
         					}else{
         					go = i-12;
         					}
         					if (i%2==0){
         					gridMove=5+go*35;
         					}else{
         					gridMove=-15+go*35;
         					}
         					sym.getSymbol("liveMc").getSymbol("gridMc").$("grid"+i).delay(i*400).animate({'top':gridMove}, 1000);								
         				}
                  }
               });
         }
         function getStandings(){
         $.ajax({ type:"GET",
         			url:dataURL,
         			data:  "gn="+gnNo+"&q=champdrivers&yr="+yearNo+"&race=",
                  contentType: "text/plain", dataType: "jsonp", jsonp: "callback",
                  async: true,
                  crossDomain: true,
                  success: function (data) {
         					var rankData = data;
                        for (var i = 0; i < rankData.length; i++) {
         						if (i<10){
         							if (i%2 == 0){
         							var rankText ="<div class='rankingeven'><table style='width:98%; border:none; border-collapse:collapse; padding:0; margin:0'><tr><td id='rank"+i+"' width='20%'></td><td id='rankdriver"+i+"' width='55%' style='font-weight:600'></td><td id='rankpoints"+i+"' width='20%' style='text-align:right; font-style:italic'></td></tr></table></div>";
         							}else{
         							var rankText ="<div class='rankingodd'><table style='width:98%; border:none; border-collapse:collapse; padding:0; margin:0'><tr><td id='rank"+i+"' width='20%'></td><td id='rankdriver"+i+"' width='55%' style='font-weight:600'></td><td id='rankpoints"+i+"' width='20%' style='text-align:right; font-style:italic'></td></tr></table></div>";							
         							}					
         						}
         					sym.getSymbol("resultsMc").$("standings").append(rankText);
         					$('#rank' + i).text(rankData[i].n_RankSort);		
         					$('#rankdriver' + i).text(rankData[i].c_PersonShort);		
         					$('#rankpoints' + i).text((rankData[i].n_PointsSort)/1000);
         					$(".rankingeven").css({'background-color':'rgb(150,210,255)','font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%'});
         					$(".rankingodd").css({'background-color':'rgb(213,239,255)','font-size':'13px', 'font-family':'pragmatica-web, sans-serif', 'width':'100%'});
                        }										
         			}
         	});
         }
         // CIRCUIT BUTTONS & TIMELINE FUNCTIONS
         sym.gearChange = function(gearIn,gearOut,duration) {
         					sym.$({countNum: gearIn}).animate({countNum: gearOut}, {
         						duration: duration,
         						easeOut:'cubic',
         						step: function() {
         						 sym.getSymbol("circuitMc").$("gear").text(Math.round(this.countNum));
         						},
         					});
         }
         sym.speedChange = function(speedIn,speedOut,duration) {
         					sym.$({countNum: speedIn}).animate({countNum: speedOut}, {
         					  duration: duration,
         					  easeOut:'cubic',
         					  step: function() {
         						 sym.getSymbol("circuitMc").$("speed").html(Math.round(this.countNum));
         					  },
         					});			
         }
         
         var mcArr=['circuitMc','liveMc','resultsMc','winnersMc'];
         function startPanel(){
         	for (var i=0; i<3; i++){
         		if(showMc==i){	
         			sym.$(mcArr[i]).fadeIn(1000);
         			sym.getSymbol("styleHead").getSymbol("menuBtn" + i).$("btnClick").fadeIn(0);
         			if (i==0){
         				//setTimeout( playIt, 2850);
         				playTime=setTimeout(playIt,2850);//
         			}else if(i==1){
         			//show grid
                  					if(gridPhase>0){
                  						sym.getSymbol("liveMc").$("gridMc").fadeIn(1000);
                  						sym.getSymbol("liveMc").$("timingMc").fadeOut(0);
                  						sym.getSymbol("liveMc").$("latestMc").fadeOut(0);
                  						getGrid(gridPhase);
                  					}else{
                  						sym.getSymbol("liveMc").getSymbol("latestMc").$("leadDriver").delay(500).fadeIn(1000);
                  						setTimeout(startPanel,2000);
                  					}
         			}else if(i==2){
         				for (m=0; m<10; m++){
         					var carMove=43+m*420/nRaceDrivers;//height divided by number of drivers
         					sym.getSymbol("resultsMc").$("car"+m).animate({'top':carMove}, 1000);
         				}
         			}
         		}else{
         			sym.$(mcArr[i]).fadeOut(1000);
         			sym.getSymbol("styleHead").getSymbol("menuBtn" + i).$("btnClick").fadeOut(0);
         		}			
         	}
         }
         //startPanel();
         setTimeout(startPanel,2000);
         $('img').on('dragstart',function(e){ e.preventDefault(); }); //make images undraggable
         $('img').attr('draggable',false); //make images undraggable

      });
      //Edge binding end

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

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

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

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

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

   //=========================================================

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

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

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

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

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

   //=========================================================

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

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

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

   //=========================================================

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

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

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

   //=========================================================
   
   //Edge symbol: 'Down-level'
   (function(symbolName) {   
   
   })("Down-level");
   //Edge symbol end:'Down-level'

   //=========================================================

   //=========================================================

   //=========================================================
   
   //Edge symbol: 'flatmap_two'
   (function(symbolName) {   
   
   })("flatmap-two");
   //Edge symbol end:'flatmap-two'

   //=========================================================
   
   //Edge symbol: 'Intro'
   (function(symbolName) {   
   
      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 0, function(sym, e) {
         sym.getComposition().getStage().lat();

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 2500, function(sym, e) {
         sym.getSymbol("wheelMc").stop();
         sym.getComposition().getStage().fadeIt();

      });
      //Edge binding end

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

   //=========================================================
   
   //Edge symbol: 'Symbol_1'
   (function(symbolName) {   
         

   })("continents-animation");
   //Edge symbol end:'continents-animation'

   //=========================================================
   
   //Edge symbol: 'wheelMc'
   (function(symbolName) {   
   
      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 633, function(sym, e) {
         sym.play(500);

      });
      //Edge binding end

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

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

   //=========================================================
   
   //Edge symbol: 'globe'
   (function(symbolName) {   
   
      

      

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

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

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

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

   //=========================================================

   //=========================================================

   //=========================================================
   
   //Edge symbol: 'carMc'
   (function(symbolName) {   
   
      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 1000, function(sym, e) {
         sym.play();

      });
      //Edge binding end

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

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

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

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

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

   //=========================================================
   
   //Edge symbol: 'circuitMc'
   (function(symbolName) {   
   
      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 15000, function(sym, e) {
         sym.stop();
         var mySymbolObject = sym.getSymbol("carMc").stop(1);
         sym.$("speed").html("290");
         sym.getComposition().getStage().stopIt();

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 41, function(sym, e) {
         sym.getComposition().getStage().speedChange(20,305,700);
         sym.getComposition().getStage().gearChange(1,7,700);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 750, function(sym, e) {
         sym.getComposition().getStage().speedChange(305,255,250);
         sym.getComposition().getStage().gearChange(7,5,250);

      });
      //Edge binding end

      

      

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 1500, function(sym, e) {
         sym.getComposition().getStage().speedChange(285,120,600);
         sym.getComposition().getStage().gearChange(46,2,600);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 2150, function(sym, e) {
         sym.getComposition().getStage().speedChange(120,90,450);
         sym.getComposition().getStage().gearChange(2,2,450);

      });
      //Edge binding end

      

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 3350, function(sym, e) {
         sym.getComposition().getStage().speedChange(256,300,650);
         sym.getComposition().getStage().gearChange(6,7,650);

      });
      //Edge binding end

      

      

      

      

      

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 1000, function(sym, e) {
         sym.getComposition().getStage().speedChange(255,285,500);
         sym.getComposition().getStage().gearChange(5,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 4000, function(sym, e) {
         sym.getComposition().getStage().speedChange(300,320,500);
         sym.getComposition().getStage().gearChange(7,7,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 4500, function(sym, e) {
         sym.getComposition().getStage().speedChange(320,180,400);
         sym.getComposition().getStage().gearChange(7,4,400);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 5250, function(sym, e) {
         sym.getComposition().getStage().speedChange(140,125,250);
         sym.getComposition().getStage().gearChange(3,3,250);

      });
      //Edge binding end

      

      

      

      

      

      

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 4900, function(sym, e) {
         sym.getComposition().getStage().speedChange(180,140,500);
         sym.getComposition().getStage().gearChange(4,3,500);

      });
      //Edge binding end

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 5500, function(sym, e) {
         sym.getComposition().getStage().speedChange(125,195,250);
         sym.getComposition().getStage().gearChange(3,4,250);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 9500, function(sym, e) {
         sym.getComposition().getStage().speedChange(270,170,700);
         sym.getComposition().getStage().gearChange(6,4,700);

      });
      //Edge binding end

      

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 10200, function(sym, e) {
         sym.getComposition().getStage().speedChange(170,280,500);
         sym.getComposition().getStage().gearChange(4,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 10750, function(sym, e) {
         sym.getComposition().getStage().speedChange(280,325,1500);
         sym.getComposition().getStage().gearChange(6,7,1500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 12250, function(sym, e) {
         sym.getComposition().getStage().speedChange(325,180,500);
         sym.getComposition().getStage().gearChange(7,4,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 12750, function(sym, e) {
         sym.getComposition().getStage().speedChange(180,235,250);
         sym.getComposition().getStage().gearChange(4,5,250);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 13000, function(sym, e) {
         sym.getComposition().getStage().speedChange(235,280,500);
         sym.getComposition().getStage().gearChange(5,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 13500, function(sym, e) {
         sym.getComposition().getStage().speedChange(280,110,400);
         sym.getComposition().getStage().gearChange(6,3,400);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 14250, function(sym, e) {
         sym.getComposition().getStage().speedChange(130,225,250);
         sym.getComposition().getStage().gearChange(3,5,250);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 2600, function(sym, e) {
         sym.getComposition().getStage().speedChange(90,256,750);
         sym.getComposition().getStage().gearChange(2,6,750);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 5750, function(sym, e) {
         sym.getComposition().getStage().speedChange(195,280,500);
         sym.getComposition().getStage().gearChange(4,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 6250, function(sym, e) {
         sym.getComposition().getStage().speedChange(280,295,500);
         sym.getComposition().getStage().gearChange(6,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 6750, function(sym, e) {
         sym.getComposition().getStage().speedChange(295,310,500);
         sym.getComposition().getStage().gearChange(6,7,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 7250, function(sym, e) {
         sym.getComposition().getStage().speedChange(310,255,250);
         sym.getComposition().getStage().gearChange(7,6,250);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 7500, function(sym, e) {
         sym.getComposition().getStage().speedChange(255,265,500);
         sym.getComposition().getStage().gearChange(6,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 8000, function(sym, e) {
         sym.getComposition().getStage().speedChange(265,290,500);
         sym.getComposition().getStage().gearChange(6,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 8500, function(sym, e) {
         sym.getComposition().getStage().speedChange(290,305,500);
         sym.getComposition().getStage().gearChange(6,7,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 9000, function(sym, e) {
         sym.getComposition().getStage().speedChange(305,270,500);
         sym.getComposition().getStage().gearChange(7,6,500);

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 13900, function(sym, e) {
         sym.getComposition().getStage().speedChange(110,130,350);
         sym.getComposition().getStage().gearChange(3,3,350);
         

      });
      //Edge binding end

      Symbol.bindTriggerAction(compId, symbolName, "Default Timeline", 14500, function(sym, e) {
         sym.getComposition().getStage().speedChange(225,280,500);
         sym.getComposition().getStage().gearChange(5,6,500);

      });
      //Edge binding end

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

})(window.jQuery || AdobeEdge.$, AdobeEdge, "GraphicNews32723");