﻿/***    eQuery 2.0   */
/***    Johnny V. evgeny@land.ru  */


window.onerror = function() {
	return true;
}

oHTML = document.getElementsByTagName('html')[0];

var eQueryCss = document.createElement('link');
eQueryCss.rel = 'stylesheet';
eQueryCss.type = 'text/css';
eQueryCss.href = './scripts/eQuery/eQueryCss.css';
eQueryCss.media = 'all';
document.getElementsByTagName('head')[0].appendChild(eQueryCss);


function eQuery() {
    this.elements = function(myTag, myClass, query) { 
        if(myTag && myClass && query) { 
    		var myTag = myTag.toLowerCase();
   			var $ = document.getElementsByTagName(myTag);
   			var alltags = $.length;

    		for(var i = 0; i<=alltags; i++) {
    			if($[i]) {
    				if(myClass != '*') {
    					if($[i].className == myClass) {
    						query.call($[i]);
    					}
    				}
    				if(myClass == '*') {
    					query.call($[i]);
    				}
    			}
    		}
    	}
	}
	
	
	this.boxAnimation = function(elem, typeAnimation, speed) {
		if(!window.intervalID && elem && typeAnimation && speed) {
			if(elem.style.cssText != '') {
				defaultstyle = elem.style.cssText;
			}
			
			else {
				defaultstyle = '';
			}
			
			if(typeAnimation == 'appearance') { 
				elem.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
				elem.style.opacity = '0';
				elem.style.display = 'block';
				var param = 0;
				var IEparam = 0;
				
				function anim() {
					
					if(param < 10) {
						elem.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+IEparam+')';
						elem.style.opacity = '0.'+param;
						param++;
						IEparam = IEparam+25;;
					}
					
					else {
						clearInterval(intervalID);
						elem.removeAttribute('style');
						if(defaultstyle != false) {
							elem.style.cssText = defaultstyle;
						}
						delete intervalID;
					}
					
				}
				intervalID = setInterval(anim, speed);
			}
			
			if(typeAnimation == 'expand') { /*Развернуть блок*/
				if(window.expandIntervalID) { /*Проверяем есть ли интервал ID и если есть удаляем*/
					delete window.expandIntervalID;
				}
				
				elem.style.display = 'block'; /*Делаем блок видимым*/
				expandElemHeight = elem.offsetHeight;/*Снимаем его высоту и ширину*/
				expandElemWidth = elem.offsetWidth;
				elem.style.display = 'none'; /*Делаем блок не видимым*/
				
				
				expandTempBox = document.createElement('div'); /*Создаем новый элемент*/
				expandTempBox.style.width = expandElemHeight; /*Присваиваем ему такую же ширину и высоту, что и у основного блока*/
				expandTempBox.style.height = expandElemWidth;
				expandTempBox.style.display = 'inline-block';
				
				expandElemCode = elem.innerHTML; /*Забираем весь код из основного блока*/
				expandTempBox.innerHTML = expandElemCode; /*И копируем его в новый элемент*/
				elem.innerHTML = ''; /*Удаляем весь код из основного блока*/
				elem.appendChild(expandTempBox); /*Вставляем новый элемент с кодом в основной блок (что бы содержимое при развертывании не переносилось по срокам)*/
				
				expandHeightPercet = expandElemHeight/100*1; /*Получаем 1% от общей высоты*/
				expandWidthPercet = expandElemWidth/100*1; /*Получаем 1% от общей ширины*/
				
				expandH = 0; /*Это будет текущая непостоянная высота элемента*/
				expandW = 0; /*Это будет текущая непостоянная ширина элемента*/
				expandI = 1; /*Это будет счечик для увеличения скорости*/
				function expand() { /*Функция развертывания*/
					if(expandW < expandElemWidth-(expandWidthPercet*expandI)) { /*Если текущая ширина меньше предельной */
						expandI = expandI+speed; /*Увеличивам I на число заданное в скорости*/
						expandH = expandH+(expandHeightPercet*expandI);/*Увеличивам екущую не постоянную высоту на 1 процент * на скорость I*/
						expandW = expandW+(expandWidthPercet*expandI); /*Увеличивам текущую не постоянную ширину на 1 процент * на скорость I*/
						elem.style.overflow = 'hidden'; /*Ставим хидден, что бы дополнительный блок не вылезал за приделы*/
						elem.style.display = 'block'; /*Делаем элемент видимым*/
						elem.style.width = expandW+'px';/*Устанавливаеи на элемент не постоянную ширину*/
						elem.style.height = expandH+'px';/*Устанавливаеи на элемент не постоянную высоту*/
					}
					else {
						clearInterval(expandIntervalID);
						elem.innerHTML = expandElemCode; /*Возвращаем исходное значение без дополнительного элемента*/
					}
				}
				
				var expandIntervalID = setInterval(expand, 10) /*Запускаем сетинтервал*/
			}
			
			if(typeAnimation == 'wrap') { /*Завернуть блок*/
				if(window.wrapIntervalID) {
					delete window.wrapIntervalID;
				}
				
				elem.style.display = 'block';
				wrapElemHeight = elem.offsetHeight;
				wrapElemWidth = elem.offsetWidth;
				
				wrapTempBox = document.createElement('div');
				wrapTempBox.style.width = wrapElemWidth;
				wrapTempBox.style.height = wrapElemHeight;
				wrapTempBox.style.display = 'inline-block';
				
				wrapElemCode = elem.innerHTML;
				elem.innerHTML = '';
				wrapTempBox.innerHTML = wrapElemCode;
				elem.appendChild(wrapTempBox);
				
				wrapHeightPercet = wrapElemHeight/100*1;
				wrapWidthPercet = wrapElemWidth/100*1;
				wrapH = wrapElemHeight;
				wrapW = wrapElemWidth;
				wrapI = 1;
				
				if(navigator.appName == 'Microsoft Internet Explorer') {
					speed = 2;
				}
				
				function wrap() {
					if(3 <= wrapW) {
						wrapI = wrapI+speed;
						wrapH = wrapH-(wrapHeightPercet*wrapI);
						wrapW = wrapW-(wrapWidthPercet*wrapI);
						elem.style.overflow = 'hidden';
						elem.style.display = 'block';
						elem.style.width = wrapW+'px';
						elem.style.height = wrapH+'px';
					}
					
					else {
						elem.style.cssText = '';
						elem.style.display = 'none';
						clearInterval(wrapIntervalID);
						elem.innerHTML = wrapElemCode;
					}
					
				}
				var wrapIntervalID = setInterval(wrap, speed)
			}
		}
		
		else {
			return false;
		}
	}
	
	this.noimg = function() {
		
	}
	
	this.monitoring = function(myObj) {
		if(myObj) {
			var monitoringElem = document.createElement('div');
			monitoringElem.style.background = '#FFF';
			monitoringElem.style.color = '#333';
			monitoringElem.fontSize = '13px';
			monitoringElem.padding = '20px';
			for(var key in myObj) {
				monitoringElem.innerHTML += '<p style="padding: 5px 20px;"><b style="font-weight: bold; text-decoration: underline;">'+key+'</b>: '+myObj[key]+'</p>';
			}
			document.getElementsByTagName('body')[0].appendChild(monitoringElem);
		}
		else {
			return false;
		}
	}
	

	this.alert = function(eQueryAlertType, eQueryAlertMessage) {
		if(eQueryAlertType && eQueryAlertMessage) {
			if(eQueryAlertType == 'top') {
				if(window.alertTopBox) {
					alertTopBox.parentNode.removeChild(alertTopBox);
				}
			
				alertTopBox = document.createElement('div');
				
				alertTopBox.className = 'eQueryAlertTop';
				
				var alertMessage = document.createElement('div');
				alertMessage.className = 'eQueryAlertMessage';
				alertTopBox.appendChild(alertMessage);
				alertTopBox.title = "Закрыть";
				
				alertTopBox.onmouseover = function() {
					this.style.borderColor = '#FFF';
					this.style.backgroundColor = '#fff6cb';
				}
				
				alertTopBox.onmouseout = function() {
					this.style.borderColor = '';
					this.style.backgroundColor = '';
				}

				alertMessage.innerHTML += eQueryAlertMessage;
				document.getElementsByTagName('body')[0].appendChild(alertTopBox);

				i = 0 - alertTopBox.clientHeight;
				alertTopBox.style.top = i+'px';

				if(navigator.appName == 'Microsoft Internet Explorer') {
					speed = 12;
				}
				
				else {
					speed = 3;
				}
				
				function alertTopStart() {
					if(i < -2) {
						i = i+speed;
						alertTopBox.style.top = i+'px';
					}
					else {
							alertTopBox.style.top = '0px';
							clearInterval(indervalID);
							delete window.indervalID;
					}
				}
				indervalID = setInterval(alertTopStart, 1);
				
				alertTopBox.onclick = function() {
					this.onmouseout = function() {}

					maxTop = 0 - alertTopBox.clientHeight;
					i = 0;
					function alertTopStop() {
						if(i > maxTop) {
							i = i-speed;
							alertTopBox.style.top = i+'px';
						}
						else {
							clearInterval(indervalID);
							alertTopBox.parentNode.removeChild(alertTopBox);
							delete window.alertTopBox;
							delete indervalID;
						}
					}
					indervalID = setInterval(alertTopStop, 1);
				}
			}
			
			if(eQueryAlertType == 'bottom') {
				if(window.alertBottomBox) {
					alertBottomBox.parentNode.removeChild(alertBottomBox);
				}
			
				alertBottomBox = document.createElement('div');
				
				alertBottomBox.className = 'eQueryAlertBottom';
				
				var alertMessage = document.createElement('div');
				alertMessage.className = 'eQueryAlertMessage';
				alertBottomBox.appendChild(alertMessage);
				alertBottomBox.title = "Закрыть";
				
				alertBottomBox.onmouseover = function() {
					this.style.borderColor = '#FFF';
					this.style.backgroundColor = '#fff6cb';
				}
				
				alertBottomBox.onmouseout = function() {
					this.style.borderColor = '';
					this.style.backgroundColor = '';
				}

				alertMessage.innerHTML += eQueryAlertMessage;
				document.getElementsByTagName('body')[0].appendChild(alertBottomBox);

				i = 0 - alertBottomBox.clientHeight;
				alertBottomBox.style.bottom = i+'px';

				if(navigator.appName == 'Microsoft Internet Explorer') {
					speed = 11;
				}
				
				else {
					speed = 3;
				}
				
				function alertBottomStart() {
					if(i < -2) {
						i = i+speed;
						alertBottomBox.style.bottom = i+'px';
					}
					else {
							alertBottomBox.style.bottom = '0px';
							clearInterval(indervalID);
							delete window.indervalID;
					}
				}
				indervalID = setInterval(alertBottomStart, 1);
				
				alertBottomBox.onclick = function() {
					this.onmouseout = function() {}

					maxTop = 0 - alertBottomBox.clientHeight;
					i = 0;
					function alertBottomStop() {
						if(i > maxTop) {
							i = i-speed;
							alertBottomBox.style.bottom = i+'px';
						}
						else {
							
							clearInterval(indervalID);
							alertBottomBox.parentNode.removeChild(alertBottomBox);
							delete window.alertBottomBox;
							delete indervalID;
						}
					}
					indervalID = setInterval(alertBottomStop, 1);
				}
			}
		
			if(eQueryAlertType == 'default') {
				alert(eQueryAlertMessage);
			}
		}
		
	}
}

var eQuery = new eQuery();
