function createCountDownFlipStyles(targetDate, imgSrc, innerDIV, extraConf, currentDate){
	if(typeof(imgSrc) == "string" && typeof(innerDIV) == "string" ){
		if ((extraConf.search('days') > -1) && (extraConf.search('comma') > -1) ){
			alert("Los parametros de 'comma' y 'days' son mutuamente excluyentes, solo indica uno de los dos por favor.");
			return false;
		}
		
		if ( (extraConf.search('legend') > -1) && ( (extraConf.search('hours') > -1) || (extraConf.search('minutes') > -1) || (extraConf.search('seconds') > -1) || (extraConf.search('days') > -1)) ){
			alert("Los parametros de 'days', 'hours', 'minutes', 'seconds' y 'legend' son mutuamente excluyentes.");
			return false;
		}
		
		countBackVars = initCountDownFlip(targetDate, currentDate).split("|");
		var dias = (''+stripHTML(reckonTime(countBackVars[0],86400,100000, true))+'').split("");
	
		styleConstructor = '';
		styleConstructor += '	<style type="text/css"> \n';
		styleConstructor += '		/*---countDownFlip ---*/ \n';
		styleConstructor += '		#countDownFlip {	position:relative; height: 103px; overflow: hidden; } \n';
		styleConstructor += '		#countDownFlip .digit {float: left; position: relative; height: 103px; width: 53px; overflow: hidden;} \n';
		styleConstructor += '		#countDownFlip .digit .digitImage {position: absolute; width: 53px; height: 12360px;} \n';
		styleConstructor += '		#countDownFlip .digit .digitImageElement {background-image: url("'+imgSrc+'/inversefilmstrip_02.png"); background-repeat: no-repeat; background-position: 0px 0px; width: 53px; height: 6180px;} \n';
		//styleConstructor += '		#countDownFlip .digit .digitSeparatorImage {background-image: url("'+imgSrc+'/segundero.gif"); background-repeat: no-repeat; width: 53px; height: 103px; z-index: 999; } \n';
		//styleConstructor += '		#countDownFlip .digit .digitSeparator {position: absolute; width: 53px; height: 103px;} \n';
		styleConstructor += '		#countDownFlip .legend{position: relative; top:105px; height: 28px; z-index: 999; font-family: Georgia, "Times New Roman", Times, serif; font-size: 25px;} \n';
		styleConstructor += '		#countDownFlip .digit .comma {background-image: url("'+imgSrc+'/coma.png"); background-repeat: no-repeat; width: 53px; height: 103px; } \n';
		styleConstructor += '		#countDownFlip .digit .days {background-image: url("'+imgSrc+'/dias.jpg"); background-repeat: no-repeat; width: 53px; height: 103px; } \n';
		styleConstructor += '		#countDownFlip .digit .hours {background-image: url("'+imgSrc+'/hrs.jpg"); background-repeat: no-repeat; width: 53px; height: 103px; } \n';
		styleConstructor += '		#countDownFlip .digit .minutes {background-image: url("'+imgSrc+'/min.jpg"); background-repeat: no-repeat; width: 53px; height: 103px; } \n';
		styleConstructor += '		#countDownFlip .digit .seconds {background-image: url("'+imgSrc+'/seg.jpg"); background-repeat: no-repeat; width: 53px; height: 103px; } \n';
		styleConstructor += '		#countDownFlip .digit .digitSeparatorImage {background-image: url("'+imgSrc+'/separador.png"); background-repeat: no-repeat; background-position: 0px 0px; width: 53px; height: 206px;} \n';
		styleConstructor += '		#countDownFlip .digit .digitSeparator {position: absolute; *position:relative; width: 53px; height: 206px;} \n';
		styleConstructor += '	</style> \n\n\n';
		
		
		var pa= document.getElementsByTagName('head')[0] ;
		var el= document.createElement('style');
		el.type= 'text/css';
		if(el.styleSheet) 
			el.styleSheet.cssText= styleConstructor;// IE method
		else 
			el.appendChild(document.createTextNode(styleConstructor));// others
		pa.appendChild(el);
		
		styleConstructor = '';
		styleConstructor += '\n	<!-- INICIO DE CONTADOR \n';
		styleConstructor += '	Por favor, no editar nada desde aqui hasta la el siguiente comentario que dira: FIN DE CONTADOR --> \n';
		styleConstructor += '	<div id="countDownFlip" style="position:relative;"> \n';
		
		if (dias.length == 4)
			styleLeft = 'style="left:105px;"';
		if (dias.length == 3)
			styleLeft = 'style="left:50px;"';
		if (dias.length == 2)
			styleLeft = 'style="left:0px;"';
		if (dias.length == 1)
			styleLeft = 'style="left:-25px;"';
			
			
		if ((extraConf.search('legend') > -1) && (dias.length >= 1 && dias[0] > 0))
			styleConstructor += '	    <div class="legend" '+styleLeft+' >&nbsp;&nbsp;&nbsp;&nbsp; d&iacute;as &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hrs &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; min &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; seg</div> \n';
		else		
			styleConstructor += '	    <div class="legend">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hrs &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; min &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; seg</div> \n';
			
		if (dias.length == 4){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipDayThousand"> \n';
			styleConstructor += '	            <div class="digitImageElement"></div> \n';
			styleConstructor += '	        </div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		if (dias.length >= 3){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipDayHundred"> \n';
			styleConstructor += '	            <div class="digitImageElement"></div> \n';
			styleConstructor += '	        </div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		
		if (dias.length >= 2 && dias[1] >= 0){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipDayTen"> \n';
			styleConstructor += '	            <div class="digitImageElement"></div> \n';
			styleConstructor += '	        </div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		
		
		if (dias.length >= 1 && dias[0] > 0){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipDayUnit"> \n';
			styleConstructor += '	            <div class="digitImageElement"></div> \n';
			styleConstructor += '	        </div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		
		if ((extraConf.search('days') > -1) && (extraConf.search('comma') < 0) && (dias.length >= 1 && dias[0] > 0) ){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	         <div class="days"></div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		if ((extraConf.search('days') < 0) && (extraConf.search('comma') > -1) && (dias.length >= 1 && dias[0] > 0) ){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	         <div class="comma"></div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipHourTen"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipHourUnit"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		
		if ((extraConf.search('hours') > -1)){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	         <div class="hours"></div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitSeparator" id="minutero"> \n';
		styleConstructor += '	            <div class="digitSeparatorImage"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipMinTen"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipMinUnit"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		
		if ((extraConf.search('minutes') > -1)){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	         <div class="minutes"></div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitSeparator" id="segundero"> \n';
		styleConstructor += '	            <div class="digitSeparatorImage"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipSegTen"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		styleConstructor += '	    <span class="digit"> \n';
		styleConstructor += '	        <div style="top: 0px;" class="digitImage" id="countDownFlipSegUnit"> \n';
		styleConstructor += '	            <div class="digitImageElement"></div> \n';
		styleConstructor += '	        </div> \n';
		styleConstructor += '	    </span> \n';
		
		if ((extraConf.search('seconds') > -1)){
			styleConstructor += '	    <span class="digit"> \n';
			styleConstructor += '	         <div class="seconds"></div> \n';
			styleConstructor += '	    </span> \n';
		}
		
		styleConstructor += '	</div> \n';
		styleConstructor += '	<div id="tmptimer"></div> \n';
		styleConstructor += '	<!-- FIN DE CONTADOR --> \n\n\n';
		document.getElementById(innerDIV).innerHTML = styleConstructor;
	} else
		alert("La ruta de las imagenes del contador o el contendor no ha sido colocado.");
}

function createCountDownFlip(targetDate, imgSrc, innerDIV, extraConf, currentDate){
	createCountDownFlipStyles(targetDate, imgSrc, innerDIV, extraConf, currentDate);
	countBackVars = initCountDownFlip(targetDate, currentDate).split("|");
	changeSeconds('segundero');
	changeSeconds('minutero');
	countBack(countBackVars[0], countBackVars[1]);
	
}


function changeNumber(number, initialCount, containerID){
	/*var arrayNumbers = new Array(-5459, 0, -618, -1236, -1854, -2472, -3090, -3708, -4326, -4944, -5562);/*contador normal*/
	var arrayNumbers = new Array(-5459, -4944, -4326, -3708, -3090, -2472, -1854, -1236, -618, 0, -5459);
	if (initialCount > 618) return;
	newTop = arrayNumbers[number]-initialCount;
	initialCount += 103;
	document.getElementById(containerID).style.top = ''+newTop+'px';
	setTimeout("changeNumber("+number+", "+initialCount+", '"+containerID+"');", 60);
}

function changeSeconds(containerID, initialCount){
	if (typeof(initialCount) != "number")	initialCount = 0;
	if (initialCount > 103)	initialCount = 0;
	newTop = -initialCount;
	initialCount += 103;
	document.getElementById(containerID).style.top = ''+newTop+'px';
	setTimeout("changeSeconds('"+containerID+"', "+initialCount+");", 1000);
}

function stripHTML(strToStrip){
	//alert(strToStrip);
	return strStripped = strToStrip.replace(/(<([^>]+)>)/ig,""); 
}

function reckonTime(secs, num1, num2, days) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2 && !days)
    s = "0" + s;
  return s;
}

function countBack(secs, SetTimeOutPeriod, prevTimer) {
  if (secs < 0) return;
  DisplayFormat = "%%D%%|%%H%%|%%M%%|%%S%%";
  DisplayStr = DisplayFormat.replace(/%%D%%/g, reckonTime(secs,86400,100000, true));
  DisplayStr = DisplayStr.replace(/%%H%%/g, reckonTime(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, reckonTime(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, reckonTime(secs,1,60));

  var dias = (''+stripHTML(reckonTime(secs,86400,100000))+'').split("");
  if ( typeof(dias[3]) == "undefined"){
  	if ( typeof(dias[2]) == "undefined"){
   		dias[3] = dias[1]; 
  		dias[2] = dias[0]; 
		dias[1] = 0; 
		dias[0] = 0;
	} else {
		dias[3] = dias[2]; 
  		dias[2] = dias[1]; 
		dias[1] = dias[0]; 
		dias[0] = 0;
	}
  }

  var horas = (''+stripHTML(reckonTime(secs,3600,24))+'').split("");
  var minutos = (''+stripHTML(reckonTime(secs,60,60))+'').split("");
  var segundos = (''+stripHTML(reckonTime(secs,1,60))+'').split("");

  if (typeof(prevTimer) != "undefined"){
  	var prevTimerUnits = stripHTML(prevTimer).split("|");
	var currentTimeUnits = stripHTML(DisplayStr).split("|");
  	
	if (((currentTimeUnits[3]).split("")[0]-(prevTimerUnits[3]).split("")[0]) != 0)
		changeNumber(segundos[0], 0, 'countDownFlipSegTen');
	
	if ((currentTimeUnits[2]-prevTimerUnits[2]) != 0){
		changeNumber(minutos[1], 0, 'countDownFlipMinUnit');
		if (((currentTimeUnits[2]).split("")[0]-(prevTimerUnits[2]).split("")[0]) != 0)
			changeNumber(minutos[0], 0, 'countDownFlipMinTen');
	}
	
	if ((currentTimeUnits[1]-prevTimerUnits[1]) != 0){
		changeNumber(horas[1], 0, 'countDownFlipHourUnit');
		if (((currentTimeUnits[1]).split("")[0]-(prevTimerUnits[1]).split("")[0]) != 0)
			changeNumber(horas[0], 0, 'countDownFlipHourTen');
	}
	
	if ((currentTimeUnits[0]-prevTimerUnits[0]) != 0){
		changeNumber(dias[2], 0, 'countDownFlipDayUnit');
		if (((currentTimeUnits[0]).split("")[0]-(prevTimerUnits[0]).split("")[0]) != 0)
			changeNumber(dias[1], 0, 'countDownFlipDayTen');
	}
		
  } else {
	changeNumber(segundos[0], 0, 'countDownFlipSegTen');
	changeNumber(minutos[1], 0, 'countDownFlipMinUnit');
	changeNumber(minutos[0], 0, 'countDownFlipMinTen');
	changeNumber(horas[1], 0, 'countDownFlipHourUnit');
	changeNumber(horas[0], 0, 'countDownFlipHourTen');
	
	if (document.getElementById('countDownFlipDayUnit'))
		changeNumber(dias[3], 0, 'countDownFlipDayUnit');
	if (document.getElementById('countDownFlipDayTen'))
		changeNumber(dias[2], 0, 'countDownFlipDayTen');
	if (document.getElementById('countDownFlipDayHundred'))
		changeNumber(dias[1], 0, 'countDownFlipDayHundred');
	if (document.getElementById('countDownFlipDayThousand'))
		changeNumber(dias[0], 0, 'countDownFlipDayThousand');
  }
  changeNumber(segundos[1], 0, 'countDownFlipSegUnit');
  
  var prevTimer = DisplayStr;
  //document.getElementById("tmptimer").innerHTML=DisplayStr;
  if (CountActive)
    setTimeout("countBack(" + (secs+CountStepper) + ", "+SetTimeOutPeriod+", '"+prevTimer+"')", 1000);
}

function initCountDownFlip(TargetDate, currentDate){
	if (typeof(TargetDate)=="undefined")  
		TargetDate = "01/01/2010 00:01 AM";
	DisplayFormat = "%%D%%|%%H%%|%%M%%|%%S%%";
	CountActive = true;
	CountStepper = -1;
	LeadingZero = true;
	
	CountStepper = Math.ceil(CountStepper);
	if (CountStepper == 0)
	  CountActive = false;
	var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
	var dthen = new Date(TargetDate);
	currentDate = currentDate.replace(/ /g, '');
	currentDate = currentDate.split(',');
	var dnow = new Date(currentDate[0], currentDate[1], currentDate[2], currentDate[3], currentDate[4], currentDate[5]) ;
	if(CountStepper>0)
	  ddiff = new Date(dnow-dthen);
	else
	  ddiff = new Date(dthen-dnow);
	gsecs = Math.floor(ddiff.valueOf()/1000);
	return gsecs+'|'+SetTimeOutPeriod;
}