// JavaScript Document
var isCSS, isW3C, isIE4, isNN4;
//инициализация после загрузки, чтобы все браузеры успели
//сформировать структуру объектов
function initDHTMLAPI() {
	if(document.images)	 {
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false ;
		isNN4 = (document.layers) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
	window.onload = initDHTMLAPI;
}

// поиск вложенного объекта layer и NN4 по имени
function seekLayer(doc, name) {
	var theObj;
	for(var i = 0; i < doc.layers.length; i++) {
		if(doc.layers[i].name == name) {
			theObj = doc.layers[i];
			break;
		}
		// переходим к вложенным слоям, если такие есть
		if(doc.layers[i].document.layers.length > 0) {
			theObj = seekLayer(doc.layers[i].document, name);
		}
	}
	return theObj;
}

// Преобразуем строку с именем объекта или ссылку на объект
// в ссылку на элемент документа
function getRawObject(obj) {
	var theObj;
	if(typeof obj == "string") {
		if(isW3C) {
			theObj = document.getElementById(obj);
		} else if(isIE4) {
			theObj = document.all(obj);
		} else if(isNN4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		// Получаем ссылку на объект
		theObj = obj;
	}
	return theObj;
}

// Преобразуем строку с именем объекта или ссылку на объект
// в ссылку на объект стиля (или в ссылку на слой в NN4)
function getObject(obj) {
	var theObj = getRawObject(obj);
	if(theObj && isCSS) {
		theObj = theObj.style;
	}
	return theObj;
}

// распологаем объект по переданным кординатам
function shiftTo(obj, x, y) { 	
	var theObj = getObject(obj);
	if(theObj) {
		if(isCSS) {
			// преобразуем некоторые числовые значения
			var units = (typeof theObj.left == "string") ? "px" : 0;
			if(x != "undefined")
				theObj.left = x + units;
			theObj.top = y + units;
		} else if(isNN4) {
			theObj.moveTo(x,y)
		}
	}
}

function setZIndex(obj, zOrder) {
	var theObj = getObject(obj);
	if(theObj) {
		theObj.zIndex = zOrder;
	}
}