$(document).ready(function(){ 
        var i = 0;
        var n = 0;
        $.getJSON("/_inc/countdown-times.php",function(data){
            //window.console.log(data[0].date);
            var starttime = new Date(data[i].date.start);
            var endtime = new Date(data[i].date.end);
            var curtime = new Date(); 
            
            var lbs = ["YR","MO", "WK", "DAYS","HRS","MIN","SEC"];
            //accounts for events in data that have already happened or are happening
            if(curtime < endtime && curtime > starttime){
			    $('#countdown').addClass('live');
			    $('#countdown #intro').text('Service Is Currently Live!');
			  // $("selector").colorbox({ other_key:other_value, open: true});
            }else if(curtime > endtime){
                n = n + 1;
                starttime = new Date(data[n].date.start);
              //window.console.log("NOT LIVE");
              $("#clock").countdown({until:starttime, format:'dHM', onExpiry:setNext, labels:lbs,labels1:lbs});  
            }else{
               $("#clock").countdown({until:starttime, format:'dHM', layout: '{dn} <span>days</span> {hn} <span>hrs</span> {mn} <span>min &ndash; </span>', onExpiry:setNext});     
            }
            
             function setNext(){
                 if(n===i){
					 $('#countdown').addClass('live');
			   		 $('#countdown #intro').text('Service Is Currently Live!');
                 }else{
                    $("#clock").countdown('change',{until:starttime, format:'dHM', layout: '{dn} <span>days</span> {hn} <span>hrs</span> {mn} <span>min &ndash; </span>', onExpiry:setNext}); 
                    endtime = new Date(data[n].date.end);
                    i = n;
                 }
             }
        });
    });
