/**
 * Core
 */
this.getSelf = function() {
	if(self) {
		return self;
	}
	return null;
}
this.getDocument = function() {
	if(this.getSelf().document) {
		return this.getSelf().document;
	}
	return null;
}
this.getLayer = function(id) {
	if(this.getDocument().getElementById) {
		return this.getDocument().getElementById(id);
	} else if(this.getDocument().all) {
		return this.getDocument().all[id];
	} else if(this.getDocument().layers) {
		return this.getDocument().layers[id];
	}
	return null;
}
this.getStyle = function(id) {
	if(this.getLayer(id)) {
		if(this.getLayer(id).style) {
			return this.getLayer(id).style;
		}
		return this.getLayer(id);
	}
	return null;
}
this.getOpacity = function(id) {
	if (typeof this.getStyle(id).opacity == 'string') {
		return 'opacity';
	} else if (typeof this.getStyle(id).MozOpacity == 'string') {
		return 'MozOpacity';
	} else if (typeof this.getStyle(id).KhtmlOpacity == 'string') {
		return 'KhtmlOpacity';
	} else if (this.getStyle(id).filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) {
		return 'filter';
	}
	return null;
}

/**
 * Functions
 */
var bool = null;
var prev = null;
var next = null;
var setTimer = null;
var setWidth = null;
var setHeight = null;
var setSecondA = 0;
var setSecondB = 0;
var fontWeightPrev = null;
var fontWeightNext = null;
var arrowRight = 'http://www.seolib.ru/themes/default/images/arrow_right.png';
var arrowDown = 'http://www.seolib.ru/themes/default/images/arrow_down.png';


function setDisplay(id) {
	this.getStyle(id).display = (this.getStyle(id).display == '') ? 'none' : '';
}

function setImg(id, a1, b1) {
	this.getLayer(id).src = (this.getLayer(id).src == b1) ? a1 : b1;
}

function setOpacity(id, opacity) {
	var getOpacity = this.getOpacity(id);
	if (getOpacity == 'filter') {
		opacity *= 100;
		var alpha = this.getLayer(id).filters['DXImageTransform.Microsoft.alpha'] || this.getLayer(id).filters.alpha;
		if (alpha) {
			alpha.opacity = opacity;
		} else {
			this.getStyle(id).filter += 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
		}
	} else {
		this.getStyle(id)[getOpacity] = opacity;
	}
}

function setSmoothShow(id, max){
	var opacity = (this.getStyle(id).opacity)?parseFloat(this.getStyle(id).opacity):parseInt(this.getStyle(id).filter)/100;
	if(opacity <= max) {
		if(opacity >= 1) {
			return;
		}
		clearTimeout(setTimer);
		opacity += 0.1;
		setOpacity(id, opacity);
		setTimer=setTimeout('setSmoothShow(\''+ id +'\', '+ max +')', 20);
	}
}
function setSmoothHide(id, max) {
	opacity = (this.getStyle(id).opacity)?parseFloat(this.getStyle(id).opacity):parseInt(this.getStyle(id).filter)/100;
	if(opacity >= max) {
		if(opacity <= 0.11) {
			setOpenChart(id);
			return 1;
		}
		
		clearTimeout(setTimer);
		opacity -= 0.1;
		setOpacity(id, opacity);
		setTimer=setTimeout('setSmoothHide(\''+ id +'\', '+ max +')',20);
		
	}
}
/*
function setSize(position) {
	if(setHeight < position) {
		clearTimeout(setTimer);
		setHeight+=5;
		setTimer = setTimeout('setSize('+ position +')', 25);
	} else {
		clearTimeout(setTimer);
		if(setHeight > position) {
			setHeight-=5;
			setTimer = setTimeout('setSize('+ position +')', 25);
		}
	}
	this.getStyle("Loading").height = setHeight + 'px';
}
*/

function setSize(position) {
	if(setHeight < position) {
		clearTimeout(setTimer);
		setHeight+=5;
		setTimer = setTimeout('setSize('+ position +')', 25);
		if(setHeight == position) {
			setDisplay('loading');
			setOpacity('loading', 0);
			setSmoothShow('loading', 1);
		}
	}
	this.getStyle("Loading").height = setHeight + 'px';
}

function setGenerate() {
	if(setSecondB == 60) {
		setSecondB = 0;
		setSecondA++;
	}
	setSecondB++;
	switch(setSecondB) {
		case 0: {
			setSecondB = '00';
			break;
		}
		case 1: {
			setSecondB = '01';
			break;
		}
		case 2: {
			setSecondB = '02';
			break;
		}
		case 3: {
			setSecondB = '03';
			break;
		}
		case 4: {
			setSecondB = '04';
			break;
		}
		case 5: {
			setSecondB = '05';
			break;
		}
		case 6: {
			setSecondB = '06';
			break;
		}
		case 7: {
			setSecondB = '07';
			break;
		}
		case 8: {
			setSecondB = '08';
			break;
		}
		case 9: {
			setSecondB = '09';
			break;
		}
	}
	this.getLayer('generate').innerHTML = '<h4 class="H4" id="time">' + setSecondA +'.'+setSecondB+' ρεκ.</h4>';
}

function setLoading(id) {
	setInterval('setGenerate()', 15);
	setDisplay(id);
	setSize(50);
}

function setOpenList(id) {
	setDisplay(id);
	setOpacity(id, 0);
	setSmoothShow(id, 1);
	setImg(id+'Img', arrowRight, arrowDown);
}

function setOpenChart(id) {
	setDisplay(id);
	setOpacity(id, 0);
	setSmoothShow(id, 1);
}

var arrowRight2 = 'http://currentdev.seolib.ru/themes/default/images/triangle_right.gif';
var arrowDown2 = 'http://currentdev.seolib.ru/themes/default/images/triangle_bottom.gif';

function setOpenList2(id) {
	setDisplay(id);
	setOpacity(id, 0);
	setSmoothShow(id, 1);
	setImg(id+'Img', arrowRight2, arrowDown2);
}

function getTags (name) {
	var tag = null;
	tag = document.getElementsByName(name);
	if(tag.length != 0) {
		return tag;
	} else {
		tag = document.getElementsByTagName(name);
		if(tag.length != 0) {
			return tag;
		}
	}
	return null;
}

function setClassByTag(tag, get, set) {
	var tr = getTags(tag);
	for (var i = 0; i < tr.length; i++) {
		if(tr[i].className == get) {
			tr[i].className = (tr[i].className == get) ? set : get;
		}
	}
}

function getList(tag, get, set) {
	if(bool == get) {
		setClassByTag(tag, set, get);
		bool = null;
	} else {
		setClassByTag(tag, get, set);
		bool = get;
	}
	setImg(get+'Img', arrowRight, arrowDown);
}

function setBackgroundColor(element, color) {
	if(prev != null){
		prev.style.backgroundColor = next;
	}
	prev = element;
	next = element.style.backgroundColor;
	element.style.backgroundColor = color;
}

function setFontWeight(element, weight) {
	if(fontWeightPrev != null){
		fontWeightPrev.style.fontWeight = fontWeightNext;
	}
	fontWeightPrev = element;
	fontWeightNext = element.style.fontWeight;
	element.style.fontWeight = weight;
}
