// JavaScript Document

function swapImagesBegin( imgId, imgId2, imgSrc ) {
	opacityElm( imgId2, 0 );
	document.images[ imgId2 ].src = imgSrc;
}
function swapImagesEnd( imgId, imgId2, imgSrc ) {
	document.images[ imgId ].src = imgSrc;
	opacityElm( imgId2, 0 );
}
function swapImages( imgId, imgId2, imgSrc, step, delay ) {
	swapImagesBegin( imgId, imgId2, imgSrc );
	var i, t;
	var j = 0;
	var t = new Array();
	for( i = 100-100/step*step, j = 0; i <= 100; i+=step, j++ ) {
		t = setTimeout( "opacityElm('"+imgId2+"',"+i+")", j*delay );
	}
	t = setTimeout( "swapImagesEnd('"+imgId+"','"+imgId2+"','"+imgSrc+"')", j*delay );
		
}

function titleRoll ( p ) {
	pTitle = p;
	window.clearInterval( autoRollInt );
	autoRollInt = setInterval( "titleAutoRoll ()", autoRollSec*1000 );
	for( var i = 1; i <= nTitle; ++i ) {
		document.images[ titlePoint+i ].src = 'wp-content/themes/hvezdarna/images/point-white.png';
	}
	document.images[ titlePoint+p ].src = 'wp-content/themes/hvezdarna/images/point-blue.png';
	var elm = document.getElementById( titleElmId );
	elm.innerHTML = titleText[p-1];
	var link = document.getElementById( titleLink );
	link.href = titleHref[p-1];	
	swapImages( titleImgId1, titleImgId2, titleSrc[p-1], 4, 15 );
}	

function titleAutoRoll () {
	pTitle++;
	if( pTitle > nTitle ) pTitle = 1;
	titleRoll ( pTitle );	
}	
	
function loadTitleImages() {
	var images = new Array();
	var i = 0;
	for( i = 0; i < nTitle; ++i ) {
		images[i] = new Image();
		images[i].src = titleSrc[i];
	}
	i++;
	images[i] = new Image();
	images[i].src = 'wp-content/themes/hvezdarna/images/highlink-back2.png';
}


var autoRollInt;
var autoRollSec = 6.5; 
	

