function equalize_thumbs() {
	var thumb_max_height=0;
	var div=document.getElementsByTagName('div');
	for(var z=0; z<div.length; z++) 
	{
		if(div[z].className=='thumbnail_list equalize_thumbs') 
		{
			var thumb=div[z].getElementsByTagName('a');
			if(thumb && thumb.length)
			{
				var thumb_width = thumb[0].offsetWidth + 20;
				var thumb_inline = Math.floor((div[z].offsetWidth + 20)/thumb_width);
				var thumb_rows = Math.ceil(thumb.length/thumb_inline);
				for (i=0; i<thumb_rows; i++) 
				{
					for (n=0; n<thumb_inline; n++) 
					{
						var id = (i*thumb_inline)+n;
						var e = thumb[id];
						if (e) 
						{
							if (thumb_max_height <= e.offsetHeight ) { 
								thumb_max_height = e.offsetHeight;
							}
						}
					}

					for (n=0; n<thumb_inline; n++) 
					{
						var id = (i*thumb_inline)+n;
						var e = thumb[id];
						if (e) {
							e.style.height = thumb_max_height+"px";
						}
					}
					thumb_max_height = 0;
				}
			}
		}
	}
}

function equalize_products() {
	var thumb_max_height=0;
	var box_max_height=0;
	var div=document.getElementsByTagName('div');
	for(var z=0; z < div.length; z++) {
		if(div[z].className=='products_list equalize_thumbs') {
			var thumb=div[z].getElementsByTagName('div');
			var thumb_width = thumb[0].offsetWidth;
			var thumb_inline = Math.floor((div[z].offsetWidth)/thumb_width);			
			var thumb_rows = Math.ceil(thumb.length/thumb_inline);						
				for (i=0; i < thumb_rows; i++) {
					for (n=0; n < thumb_inline; n++) {
						var id = (i*thumb_inline)+n;
						var e = thumb[id];
						if (e && (e.className == 'product_box' || e.className == 'product_box odd')) {	
							var children = e.childNodes;
							if (box_max_height <= e.offsetHeight) { 
								box_max_height = e.offsetHeight;
							}							
							pic = e.getElementsByTagName('img')
							a = pic[0];
							if(thumb_max_height <= a.offsetHeight ) { 
								thumb_max_height = a.offsetHeight;
							}							
						}
					}
					for (n=0; n<thumb_inline; n++) {
						var id = (i*thumb_inline)+n;
						var e = thumb[id];
						if (e && (e.className == 'product_box' || e.className == 'product_box odd')) {											
							pic = e.getElementsByTagName('img')
							pic[0].style.marginTop = (thumb_max_height-pic[0].offsetHeight)/2+"px";
							pic[0].style.marginBottom = (thumb_max_height-pic[0].offsetHeight)/2+"px";
							e.style.height = box_max_height + "px";
						}
					}
					box_max_height = 0;
					thumb_max_height = 0;
			}
		}
	}
}

function refresh_kcaptcha(url,obj) {
	if(url.href){
		document.getElementById(obj).src=url.href+ '&' + Math.random();
	}
	return false;
}

function hide_extra_name() {
	if(document.getElementById('extra_name')){
		document.getElementById('extra_name').style.display = 'none';
	}
}

var scroller = null;
var timeout = 50;
var step = 0;
var correction = 344;
var loop = null;
var scrollerX = -1*correction;

function scroll_clients(){
	scroller = document.getElementById('scroller');
	if(scroller.getElementsByTagName('div').length < 4) return;
	//scroller.style.left = 0 + "px";
	//rebuild();
	scroll_looper();	
}
function rebuild(){
	content = '';
	//string = /<div class=\"product_box\"(.|\s)+?<\/div>/im
	//scroller.innerHTML = scroller.innerHTML.replace(string, '') + scroller.innerHTML.match(string)
	thumbs = scroller.getElementsByTagName('div');
	for(i=1; i<thumbs.length; i++){		
		content = content + '<div class="product_box">' + thumbs[i].innerHTML + '</div>';
	}
	content = content + '<div class="product_box">' + thumbs[0].innerHTML + '</div>';
	scroller.innerHTML = content;
	scrollerX = scrollerX + correction;			
	scroller.style.left = scrollerX + "px";	
	equalize_products();
	//loop = setTimeout("scroll_looper()",timeout);	
}
function scroll_looper(){
	clearTimeout(loop);
	scrollerX = (parseFloat(scroller.style.left))?parseFloat(scroller.style.left):0;
	if(step>=correction) {
		step = 0;
		rebuild();		
		//return;
	}
	step++;
	scroller.style.left = (scrollerX-1) + "px";
	loop = setTimeout("scroll_looper()",timeout);	
}	
