var reClassNameCache = {}; // cache regexes for className
DOM = {
	/* метод из YUI, ищет по тегу и имени класса */
	getElementsByClassName: function(className, tag, root, apply) {
            tag = tag || '*';
            /* временно закроем root = (root) ? Y.Dom.get(root) : null || document; */
			root = document;
            if (!root) {
                return [];
            }

            var nodes = [],
                elements = root.getElementsByTagName(tag),
                re = getClassRegEx(className);

            for (var i = 0, len = elements.length; i < len; ++i) {
                if ( re.test(elements[i].className) ) {
                    nodes[nodes.length] = elements[i];
                    if (apply) {
                        apply.call(elements[i], elements[i]);
                    }
                }
            }
            
            return nodes;
        },
    getParamsFromClassName: function(classname) {
        // выделим только то, что касается параметров
        re = new RegExp('params\{(.*)\}');
        arr = re.exec(classname);
        params = arr[1];
        params = params.split(':');
        params_r = new Array();
        for(i=1;i<=params.length;i++) {
            if (i%2 == 0) {
                params_r[params[i-2]] = params[i-1];
            }
        }
        return params_r;
    }
		
}

/* общие методы */
var getClassRegEx = function(className) {
        var re = reClassNameCache[className];
        if (!re) {
            re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
            reClassNameCache[className] = re;
        }
        return re;
    };

/* определяем браузер */
var	isIE = false,
    isIE6 = false,
    isIE7 = false,
	isOpera = false,
	isFF = false;
whatBrowser = function() {
	var agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	isFF = ((agt.indexOf("mozilla")!= -1) && (agt.indexOf("msie") == -1));
	isIE = (agt.indexOf("msie") != -1);
	is_ie = (agt.indexOf("msie") != -1);
	var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    isIE6    = (isIE && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    isIE7    = (isIE && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
    isIE7up = (isIE && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !isIE6);
    //var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    
	isOpera = (agt.indexOf("opera") != -1);
}
whatBrowser();
//alert(isIE7up);
/* /определяем браузер */


/* функции определения стиля */
if(isIE) {
	getStyle = function(el, pr) {
		switch(pr) {
			case "opacity":
				var val = 100;
				try { // will error if no DXImageTransform
					val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
				}
				catch(e) {
					try { // make sure its in the document
						val = el.filters('alpha').opacity;
					}
					catch(e) {
					}
				}
                return val;
				break;
			default:
				return el.currentStyle[pr];
				break;
		}
	}
}
if(isFF || isOpera) {
	getStyle = function(el, pr) {
		switch (pr) {
			case "opacity":
				var comp = document.defaultView.getComputedStyle(el, '');
				return comp[pr]*100;
				break;
			default:
				var comp = document.defaultView.getComputedStyle(el, '');
				return comp[pr];
				break;
		}
	}
}
/* /функции определения стиля */

/* функции задания стиля*/
if(isIE) {
	setStyle = function(el, pr, value) {
		switch(pr) {
			case "opacity":
				val = value/100;
				el.style["opacity"]=val;
				el.style["-moz-opacity"]=val;
				el.style["-khtml-opacity"]=val;
				el.style.filter = "alpha(opacity=" + value + ")";
				break;
			default:
				el.style[pr] = value;
				break;
		}
	}
}
if(isFF || isOpera) {
	setStyle = function(el, pr, value) {
		switch(pr) {
			case "opacity":
				val = value/100;
				el.style["opacity"]=val;
				el.style["-moz-opacity"]=val;
				el.style["-khtml-opacity"]=val;
				break;
			default:
				el.style[pr] = value;
				break;
		}
	}
}
/* /функции задания стиля */

/* обращение к документу по имени */
if(isIE || isOpera) {
	getElementsByName = function(tag, name) {
		var elems = document.getElementsByTagName(tag);
		var arr = [];
		for(var i = 0; i < elems.length; i++) {
			if(elems[i].getAttribute("name") == name){ arr.push(elems[i]); }
        	}
		return arr;
	}
	
}
if(isFF) {
	getElementsByName = function(tag, name) {
	arr = document.getElementsByName(name);
	return arr;
	}
}


/* размер страницы */
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

