var countdown1;
countdown1=428;
var countdown2;
countdown2=279;
var countdown3;
countdown3=36;

// Tick (countdownId, eventDate)
function CD_T(id, e) {
	var n = new Date();
	CD_D(+n, id, e);
	var rand_no = Math.random();
    rand_no = rand_no * 3400 + 2500;
    rand_no = Math.ceil(rand_no);
	setTimeout("if(typeof CD_T=='function'){CD_T('" + id + "'," + e + ")}", rand_no); // We offset from 1100 so that our clock ticks every second (the millisecond correction each loop sees to that), but updates 0.1s after every whole second so that we don't accidentally read the same Date() twice in the same second

//	setTimeout("if(typeof CD_T=='function'){CD_T('" + id + "'," + e + ")}", 1100-n.getMilliseconds()); // We offset from 1100 so that our clock ticks every second (the millisecond correction each loop sees to that), but updates 0.1s after every whole second so that we don't accidentally read the same Date() twice in the same second
};

// Calculate time and update display (dateNow, countdownId, eventDate)
function CD_D(n, id, e) {
	var ms = e - n;
	if (ms <= 0) ms *= -1;
	var d = Math.floor(ms/864E5);
	ms -= d*864E5;
	var h = Math.floor(ms/36E5);
	ms -= h*36E5;
	var m = Math.floor(ms/6E4);
	ms -= m*6E4;
	var s = Math.floor(ms/1E3);

	// If you want to manually customise the counter display, then edit this line:
	if (CD_OBJS[id]) {
		CD_OBJS[id].innerHTML = d + " day" + (d == 1 ? " " : "s ") + CD_ZP(h) + "h " + CD_ZP(m) + "m " + CD_ZP(s) + "s";
	}
};

// Prefix single integers with a zero
function CD_ZP(i) {
	return (i<10 ? "0" + i : i);
};

// Initialisation
function CD_Init() {
	var pref = "countdown";
	var objH = 1; // temp boolean true value
	if (document.getElementById || document.all) {
		for (var i=1; objH; ++i) {
			var id	= pref + i;
			objH	= document.getElementById ? document.getElementById(id) : document.all[id];

            if (objH && (typeof objH.innerHTML) != 'undefined') {
                if (id = "countdown1"){
                    // First countdown
                    countdown1 = countdown1-1;
                    if (countdown1<=0){
                        objH.innerHTML = "<strong style=\"color:#ff0000;\">Minimal Quantities Remaining</strong>"
                        return;
                    }else{
                        objH.innerHTML = countdown1;
                        if (objH.style) {
				            objH.style.visibility = "visible";
			            }
                        var rand_no = Math.random();
                        rand_no = rand_no * 4400 + 100;
                        rand_no = Math.ceil(rand_no);
			            setTimeout("CD_Init();", rand_no); // We offset from 1100 so that our clock ticks every second (the millisecond correction each loop sees to that), but updates 0.1s after every whole second so that we don't accidentally read the same Date() twice in the same second
                        return;
                    }
                    
                }
            }
		}
	}
};


// Initialisation
function CD_Init2() {
	var pref = "countdown2";
	var objH = 1; // temp boolean true value
	if (document.getElementById || document.all) {
	
		objH	= document.getElementById ? document.getElementById(pref) : document.all[pref];
		
        if (objH && (typeof objH.innerHTML) != 'undefined') {
           
            // First countdown
            countdown2 = countdown2-1;
            if (countdown2==0){
                objH.innerHTML = "<strong style=\"color:#ff0000;\">Minimal Quantities Remaining</strong>"
                return;
            }else{
                objH.innerHTML = countdown2;
                if (objH.style) {
	                objH.style.visibility = "visible";
                }
                var rand_no = Math.random();
                rand_no = rand_no * 4400 + 100;
                rand_no = Math.ceil(rand_no);
                setTimeout("CD_Init2();", rand_no); // We offset from 1100 so that our clock ticks every second (the millisecond correction each loop sees to that), but updates 0.1s after every whole second so that we don't accidentally read the same Date() twice in the same second
                return;
            }
                
        }
	}
};

// Initialisation
function CD_Init3() {
	var pref = "countdown3";
	var objH = 1; // temp boolean true value
	if (document.getElementById || document.all) {
	
		objH	= document.getElementById ? document.getElementById(pref) : document.all[pref];
		
        if (objH && (typeof objH.innerHTML) != 'undefined') {
           
            // First countdown
            countdown3 = countdown3-1;
            if (countdown3==0){
                objH.innerHTML = "<strong style=\"color:#ff0000;\">Minimal Quantities Remaining</strong>"
                return;
            }else{
                objH.innerHTML = countdown3;
                if (objH.style) {
	                objH.style.visibility = "visible";
                }
                var rand_no = Math.random();
                rand_no = rand_no * 4400 + 100;
                rand_no = Math.ceil(rand_no);
                setTimeout("CD_Init3();", rand_no); // We offset from 1100 so that our clock ticks every second (the millisecond correction each loop sees to that), but updates 0.1s after every whole second so that we don't accidentally read the same Date() twice in the same second
                return;
            }
                
        }
	}
};

// Get Date() object from 2006-01-01 00:00:00 GMT+00:00 date format
function CD_Parse(strDate) {
	// Pattern match to a countdown date
	var objReDte = /(\d{4})\-(\d{1,2})\-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{0,2})\s+GMT([+\-])(\d{1,2}):?(\d{1,2})?/;

	if (strDate.match(objReDte)) {
		// Start with a default date and build it up into the countdown date through Date setter methods
		var d = new Date(0);

		d.setUTCFullYear(+RegExp.$1,+RegExp.$2-1,+RegExp.$3); // Set YYYY-MM-DD directly as UTC
		d.setUTCHours(+RegExp.$4,+RegExp.$5,+RegExp.$6); // Set HH:MM:SS directly as UTC

		// If there is a timezone offset specified then we need to compensate for the offset from UTC
		var tzs	= (RegExp.$7 == "-" ? -1 : 1); // Timezone sign
		var tzh = +RegExp.$8; // Get requested timezone offset HH (offset ahead of UTC - may be negative)
		var tzm = +RegExp.$9; // Get requested timezone offset MM (offset ahead of UTC - always positive)
		if (tzh) {
			d.setUTCHours(d.getUTCHours() - tzh*tzs); // Compensate for timezone HH offset from UTC
		}
		if (tzm) {
			d.setUTCMinutes(d.getUTCMinutes() - tzm*tzs); // Compensate for timezone MM offset, depending on whether the requested MM offset is ahead or behind of UTC
		}
		return d; // Date now correctly parsed into a Date object correctly offset from UTC internally regardless of users current timezone.
	}
	else {
		return NaN; // Didn't match required date format
	};
};

var CD_OBJS = new Object();

function finitialize(){
    CD_Init();
    CD_Init2();
    CD_Init3();
}

// Try not to commandeer the default onload handler if possible
if (window.attachEvent) {
	window.attachEvent('onload', finitialize);
}
else if (window.addEventListener) {
	window.addEventListener("load", finitialize, false);
}
else {
	window.onload = finitialize;
}