/*
 * spriteTimer jQuery plugin v1.3.6
 * Copyright (c) 2010 Davor Spasovski
 * October 25, 2010
 * http://www.spasovski.net/code/spritetimer
 * Tested on: jQuery 1.4.2 and jQuery 1.4.3
 *
 * Dual licensed under the MIT or GPL Version 2 licenses.
 */
$(document).ready(function(){
    var AutoHappyHour = setInterval('HappyHourliftOff()', 60000);
    HappyHourTopliftOff();
    var AutoHappyHourTop = setInterval('HappyHourTopliftOff()', 60000);
    //var chkHappyHour = setInterval('CheckAutoHappyHour()', 70000);
    
});

function start_counter(ts) {
    ts -= 1;
    if(ts <= 0) {
        HappyHourliftOff();
        return;
    }
   /* if(ts < 0) {
        ts = 0;
    }*/
    hrs = Math.floor(ts/60/60);
    if(hrs < 10) {
        hrs = "0"+hrs;
    }
    mins = Math.floor(ts/60)%60;
    if(mins < 10) {
        mins = "0"+mins;
    }
    secs = ts%60;
    if(secs < 10) {
        secs = "0"+secs;
    }
    if ($("#timer #hours").length >0)
    {
        $("#timer #hours")[0].innerHTML = hrs + ':';
        $("#timer #minutes")[0].innerHTML = mins + ':';
        $("#timer #seconds")[0].innerHTML = secs;
        setTimeout("start_counter("+ts+")", 1000);
    }
}

function start_counter_byId(ts,id) {
   ts -= 1;
    if(ts <= 0) {
        HappyHourTopliftOff();
        return;
    }
   /* if(ts < 0) {
        ts = 0;
    }*/
    hrs = Math.floor(ts/60/60);
    if(hrs < 10) {
        hrs = "0"+hrs;
    }
    mins = Math.floor(ts/60)%60;
    if(mins < 10) {
        mins = "0"+mins;
    }
    secs = ts%60;
    if(secs < 10) {
        secs = "0"+secs;
    }
    if ($("#"+id+" .hours").length >0)
    {
    $("#"+id+" .hours")[0].innerHTML = hrs + ':';
    $("#"+id+" .minutes")[0].innerHTML = mins + ':';
    $("#"+id+" .seconds")[0].innerHTML = secs;
        setTimeout("start_counter_byId("+ts+",'"+id+"')", 1000);
    }
}

function CheckAutoHappyHour()
{
    if(AutoHappyHour==null)
         var AutoHappyHour = setInterval('HappyHourliftOff()', 60000);
}
 
 function HappyHourliftOff(){
    if ($('#HappyHourProducts').length >0) {
        //$('#HappyHourProducts').empty();
        //$('#HappyHourProducts').load('/HappyHour.aspx #HappyHourClone');
        
        $.ajax({
            type: "POST",
            url: "/HappyHour.aspx",
            cache: false,
            success: function (html) {
            html = html.replace('<body><form name="form1" method="post" action="HappyHour.aspx" id="form1">','');
            html = html.replace('<head id="Head1"><link href="App_Themes/Panika/styles.css" type="text/css" rel="stylesheet" /><title></title></head>','');
            html = html.replace('<link href="App_Themes/Panika/styles.css" type="text/css" rel="stylesheet" />','');
            html = html.replace('title','');
            html = html.replace('<>','');
            html = html.replace('</form></body></html>','');
             $('#HappyHourProducts').empty()
             $('#HappyHourProducts').append(html);}    
            });
            
            if ($('#defaultCountdown').length >0)
            {
                 
                 
            }
           
      }  
}

function HappyHourTopliftOff(){
    if ($('#HappyHourProductsTop').length >0) {
        //$('#HappyHourProducts').empty();
        //$('#HappyHourProducts').load('/HappyHour.aspx #HappyHourClone');
        
        $.ajax({
            type: "POST",
            url: "/HappyHourTop.aspx",
            cache: false,
            success: function (html) {
            html = html.replace('<body><form name="form1" method="post" action="HappyHourTop.aspx" id="form1">','');
            html = html.replace('<head id="Head1"><link href="App_Themes/Panika/styles.css" type="text/css" rel="stylesheet" /><title></title></head>','');
            html = html.replace('<link href="App_Themes/Panika/styles.css" type="text/css" rel="stylesheet" />','');
            html = html.replace('title','');
            html = html.replace('<>','');
            html = html.replace('</form></body></html>','');
             $('#HappyHourProductsTop').empty()
             $('#HappyHourProductsTop').append(html);}    
            });
            
            if ($('#defaultCountdownTop').length >0)
            {
                 
                 
            }
           
      }  
}


