/* ============= nahodne cele cislo od 1 do N ================= */
function randomNumber(n) {
	n = Math.ceil(n);
	return Math.ceil(Math.random()*n);
}

/* ==================== VLOZENI FLASHE DO STRANKY ========================== */
function getFlashCode(file, width, height, alt) {
	document.write('' + 
	'<div class="flash-h"> ' +
	
	'	<!--[if !IE]> -->' + 
	'	<object type="application/x-shockwave-flash"' + 
	'	  data="' + file + '" width="' + width + '" height="' + height + '">' + 
	'	<!-- <![endif]-->' + 
	'	' + 	
	'	<!--[if IE]>' + 
	'	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 
	'		codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' + 
	'		width="' + width + '" height="' + height + '">' + 
	'		<param name="movie" value="' + file + '" />' + 
	'	<!--><!---->' + 
	'		<param name="loop" value="true" />' + 
	'		<param name="wmode" value="transparent" />' +
	'		<param name="menu" value="false" />' + 
	'		' + 	
	'		' + alt + '' + 
	'	</object>' + 
	'	<!-- <![endif]-->' +
	'</div>'
	);
}

function getMplayerCode(file, width, height, alt) {
	//alert('Budu zobrazovat video.');
	document.write('' +
	'<div id="video">' +
	'	<object id="MediaPlayer" name="MediaPlayer"' +
	'	  classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"' +
	'	  codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"' +
	'	  width="' + width + '" height="' + height + '"' +
	'	  standby="Nahrávají se součásti Microsoft Windows Media..."' +
	'	  type="application/x-oleobject">' +
	'	  <param name="filename" value="' + file + '" />' +
	'	  <param name="autosize" value="0" />' +
	'	  <param name="autostart" value="1" />' +
	'	  <param name="animationatstart" value="1" />' +
	'	  <param name="clicktoplay" value="1" />' +
	'	  <param name="displaysize" value="1" />' +
	'	  <param name="showcontrols" value="0" />' +
	'	  <param name="showaudiocontrols" value="0" />' +
	'	  <param name="showdisplay" value="0" />' +
	'	  <param name="showgotobar" value="0" />' +
	'	  <param name="showpositioncontrols" value="0" />' +
	'	  <param name="showstatusbar" value="0" />' +
	'	  <param name="showtracker" value="0" />' +
	'	  <param name="transparentatstart" value="1" />' +
	'	  <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"' +
	'	    src="' + file + '" filename="' + file + '"' +
	'	    name="MediaPlayer" id="MediaPlayer"' +
	'	    width="' + width + '" height="' + height + '"' +
	'	    autosize="0"' +
	'	    autostart="1"' +
	'	    animationatstart="1"' +
	'	    clicktoplay="1"' +
	'	    displaysize="1"' +
	'	    showcontrols="0"' +
	'	    showaudiocontrols="0"' +
	'	    showdisplay="0"' +
	'	    showgotobar="0"' +
	'	    showpositioncontrols="0"' +
	'	    showstatusbar="0"' +
	'	    showtracker="0"' +
	'	    transparentatstart="1">' +
	'	  </embed>' +
	'	</object>' +
	'	<noembed>' +
	'	  <a href="' + file + '" target="_blank">Stáhnout video</a><br />' +
	'	</noembed> ' +
	'</div>');
}



function changeIlustration(ilustrations, element_id) {
	 var ilu_index = Math.floor(ilustrations.length*(Math.random()%1));
	 var ilu = ilustrations[ilu_index];
	 
	 element = document.getElementById(element_id);
	 element.style.backgroundImage = "url('" + ilu + "')";
}

function text_transform() {
	var paragraphs = document.getElementsByTagName('p');
	var p_count = paragraphs.length;
	var spans = document.getElementsByTagName('span');
	var s_count = spans.length;
	
	for (var i=0; i<p_count; i++) paragraphs[i].innerHTML = transform(paragraphs[i].innerHTML);
	for (var i=0; i<s_count; i++) if (spans[i].className == 'convert') spans[i].innerHTML = transform(spans[i].innerHTML);
	
}

// provede rozhazeni znaku textu
function transform(text) {
	
	// akce se znakem
	var actions = new Array (
		'',
		'',
		'font-size: 1.2em; ',
		'font-size: 0.8em; ',
		'color: #444444; ',	// svetlejsi
		'color: #282828; ',	// tmavsi
		'font-weight: bold; '
	);
	var max_spaces = 2;	// nejvetsi pocet mezer misto jedne mezery
	
	
	content = text;
	// jen odstavce bez tagu (pro jistotu)
	if (content.indexOf('<')==-1) {
		new_content = '';
		for (var j=0; j<content.length; j++) {
			char = content.charAt(j);
			
			if (char==' ') {
				// za mezeru vlozime nekolik pevnych mezer
				spaces = Math.ceil(Math.random()*max_spaces) - 1;
				//alert('Vlozime mezer: '+ spaces);
				new_content = new_content + ' ';
				for (k=0; k<spaces; k++) new_content = new_content + '&nbsp;';
				
			} else {
				// vybereme akci, kterou provedeme se znakem
				action = Math.ceil(Math.random()*actions.length);	
				new_content = new_content + '<span style="' + actions[action] + '">' + char + '</span>';
			}				
		}
		return new_content;
	} else return '';
}
