/**
 * @author Sergey Chikuyonok (gonarch@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru) 
 */

/**
 * 
 * currency-selector
 * sRootElement, sLinksTag, sCurrentClass
 */
function oSelect(sRootElement, sLinksTag, sCurrentClass)
{
	this.oRootElement = getElementsByClassName(document.getElementsByTagName('div'), sCurrentClass)[0];
	this.sLinksTag = sLinksTag;
	this.sCurrentClass = sCurrentClass;

	this.init()
}

oSelect.prototype = {
	init: function()
	{
		this.aElements = [];
		if(this.oRootElement)
			this.attachElements();
		
		this.onMouseOverBak = [];
	},
	attachElements: function()
	{
		var _this = this;
		this.ocLinks = this.oRootElement.getElementsByTagName(this.sLinksTag);
		for(var i=0; i < this.ocLinks.length; i++)
		{
			this.aElements[i] = this.ocLinks[i];
			Common.Event.add(this.ocLinks[i], 'click', function(){
				Common.Class.replace(_this.oRootElement, _this.sCurrentClass, this.id);
				_this.selectCurrentLink(this)
				_this.sCurrentClass = this.id;
			});
		}
	},
	selectCurrentLink: function(oElement)
	{
		for(var i=0; i < this.aElements.length; i++)
		{
			Common.Class.add(this.aElements[i], 'pseudo-href');
			if(!this.onMouseOverBak[i])
				this.onMouseOverBak[i] = this.aElements[i].onmouseover;
			else
				this.aElements[i].onmouseover = this.onMouseOverBak[i];
		}

		if(oElement.onmouseover != '')
			onMouseOverBak = oElement.onmouseover;
		
		Common.Class.remove(oElement, 'pseudo-href');
		Common.Class.remove(oElement, 'vHover');
		Common.Class.remove(oElement, 'hover');
		oElement.onmouseover = '';
	}
}

function switchSiteMenu(evt){
	if((evt=Common.Event.check(evt))){
 		var elem=evt.target;
 		do{
 			if(elem.nodeType == 1 && elem.nodeName == 'LI')
 				break;
 		}while(elem=elem.parentNode);
 		
 		if(elem){
			var ch=elem.parentNode.childNodes;
			for(var i=0; i<ch.length; i++){
				if(ch[i].nodeType == 1){
					if(ch[i] == elem)
						Common.Class.add(ch[i], 'expanded');
					else
						Common.Class.remove(ch[i], 'expanded');
				}
			}
 		}
 	}
}

function hideRegion(){
	var elemRegion=document.getElementById('Regions');
	if(elemRegion){
		hideMenu(elemRegion.parentNode);
	}
}

function pageLoaded(){
	attachMenuEvents();
	attachFootnoteEvents();
	Common.Event.add(document, 'click', hideRegion);

//	$('feedbackLink') ? attachFeedback() : null
}

function attachFeedback() 
{
	var oA = $('feedbackLink')
	Common.Event.add(oA, 'click', function(oEvent){
		Common.Event.cancel(Common.Event.normalize(oEvent))
		Common.Utils.popup('/feedback/', 'Обратная связь');
	})
}

function $(sId)
{
	return document.getElementById(sId)
}