 var options, $ = function (s) {
        return document.getElementById(s);
    },
    add = function (a, e, b) {
        a.addEventListener ? a.addEventListener(e, b, false) : a.attachEvent ? a.attachEvent('on' + e, b) : a['on' + e] = b
    },
    p = function () {
        var b = new Date(),
		
            target = new Date(options.iDate[0], options.iDate[1] - 1, options.iDate[2], options.iDate[3], options.iDate[4]),
            timeZ = (options.timeZone - (-b.getTimezoneOffset() / 60)) * 3600000,
            counter = target.getTime() - b.getTime() - timeZ,
            s = Math.floor(counter / 1000),
            m = Math.floor(s / 60),
            h = Math.floor(m / 60),
            d = '' + Math.floor(h / 24);
        if (counter > 0) {
            s = bTt(s % 60);
            m = bTt(m % 60);
            h = bTt(h % 24);
            d = (d.length < 2) ? '00' + d : (d.length < 3) ? '0' + d : d;
            d = d.split('', d.length);
            h = h.split('', h.length);
            m = m.split('', m.length);
            s = s.split('', s.length);
            set(d, 0);
            set(h, 4);
            set(m, 7);
            set(s, 10);
            var t = setTimeout(p, 1000)
        } else {
            while ($('jsCount').firstChild) $('jsCount').removeChild($('jsCount').lastChild);
            $('jsCount').style.textAlign = 'center';
            $('jsCount').style.color = options.msg[1];
            $('jsCount').style.fontSize = options.msg[2];
            $('jsCount').style.fontFamily = options.msg[3] + ',Helvetica,Geneva';
            if (options.link) {
                var a = document.createElement('a');
                a.href = options.link;
                a.style.color = options.msg[1];
                a.appendChild(document.createTextNode(options.msg[0]));
                $('jsCount').appendChild(a)
            } else $('jsCount').appendChild(document.createTextNode(options.msg[0]));
            if (options.redirect) setTimeout(function () {
                window.location = options.redirect[0]
            }, options.redirect[1])
        }
    },
    set = function (d, a) {
        var b = $('jsCount').getElementsByTagName('div');
        for (var i = 0; i < d.length; i++) {
            b[i + a].style.backgroundPosition = d[i] * -17 + 'px 0px'
        }
    },
    bTt = function (a) {
        num = a < 10 ? '0' + a : '' + a;
        return num
    },
    create = function (n) {
        var e;
        for (var i = 0; i < n.length; i++) {
            for (var j = 0; j < n[i][0]; j++) {
                e = document.createElement('div');
                e.style.background = 'url("' + options.SkinName + '") no-repeat';
                if (!window.attachEvent || window.opera) e.style.cssFloat = 'left';
                else e.style.styleFloat = 'left';
                if (n[i][1] != 'txt') {
                    e.className = n[i][1];
                    e.style.height = '27px'
                }
                if (n[i][1] == 'num') {
                    e.style.width = '17px'
                } else if (n[i][1] == 'sep') {
                    e.style.width = '5px';
                    e.style.backgroundPosition = '-170px 0px'
                } else if (n[i][1] == 'txt') {
                    e.id = 'txt';
                    e.style.height = '7px';
                    e.style.width = '170px';
                    e.style.backgroundPosition = '-3px -27px'
                }
                $('jsCount').appendChild(e)
            }
        }
    };
 add(window, 'load', function () {
	 
		$('jsCount').style.width = '170px';
        $('countdown').style.display = 'block';
        options = {
            iDate: [$('year').value, $('month').value, $('day').value, $('hour').value, $('minute').value],
            timeZone: $('tmz').value,
            SkinName: $('skin').value,
            msg: [$('msg').value, $('color').value, $('size').value + '%', $('font').value]
        };
		
        if ($('url').value != '') options.link = $('url').value;
        if ($('redirect').value != '') options.redirect = [$('redirect').value, $('time').value * 1000];
        while ($('jsCount').firstChild) $('jsCount').removeChild($('jsCount').lastChild);
        create([
            [3, 'num'],
            [1, 'sep'],
            [2, 'num'],
            [1, 'sep'],
            [2, 'num'],
            [1, 'sep'],
            [2, 'num'],
            [1, 'txt']
        ]);
		
        p();
    });
