var secs;
var exceeded;
var active;

var canbook = false;
var day;
var added = 0;
var timerID = null;

var timerRunning = false;
var delay = 1000;


function StartTheTimer()
{    
    DispalyActive();
    //self.status = secs;
    secs = secs - 1;
    timerRunning = true;
    timerID = self.setTimeout("StartTheTimer()", delay);
}


function DispalyExceeded()
{
     if(exceeded == 'True')
     {
         $(".actiondetailsdata").append("<div class=\"exeeded\"> <br /> <br /> Helaas is deze aanbieding uitverkocht</div> ");
         $(".actiondetailstimer").html("<span class=\"counter\" > Helaas is deze aanbieding uitverkocht </span>");           
     }
     else
     {
        var objExeedeed = $(".exeeded");
        if(objExeedeed != null)
            objExeedeed.remove();
     }
}

function DispalyActive()
{
    if(0 >= secs  && secs > -579599  )
    {
        var objInactive = $(".inactive");
        if(objInactive != null)
            objInactive.remove();

        if (exceeded == 'True')
            $(".actiondetailstimer").html("<span class=\"counter\" > Helaas is deze aanbieding uitverkocht </span>");
        else
        {
             //display timer and inactive overlay 
            var days = 0;
            var hours = 0;
            var minutes =0;
            var seconds = 0;
            var data = 579599 + parseInt(secs);
            days = parseInt(data/86400);
            hours = parseInt((data - days * 86400) / 3600);
            minutes = parseInt((data - days * 86400 - hours * 3600)/60);
            seconds = data - days * 86400 - hours * 3600 - minutes * 60;
            
            $(".actiondetailstimer").html("<span class=\"gray\">Nog</span> <span class=\"counter\">" + days + " dagen, " + hours + " uur,  " + minutes + " min en " + seconds + " sec. </span><span class=\"gray\">  totdat de aanbieding verlopen is.</span> ");    
        }
            
           
        if( $(".actiondetailstimer").html().length > 0)
        {
            //$(".actiondetailstimer").html("");            
           added = 0;
        }
    }
    else
    {
        //remove exceeded if exists
        var objExeedeed = $(".exeeded");
        if(objExeedeed != null)
            objExeedeed.remove();  
            
        //display timer and inactive overlay 
        var days = 0;
        var hours = 0;
        var minutes =0;
        var seconds = 0;
        var data = parseInt(secs);
        days = parseInt(data/86400);
        hours = parseInt((data - days * 86400) / 3600);
        minutes = parseInt((data - days * 86400 - hours * 3600)/60);
        seconds = data - days * 86400 - hours * 3600 - minutes * 60;

        if(secs > 0 )
        {
            $(".actiondetailstimer").html("<span class=\"gray\">Over</span> <span class=\"counter\">" + days + " dagen, " + hours + " uur,  " + minutes + " min en " + seconds + " sec. </span><span class=\"gray\"> kunt u deze aanbieding boeken.</span> ");    
        }
        var expiredmessage = $("#ihExpiredMessage").val();
        if (secs < -579599 && expiredmessage != undefined ){
            $(".actiondetailstimer").html("<span class=\"counter\">" + expiredmessage + "</span>");
        }
        
        if(added == 0 )
        {
            $(".actiondetailsdata").append("<div class=\"inactive\"> <a class=\"closeinactive\" onclick=\"javascript:return CloseInactive();\">X</a> <br /> <br />Helaas is deze aanbieding niet meer beschikbaar.<br /> </div> ");
            added = 1;
        }
    }
}

function CloseInactive()
{
    $(".inactive").css('display', 'none');
    return false;
}

function CloseBookOffline()
{
    $(".bookoffline").css('display', 'none');
    return false;
}

$(document).ready(function() {

    $(".more").click(function() {
        try {
            pageTracker._trackEvent('Reservering', 'Nu-boeken', 'Klikken op boek button');
        }
        catch (err) { }

        var bookofflinemessage = $("#ihBookOffline").val();
        while (typeof (bookofflinemessage) == undefined) {
            bookofflinemessage = $("#ihBookOffline").val();
        }

        if (bookofflinemessage.toString().length > 0) {
            $(".actiondetailsdata").append("<div class=\"bookoffline\"> <a class=\"closebookoffline\" onclick=\"javascript:return CloseBookOffline();\">X</a>" + bookofflinemessage + "</div> ");
            $(".bookoffline").css('display', 'block');
            return false;
        }
        else {
            if (0 >= secs && secs >= -579599) {
                return true;
            }
            else {
                $(".inactive").css('display', 'block');
                return false;
            }
        }
    });

});









