/*
	width.js
	2011-01-19, Oleksandr
*/
if (getElement("page")) {
	var
		width,
		widthPrevious,
		page = getElement("page"),
		widthResize = false;
	
	if (widthResize && getCookie("widthModified")) {
		page.style.width = getCookie("widthModified") + (getCookie("widthModified") > 100 ? "px" : "%");
	}
	
	if (getCookie("widthClass")) {
		page.className = getCookie("widthClass");
	}
	
	function setWidth() {
		width = (!document.all) ? window.innerWidth : getBody().offsetWidth;
		
		if (widthPrevious != width) {
			widthPrevious = width;
		} else {
			return;
		}
		
		var
			className = "",
			widthCurrent = getCoordinates("page"),
			widthModified = (width > 1280) ? "1255" : "100";
		
		if (widthResize && widthCurrent.width != widthModified) {
			page.style.width = widthModified + (widthModified > 100 ? "px" : "%");
			setCookie("widthModified", widthModified , "", "/");
		}
		
		if (width <= 1024) {
			className = "screen1024";
		} else {
			className = (width >= 1280) ? "screen1280" : "";
		}
		
		if (page.className != className) {
			page.className = className;
			setCookie("widthClass", className , "", "/");
		}
	}
	window.setInterval("setWidth()", 100);
	
	if (widthResize) {
		var
			css = document.createElement("style");
		css.type = "text/css";
		css.media = "print";
		var
			style = "#page {width: 100% !important; height: auto !important;}";
		if (css.styleSheet) {
			css.styleSheet.cssText = style;
		} else {
			css.appendChild(document.createTextNode(style));
		}
		getHead().appendChild(css);
	}
}
