﻿var boxId = 'whiteBox'; //jmeno Whiteboxu
var displayWhiteBox_Timer; //timer pro zobrazeni a opetne skryti white boxu
var main_Timer; //hlavni timer, ktery zobrazuje fotku
var pom = 0; //pomocna promenna pro nastaveni opacity
var name = 'pic'; //slovni cast ID fotek
var photoId = 0; //Id aktualni fotky
var interval = 4500; //doba po kterou je fotka zobrazena

/*
*
* Pocatecni funkce, vola setPhoto() -> zobrazeni fotky podle 'photoId',
*                                   -> zacne odpocet k zobrazeni dalsi fotky.
*/
function headerStart()
{
    setPhoto(photoId);
	main_Timer = setTimeout('displayWhiteBox('+pom+')',interval);
}
/*
*
* Prechod z fotky na bily box - pomoci opacity.
*/
function displayWhiteBox(pom)
{
	if(pom>=0.98)
	{
		clearTimeout(displayWhiteBox_Timer);
		pom = 1;
		photoId = (photoId==count-1) ? 0 : (photoId + 1); //photoId  = Math.round(Math.random()*27)+1; //nastaveni ID fotky, ktera bude zobrazena priste
		displayNextPicture(pom);
	}
	else
	{
		pom += 0.1;
		getId(boxId).style.opacity = pom;
		getId(boxId).style.display = 'block';
		displayWhiteBox_Timer = setTimeout('displayWhiteBox('+pom+')',50);		
	}	
}
/*
*
* Prechod z bileho boxu na fotku. To aby se zobrazila dalsi fotka zajistuje zmena ID ve funkci displayWhiteBox().
*/
function displayNextPicture(pom)
{
	if(pom<=0)
	{
		clearTimeout(displayNextPicture_Timer);
		clearTimeout(main_Timer);
		pom = 0;
		getId(boxId).style.display = 'none';
		headerStart();
	}
	else
	{
		pom -= 0.1;
		getId(boxId).style.opacity = pom;
		displayNextPicture_Timer = setTimeout('displayNextPicture('+pom+')',50);
		setPhoto(photoId);	
	}
}
/*
*
* Zobrazeni fotky podle 'photoId'.
*/
function setPhoto(photoId)
{
    //getId('partnershipCounter').innerText = (photoId + 1) + ' / ' + (count);
    getId('partnershipCounter').innerText = (photoId + 1) + ' / ' + (count);
    getId('partnershipCounter').textContent = (photoId + 1) + ' / ' + (count);
	for(var j=0;j<count;j++)
		if(photoId==j)
			getId('pic'+j).style.display = 'block';
		else
			getId('pic'+j).style.display = 'none';
}

/*
*
* Funkce zobrazi nebo skryje sipky pro prohlizeni fotek.
*/
function showPartnershipPager(turnOnOf)
{
	if(turnOnOf)
	{
	    getId('partnershipPager').style.display = 'block';
	}
	else
	{
	    getId('partnershipPager').style.display = 'none';
	}
}
/*
*
* Rotace fotek v galerii.
* Parametr direction) => 1 = vlevo, 2 = vpravo
*/
function rotateScreen(sdirection)
{
	var number=0; //udává aktuální zobrazenou fotku 

	if(sdirection==1)
	{	
		if(photoId==0)
			photoId=count-1;
		else
			photoId--;
	}
	else
	{
		photoId++;
		photoId=photoId%count ;
	}
	number=photoId;
	showPictureScreens(number);
}
/*
*
* Funkce, ktera zobrazi obrazek 'number' a vypne timery (skonci automaticke prehravani).
*/
function showPictureScreens(number)
{
	clearTimeout(displayWhiteBox_Timer);
	clearTimeout(main_Timer);
	setPhoto(number);
	getId(boxId).style.opacity = 0;
	getId(boxId).style.display = 'none';
	pom = 0;
	headerStart();
}

function getId(id)
{
	return document.getElementById(id);
}
























