var counter = 30
var tmId = 0;

function doCounterRedirect(domainReal)
{
	tmId = setTimeout(function() { 
	
	doCounterRedirect(domainReal);
	
	document.getElementById('id_counter').innerHTML = --counter;
	
	if(counter <= 0)
	{
		 clearTimeout(tmId);
		 document.location = domainReal;
	}
	
	}, 1000);
}


function doCounter(price, delta, startDate, numsCnt)
{
	var tmId = setTimeout(function() { 
	
	var num = round(price * pow(2, (microtime(true) + delta - startDate)/(365 * 86400)), numsCnt );

	var data = explode('.', num.toString());

	document.getElementById('id_counter1').innerHTML = '$' + data[0];
	document.getElementById('id_counter2').innerHTML =  data[1] + str_repeat('0', numsCnt - data[1].length);
	

	doCounter(price, delta, startDate, numsCnt);

	}, 70);
}


function str_repeat ( input, multiplier ) {
    // Returns the input string repeat mult times  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/str_repeat
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // *     example 1: str_repeat('-=', 10);
    // *     returns 1: '-=-=-=-=-=-=-=-=-=-='
    
    
    return new Array(multiplier+1).join(input); 
}

function explode (delimiter, string, limit) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/explode
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function pow (base, exp) {
    // Returns base raised to the power of exponent. Returns integer result when possible  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/pow
    // +   original by: Onno Marsman
    // *     example 1: pow(8723321.4, 7);
    // *     returns 1: 3.843909168077899e+48
    return Math.pow(base, exp);
}

function round (value, precision, mode) {
    // Returns the number rounded to specified precision  
    // 
    // version: 1009.820
    // discuss at: http://phpjs.org/functions/round
    // +   original by: Philip Peterson
    // +    revised by: Onno Marsman
    // +      input by: Greenseed
    // +    revised by: T.Wild
    // +      input by: meo
    // +      input by: William
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Josep Sanz (http://www.ws3.es/)
    // +    revised by: Rafał Kukawski (http://blog.kukawski.pl/)
    // %        note 1: Great work. Ideas for improvement:
    // %        note 1:  - code more compliant with developer guidelines
    // %        note 1:  - for implementing PHP constant arguments look at
    // %        note 1:  the pathinfo() function, it offers the greatest
    // %        note 1:  flexibility & compatibility possible
    // *     example 1: round(1241757, -3);
    // *     returns 1: 1242000
    // *     example 2: round(3.6);
    // *     returns 2: 4
    // *     example 3: round(2.835, 2);
    // *     returns 3: 2.84
    // *     example 4: round(1.1749999999999, 2);
    // *     returns 4: 1.17
    // *     example 5: round(58551.799999999996, 2);
    // *     returns 5: 58551.8
        var m, f, isHalf, sgn; // helper variables
        precision |= 0; // making sure precision is integer
        m = Math.pow(10, precision);
        value *= m;
        sgn = (value>0)|-(value<0); // sign of the number
        isHalf = value % 1 === 0.5 * sgn;
        f = Math.floor(value);
        
        if(isHalf){
                switch(mode){
                        case 'PHP_ROUND_HALF_DOWN':
                                value = f + (sgn < 0); // rounds .5 toward zero
                                break;
                        case 'PHP_ROUND_HALF_EVEN':
                                value = f + (f % 2 * sgn); // rouds .5 towards the next even integer
                                break;
                        case 'PHP_ROUND_HALF_ODD':
                                value = f + !(f % 2); // rounds .5 towards the next odd integer
                                break;
                        default:
                                value = f + (sgn > 0); // rounds .5 away from zero
                }
        }
        
        return (isHalf ? value : Math.round(value)) / m;
}

function microtime (get_as_float) {
    // Returns either a string or a float containing the current time in seconds and microseconds  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/microtime
    // +   original by: Paulo Freitas
    // *     example 1: timeStamp = microtime(true);
    // *     results 1: timeStamp > 1000000000 && timeStamp < 2000000000
    var now = new Date().getTime() / 1000;
    var s = parseInt(now, 10);
 
    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}
