var ie = (document.all) ? true : false;
var timerID;

function GetSpanWidth() {
	var x1,w1;
	w1 = 1;
	for ( i = 0; i < document.styleSheets.length; i++ ) {
		if (ie) { x1 = document.styleSheets[i].rules; }
		else { x1 = document.styleSheets[i].cssRules; }
		for ( q = 0; q < x1.length; q++ ) {
			if (x1[q].selectorText == ".thumb_span") {
				w1 = parseInt(x1[q].style.width + 0);
			}
		}
	}
	return w1;
}

function GetSpanMargin() {
	var x1,w1;
	w1 = 1;
	for ( i = 0; i < document.styleSheets.length; i++ ) {
		if (ie) { x1 = document.styleSheets[i].rules; }
		else { x1 = document.styleSheets[i].cssRules; }
		for ( q = 0; q < x1.length; q++ ) {
			if (x1[q].selectorText == ".thumb_span") {
				w1 = x1[q].style.margin;
			}
		}
	}
	return w1;
}

function SetSpanMargin(m1) {
	for ( i = 0; i < document.styleSheets.length; i++ ) {
		var x1;
		if (ie) { x1 = document.styleSheets[i].rules; }
		else { x1 = document.styleSheets[i].cssRules; }
		for ( q = 0; q < x1.length; q++ ) {
			if (x1[q].selectorText == ".thumb_span") {
				x1[q].style.margin = m1;
			}
		}
	}
}

function Span_Resize() {
	SetSpanMargin("0px 5px 0px 5px");

	var span_count, span_margin, span_width, cw1;

	cw1 = document.body.clientWidth;
	
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		cw1 = document.body.clientWidth - 16;
	}

	span_width = GetSpanWidth();
	span_count = Math.floor(cw1 / span_width);
	span_margin = Math.floor((cw1 - span_count*span_width) / (span_count * 2));
	
	SetSpanMargin("0px "+span_margin+"px 0px "+span_margin+"px");
	//alert("CW=" + cw1 + "   SC="+span_count+"  SW="+span_width+"  SM="+span_margin);

}

function Resize() {
//	SetSpanMargin("0px 5px 0px 5px")
	var x=0;
	x = document.body.clientWidth - (17 + 5*123 + 123);
	x = Math.round(x / 2);
	if (x <= 7) { x = 3; }
	x = x + 17 + 5*123 + 38;
	
	x = x - 7;

	if (navigator.userAgent.indexOf("MSIE") != -1) {
		x = x - 0;
	}

	document.getElementById("SearchList1").style.left = x + "px";

	if (timerID) { clearTimeout(timerID); } 
	timerID = setTimeout("Span_Resize()",250);
	//timerID = setTimeout("alert('aa')",250);
	
}
