﻿function replaceAll(text, strA, strB)
{
	var res = '';
	var i = 0, j;
	while ((j = text.indexOf(strA, i)) != -1)
	{
		if (i != j)
			res = res.concat(text.substr(i, j - i));		
		i = j + strA.length;		
		res = res.concat(strB);
	}
	res = res.concat(text.substr(i, text.length - i));
	return res;
}

function $$(elid) { return document.getElementById(elid); }
function RunCodeEveryAfter(codeToExecute, everyMilliseconds)
{	
	setTimeout("RunCodeEvery('" + replaceAll(codeToExecute, "'", "\\'") + "'," + 
		everyMilliseconds + ")", everyMilliseconds);
}
function RunCodeEveryAfterDelay(codeToExecute, everyMilliseconds, waitMilliseconds)
{
	setTimeout("RunCodeEvery('" + replaceAll(codeToExecute, "'", "\\'") + "'," + 
		everyMilliseconds + ")", waitMilliseconds);
}
function RunCodeEvery(codeToExecute, everyMilliseconds)
{
	eval(codeToExecute);
	setTimeout("RunCodeEvery('" + replaceAll(codeToExecute, "'", "\\'") + "'," + 
		everyMilliseconds + ")", everyMilliseconds);	
}

function animateHeading()
{
	if (typeof animateHeading.anim == 'undefined')
		// animate margin-left from 0 to 100 px 
		animateHeading.anim = new Animator(
		
		{
			transition: Animator.makeBounce(0),
			/*transition: Animator.makeADSR(0, 0, 0.5, 1),*/
			duration: 500,
			interval: 10/*,
			onComplete: function() { } */}
			)
		.addSubject(new CSSStyleSubject(
    $$("modal-content-top-heading"),
		"modal-content-top-heading-1",
		"modal-content-top-heading-2"
    //"font-style: normal;",
    //"font-style: italic;"
		//.addSubject(
		//				new NumericalStyleSubject(
		//					$$("modal-content-top-heading"), "margin-left", 0, 100
		));
	if (typeof animateHeading.ind == 'undefined')
		animateHeading.ind = 0;
	
	animateHeading.anim.toggle();
	if (animateHeading.ind == 0)
		setTimeout("animateHeading()", 600);
	animateHeading.ind = (animateHeading.ind + 1) % 2;
}

//RunCodeEvery("changeText()", 2000);
function changeText()
{
	if (typeof changeText.curIndex == 'undefined')
		changeText.curIndex = 0;	
	if (typeof changeText.textArr == 'undefined')
		changeText.textArr = new Array(
			"certifikácia EVPÚ podľa zákona 289/2009", 
			"kapacita fiškálnej pamäte min. 5 rokov", 
			"Rýchlosť tlače >220 mm/sec",
			"Nízko hlučná tlač",
			"Grafická schopnosť",
			"Malé rozmery",
			"Veľmi jednoduchá výmena rolky",
			"Dostupná aj v čiernej farbe"
		);

	$$("infop").innerHTML = changeText.textArr[changeText.curIndex];
	
	changeText.curIndex = (changeText.curIndex + 1) % changeText.textArr.length;
}


function animateItems()
{	
	if (typeof animateItems.anim == 'undefined')
	{
		animateItems.animOut = new Animator({duration: 500, interval: 10,
			onComplete: function() { changeText(); } })
			//.addSubject(new CSSStyleSubject($$("infop"), "infopMiddle", "infopTop"))
			.addSubject(new NumericalStyleSubject($$("infop"), "top", "200px", "50px"))
			.addSubject(new NumericalStyleSubject($$("infop"), "opacity", 1, 0.0))
		;
		
		animateItems.animIn = new Animator({duration: 500, interval: 10,
			onComplete: function() { $$("infop").style.filter = ''; } })
			//.addSubject(new CSSStyleSubject($$("infop"), "infopMiddle", "infopBottom"))
			.addSubject(new NumericalStyleSubject($$("infop"), "top", "300px", "200px"))
			.addSubject(new NumericalStyleSubject($$("infop"), "opacity", 0.0, 1.0))
		;
		/**/
	}
		
	//animateItems.animIn.toggle();
	animateItems.animOut.play();
	setTimeout("animateItems.animIn.play()", 2000);
	//animateItems.animOut.play();
	//setTimeout("animateItems.animIn.play()", 800);
}
	
var goonBlinking = true;
function blink(itemId)
{
	if (goonBlinking)
	{
		var item = $$(itemId);
		var timeout;
		if (item.style.visibility != "hidden")
		{
			item.style.visibility = "hidden";
			timeout = 300;
		}
		else
		{
			item.style.visibility = "visible";
			timeout = 1000;
		}
			
		setTimeout("blink('" + itemId + "')", timeout);
	}
}

function endModalDialog()
{
	goonBlinking = false;
	$.modal.close();
}

$(document).ready(function () {
	//$('#simplepid').click(function (e) {
		//e.preventDefault();
	/**/
	$('#basic-modal-content').modal({ overlayClose:true });
	
	blink('basic-modal-content-news');
	
	setTimeout("endModalDialog();", 15000);
	
	/*
	RunCodeEveryAfter("animateHeading()", 3000);
	RunCodeEvery("animateItems()", 6000);
		
	/**/
	//});
});
