	var winW = 10;
	var winH = 10;
	var lSrc = '';
	var done = '';
	
	function show(id){ document.getElementById(id).style.display = 'block';}
	function hide(id){ document.getElementById(id).style.display = 'none';}

	function getWindowsize(){
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	}

	function BuildCache(prefix, amount)
	{		
		Cache = new Array();
		for (var c = 0; c < amount; c++)
			Cache[c] = document.getElementById (prefix + c);
	}
	
	function count_R(){ var p = 1; alert(p); return p;}
	
	function block(wi1B, wi2B, wiW, heW){
		
		hide('formCont');		
		//show('loading');
		var h = 1;
		var generated_content = '';
		
		//if(document.getElementById('loading').style.display == 'block'){ h = 1;}
				
		if(h == 1){
		for (i = 0; i < limit; i++){
			
			var width = Math.round(Math.random()*wi2B);

			if(width > wi2B){width = wi2B;}
			else if (width < wi1B){width = wi1B;}
		
			var posX = Math.floor(Math.random()*wiW);
			var posY = Math.floor(Math.random()*heW);
			
			if(lSrc == ''){		
			var block = '<div class="red" id="_bl_'+i+'" style="width:'+width+'px;height:'+width+'px;left:'+posX+'px;bottom:'+posY+'px;'+style+';"></div>';
			}else{

			var block = '<div class="red" id="_bl_'+i+'" style="width:auto;height:auto;left:'+posX+'px;bottom:'+posY+'px;'+style+';">'+
					'<img width='+width+' src="'+lSrc+'" alt="" /></div>';													
			}
			
			generated_content = generated_content + block;
				
		//if(i == (limit-1) ) {done = 1;/*hide('loading');*/}
		}
		}
		
		return generated_content;
	}
	
	var limit = 10;
	
	var size1 = 1;
	var size2 = 50;
	var style = '';	
	var maxlimit = 1000;
	

	function open_close()
	{	
		if(n < limit)
			{
		var Span = Cache[n];
			Span.style.display = 'block';
			setTimeout("open_close();",100);
			n +=1;
			return;
		}else
			{		
			show('formCont');
			//document.getElementById('bubble').style.display = 'block';
			//document.getElementById('bubble').src = 'toshow/bubble.gif';
			}
			
	}
	
	function start(){
		
		//hide('formCont');		
		//show('loading');

			getWindowsize();

			var obj = document.getElementById('content');		
			var fff = block(size1,size2, winW, winH);			
				
			//if(done == 1){
				
				obj.innerHTML = fff;
				BuildCache('_bl_',limit);	
				n = 0;
				open_close();
			//}
		
		//}else{
		//	document.getElementById('formCont').style.display = 'block';		
		//}
	}
	
	function IsNumeric(strString)
	   //  check for valid numeric strings	
	   {
	   var strValidChars = "0123456789";
	   var strChar;
	   var blnResult = true;

	   if (strString.length == 0) return false;

	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
	      {
	      strChar = strString.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	         blnResult = false;
	         }
	      }
	   return blnResult;
	   }

	
function validate(bgDoc, bgBlock, borderBlock, blocks, loc_size1, loc_size2, opacityBlock, bColorBlock, image){
	var error = 0;
	if(blocks.length < 1 || IsNumeric(blocks) == false){alert('А что рисовать-то? Ноль блоков??'); return false;error = 1;}	
	else if(loc_size1.length < 1 || IsNumeric(loc_size1) == false){alert('Введи размеры н-о-р-м-а-л-ь-н-о'); return false;error = 1;}
	else if(loc_size2.length < 1 || IsNumeric(loc_size2) == false){alert('Введи размеры н-о-р-м-а-л-ь-н-о'); return false;error = 1;}
	//else if(loc_size1 > loc_size2){alert('сказали ж ОТ и ДО, а не наоборот'); return false;error = 1;}

	if(error != 1){	
	
		document.getElementById('content').innerHTML = '';

			if(bgDoc.length > 0){ document.getElementById('content').style.backgroundColor = bgDoc;}
			if(bgBlock.length > 0){ changecss('.red','background',bgBlock);
			//style = style + 'background-color:' + bgBlock +';';
			}
			if(borderBlock.length > 0){ 
			changecss('.red','borderColor',borderBlock);
			
			}
			if(bColorBlock.length > 0){
			//style = style + 'border-width:' + bColorBlock +'px;';
			changecss('.red','borderWidth',bColorBlock +'px;');
			}
			if(opacityBlock.length > 0){ 
				changecss('.red','filter','alpha(opacity='+opacityBlock+')');
				changecss('.red','-moz-opacity',(opacityBlock/100));
				changecss('.red','opacity',(opacityBlock/100));
				//style = style + 'filter:alpha(opacity='+opacityBlock+');-moz-opacity:.'+opacityBlock+';opacity:.'+opacityBlock+';';
				}
			if(image.length > 0){ 				
				var p = '/';
				//lSrc = 'file:///'+image.replace(/\\/g, p);
				lSrc = image.replace(/\\/g, p);
				//alert(lSrc);
				//return false;
			}else{lSrc = '';}
			//alert(image);
			limit = (blocks > maxlimit)? maxlimit : blocks;
			size1 = loc_size1;
			size2 = loc_size2;

			start();
		
		return false;
	}
	return false;
}

var en = new Array();
en[0] = 'background color';
en[1] = 'blocks` color';
en[2] = 'blocks` border color';
en[3] = 'border width';
en[4] = 'opacity %';
en[5] = 'amount of blocks';
en[6] = 'blocks` size';
en[7] = 'from';
en[8] = 'to';
en[9] = 'picture';
en[10] = 'draw';

var ru = new Array();
ru[0] = 'цвет фона';
ru[1] = 'цвет блоков';
ru[2] = 'цвет границ';
ru[3] = 'толщина границ';
ru[4] = 'прозрачность %';
ru[5] = 'кол-во блоков';
ru[6] = 'размеры блоков';
ru[7] = 'от';
ru[8] = 'до';
ru[9] = 'картинка';
ru[10] = 'рисовать';

function translate(arr){
	
	var lang = document.getElementById('form').getElementsByTagName('span');
	
	for(i = 0; i < (arr.length-1); i++){
		//alert(lang[i].innerHTML);
		lang[i].innerHTML = arr[i];
	}	
	document.getElementById('sub').value = arr[arr.length-1];
}

function changecss(theClass,element,value) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	}
	else {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}
}

function showorhide(id){ 
	var ob = document.getElementById(id);	
	if(ob.style.display != 'none'){ob.style.display = 'none';}
	else{ob.style.display = 'block';}
}