var isFirst = true;

function gE(id){
	return document.getElementById(id);	
}

function resize(main)
{
	var pogr = document.all?3:6;
	var imgwidth = 84;
	var avatarimg = 55;
	
	
	if (gE('photosList')){
		var parentwidth = gE('photosList').offsetWidth;
		objSizeTo(parentwidth, imgwidth, 'photosList', 2, 6);
	}
	if (gE('blogersList')) {
		var avatarwidth = gE('blogersList').offsetWidth;
		objSizeTo(avatarwidth, avatarimg, 'blogersList', 3, 4);
	}   
}

function objSizeTo(parentwidth,imgwidth,elemName,rows,minwidth)
{
	var count = Math.floor(parentwidth/(imgwidth + 5));
	var newWidth=Math.floor(parentwidth/count);
	if (gE(elemName)) {
		//var children = el.getElements();
		var childsList = gE(elemName).getElementsByTagName('a');
		
		for(i=0; i < childsList.length; i++)
		{
			if(i==(count-1) || i==(2*count-1) || i==(3*count-1) || i==(4*count-1)){ 				
				childsList[i].style.marginRight="0px";
			}else{
				childsList[i].style.marginRight=(newWidth-imgwidth-1)+"px";
			}
			childsList[i].style.marginBottom=(newWidth-imgwidth)+"px";
			if(elemName=='blogersList') {
				childsList[i].style.marginBottom="5px"
			}
		}
		
		gE(elemName).style.height=(newWidth*2-4)+"px";
		if(elemName=='blogersList')	{
			gE(elemName).style.height="180px";
		}
	}
}

function defaultresize()
{
	
	resize(false);
}

function remWord(elm)
{
	if(isFirst)
	{
		$(elm).value='';
		isFirst = false;
	}
}

function keyPress(e,elm)
{
	var key = (e) ? e.keyCode: event.keyCode;
	if (key == 13 ) sendForm(elm);
}

/**
 *  copy text from one text input to another
 * @param from - id name from element
 * @param to  - id name to element
 * return void
 */
 
function copyText(from,to){
	$(to).value = $(from).value
}

//
window.onresize = resize;