$(document).ready(function(){
	//dbrf - Daily Briefing
	if ($(".dbrf .double").length*2 + $(".dbrf .single").length > 4) {
		$("<div class='navbtn'></div>").insertAfter(".dbrf h2");
		$(".dbrf .double").wrap("<div class='toutDiv'></div>");
		for (var i=0; i < 3; i++) {
			$(".dbrf2 > .single:lt(2)").wrapAll("<div class='toutDiv'></div>");
		}
		$(".dbrf .double").parents(".dbrf2").addClass("withDouble");
		$(".dbrf h3 + .tout").addClass("first");
		$("<a><img src='http://img.timeinc.net/time/rd/trunk/www/web/feds/i/btn_prev.gif' alt='Previous' /></a>").appendTo(".dbrf .navbtn").bind("click", function(){
			$(".dbrf2 .toutDiv:last").prependTo(".dbrf2");
			var bgPosX = $(".double").parent(".toutDiv").prevAll(".toutDiv").length * 316;
			$(".dbrf2").css("margin-left", "-316px").css("background-position", bgPosX  + "px 0").animate({marginLeft:"0"}, 1000);
		});
		$("<a><img src='http://img.timeinc.net/time/rd/trunk/www/web/feds/i/btn_next.gif' alt='Next' /></a>").appendTo(".dbrf .navbtn").bind("click", function(){
			$(".dbrf2").animate({marginLeft:"-316px"}, 1000, function(){
				$(".dbrf2 .toutDiv:first").insertBefore(".dbrf2 .end");
				var bgPosX = $(".double").parent(".toutDiv").prevAll(".toutDiv").length * 316;
				$(".dbrf2").css("margin-left", "0").css("background-position", bgPosX  + "px 0");
			});
		});
	}
});

/* Begin TimeStamp function */
function renderTimestamp(year,month,day,hour,minutes,seconds) 
{
    var aYear = new String(year);
    var aMonth = new String(month);
    var aDay = new String(day);
    var aHour = new String(hour); 
    var aMinutes = new String(minutes);
    var aSeconds = new String(seconds); 
    articleUTC = Date.UTC(aYear, aMonth, aDay, aHour, aMinutes, aSeconds);

    /* this is EST timezone offset of 5 hours = 300 minutes
    all Time articles are published in EST */
    articleTZOffsetMS = 300 * 60 * 1000 ; 
    articleCorrectedMS = articleUTC + articleTZOffsetMS;

    localDate = new Date();
    localYear = localDate.getFullYear();
    localMonth = localDate.getMonth(); 
    localDay = localDate.getDate(); 
    localHour = localDate.getHours();
    localMinutes = localDate.getMinutes();
    localSeconds = localDate.getSeconds();
    localTZOffset = localDate.getTimezoneOffset();
    //localTZOffsetMS = localTZOffset * 1000* 60; 
    localTZOffsetMS = 300 * 1000* 60;
	localUTC = Date.UTC(localYear, localMonth, localDay, localHour, localMinutes, localSeconds); 

    localCorrectedMS = localUTC + localTZOffsetMS;

    // calculate how many minutes between article utc and user utc 
    minuteDifferential = (localCorrectedMS - articleCorrectedMS)/(1000 * 60);
    ageInMinutes = Math.round(minuteDifferential);
 
 if (ageInMinutes < 0) { ageInMinutes = 0;} 

    if ( ageInMinutes < 15 ) {
        document.write("<span>UPDATED:</span> "+ ageInMinutes +" minutes ago"); 
    } else {
        if (hour >= 12) {
            if (hour != 12) {aHour = aHour - 12;} 
            ampm = "PM";
        } else {
            ampm = "AM";
        }
        if (aMinutes < 10) {aMinutes = "0" + aMinutes} 
        document.write("<span>UPDATED:</span> "+ aHour+":" + aMinutes + ampm + " ET"); 
    }
}