function showrightels(name,rows)
{
        objA = document.getElementById(name+'A');
        objDiv = document.getElementById(name+'Div');

        if (objA == null || objDiv == null)
                return;

        var els = parseInt((objDiv.offsetWidth-objA.offsetWidth*0.1) / objA.offsetWidth);
        if (els == 0)
                return;

	if (rows > 1) els = els*rows;

/**
	alert('A:'+objA.offsetWidth+':'+objA.offsetHeight+
		', P:'+objDiv.offsetWidth + 
		', DLEFT:'+objDiv.offsetLeft + 
		', DTOP:'+objDiv.offsetTop + 
		', ALEFT:'+objA.offsetLeft + 
		', ATOP:'+objA.offsetTop + 
		', Els:'+ els);
**/

        for (i=2;i<=els;i++) 
        {
                obj = document.getElementById(name+i);
                if (obj != null)
                {
                        obj.style.display = 'block';
                }
        }
}

var rightthumbs = new Array;
var rightmore = new Array;
registerrightmore('RightAds');

// just register
function showrightthumbs(name, first, last, index) {
	rightthumbs[rightthumbs.length] = new showright(name, first, last, index);
}

function registerrightmore(name) {
	rightmore[rightmore.length] = name;
}

function showright(name, first, last, index) {
	this.name = name;
	this.first = first;
	this.last = last;
	this.index = index;
}

function dorightthumbs() {
	for (i=0;i<rightthumbs.length;i++)
	{
		cur = rightthumbs[i];
		showrightthumbsobjects(cur.name, cur.first, cur.last, cur.index);
	}
		
}

function getobjProp(obj,styleProp) {
	var y = 0;
	if (obj != null) {
		if (obj.currentStyle) {
			if (obj.currentStyle[styleProp])
				y = obj.currentStyle[styleProp];

		}else if (window.getComputedStyle) {
			y = document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);
		}
	}
	if (y == null) y = 0;
	return y;
}

function showrightthumbsobjects(name, first, last, index) {

	var pic_height = 77;
	var pic_width = 77;
	var adsheight = 0;
	var brh = getBrowserHeight();
	outobj = document.getElementById(name+'_container');

	if (last == null || last == 0 || brh == 0 || outobj == null || outobj.offsetHeight == 0)
		return(false);

	var curtop = 0;
	var tmpobj = outobj;
	if (tmpobj.offsetParent) {
		curtop = tmpobj.offsetTop
		while (tmpobj = tmpobj.offsetParent) {
			curtop += tmpobj.offsetTop
		}
	}
	
	if (curtop == 0) return(false);

	// minus all that must be shown
	for (i=0;i<rightmore.length;i++) {
		tmpobj = document.getElementById(rightmore[i]);
		if (tmpobj != null)
		{
			var marginTop = parseInt(getobjProp(tmpobj,'margin-top'));
			brh = brh - tmpobj.offsetHeight - marginTop;
		}
	}

	var pics_in_row = parseInt(outobj.offsetWidth / pic_width);
	var max_rows = parseInt((brh - curtop) / pic_height);

	if (max_rows <= 2) max_rows = 2;
	// 800x600
	if (pics_in_row < 2 && max_rows <= 3) max_rows = 4;
	var max_els = parseInt(pics_in_row * max_rows);


	var half = Math.floor(max_rows / 2);
	var start = Math.floor((index - half*pics_in_row) / pics_in_row)*pics_in_row + (1-half % 2)*pics_in_row;

	var end = start + max_els - 1;
	if (Math.floor(end/pics_in_row) > Math.floor(last/pics_in_row)) {
		end = last;
		start = Math.ceil((last - max_els) / pics_in_row)*pics_in_row;
	}

	if (start < 0) {
		start = 0;
		end = start + max_els - 1;
	}

	// 2 rows hack - last picture always dissapears
	if (end == index && index != last) {
		end += pics_in_row;
		start += pics_in_row;
	}

// no prev thumb
//	if (index > 0) start++;

	if (index < last && end <= last) {
		end--;

// no next/prev thumb any more
//		if ((end+2) % pics_in_row != 0) {

		// if the last row is'nt full yet
		if (end % pics_in_row != 0) {
			end++;
			//alert('start: '+start + ', end: ' +end + ',first: '+first+', last:'+last);
		}
	}

	for (i=first;i<=last;i++) {
		obj = document.getElementById('pic'+i);
		if (obj != null) {
			if (i>= start && i<=end) {
				obj.style.display = 'block';
			}else{
				obj.style.display = 'none';
			}
		}
	}
}

function getBrowserHeight() {
	h = 0;

	//Non-IE
	if( typeof( window.innerWidth ) == 'number' ) {
		h = window.innerHeight;

	//IE 6+ in 'standards compliant mode'
	} else if ( document.documentElement && document.documentElement.clientHeight) {

		h = document.documentElement.clientHeight;

	//IE 4 compatible
	} else if( document.body && document.body.clientHeight ) {
		
		h = document.body.clientHeight;
	}
	return(h);
}
