function MM_openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

window.onload = function () {
	startList();
	startVideoNav();
	redSlider();
	doWelcome('show');
	
	if(document.getElementById('relation-list-slider')){
		var watch_relations=new ScrollMenu;
		watch_relations.go('relation-list-slider','relation-list','scrollbar','scroller');
	}
	if(document.getElementById('relation-list-slider2')){
		var watch_relations2=new ScrollMenu;
		watch_relations2.go('relation-list-slider2','relation-list2','scrollbar2','scroller2');
	}
}

function doWelcome(action) {
	var conteiner=document.getElementById('welcome');
	var usernamecontainder=document.getElementById('username');
	if (usernamecontainder) {
		var username = usernamecontainder.innerHTML;
		if(conteiner && username != '') {
			if (action == 'show') {
				conteiner.className="welcome visible";	
			} else {
				conteiner.className="welcome invisible";
			}
		}
	}
}


function doWelcomeVK(action) {
	var conteiner=document.getElementById('welcome');
	var conteinertarget=document.getElementById('welcome-text');
	var conteinersource=document.getElementById('welcome-vk-text');
	if(conteiner && conteinertarget && conteinersource) {
		if (action == 'show') {
			conteiner.className="welcome-vk visible";
			conteinertarget.innerHTML=conteinersource.innerHTML;
		} else {
			conteiner.className="welcome-vk invisible";
		}
	}
}



/* всплывающе верхнее меню by vatokato */
function startList() { 
	if (document.getElementById("topnav")) { 
		var navRoot = document.getElementById("topnav"); 
		for (i=0; i<navRoot.childNodes.length; i++) { 			
			var node = navRoot.childNodes[i]; 					
			if (node.nodeName=="LI") { 
				node.onmouseover=function() { 
					// добавим ширину если нужно
					if(this.childNodes[2]&&this.childNodes[2].nodeName=="UL") {
						this.childNodes[2].style.display="block";
						if(this.childNodes[2].clientWidth<=this.offsetWidth)
						this.childNodes[2].style.width=this.offsetWidth-20+"px"; // 20 - padding из css
					}
					// hover для ie6
					if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) { 
						this.className+=" hover"; 
						if(this.childNodes[2]&&this.childNodes[2].nodeName=="UL"&&document.getElementById("ie_hack")) {document.getElementById("ie_hack").style.visibility="hidden";}
					}
				} 
				node.onmouseout=function() { 
					if(this.childNodes[2]&&this.childNodes[2].nodeName=="UL") {
						this.childNodes[2].style.display="none";
					}
					// hover  для ie6
					if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) { 
						this.className=this.className.replace(" hover", ""); 
						if(this.childNodes[2]&&this.childNodes[2].nodeName=="UL"&&document.getElementById("ie_hack")) {document.getElementById("ie_hack").style.visibility="visible";}
					}
				} 
			} 
		} 
	} 
} 

/* всплывающе меню нового видеодрайва by nicky */
function startVideoNav() { 
	if (document.getElementById("videonav")) { 
		var navVideo = document.getElementById("videonav"); 
		for (i=0; i<navVideo.childNodes.length; i++) { 			
			var node = navVideo.childNodes[i]; 					
			if (node.nodeName=="LI") { 
				node.onmouseover=function() { 
					// hover для ie6
					if (/MSIE (5\.5|6|7).+Win/.test(navigator.userAgent)) { 
						this.className+=" hover"; 
					}
				} 
				node.onmouseout=function() { 
					if(this.childNodes[2]&&this.childNodes[2].nodeName=="UL") {
						this.childNodes[2].style.display="none";
					}
					// hover  для ie6
					if (/MSIE (5\.5|6|7).+Win/.test(navigator.userAgent)) { 
						this.className=this.className.replace(" hover", ""); 
					}
				} 
			} 
		} 
	} 
} 

/* TODAY NEWS  */
function today_news(obj) {
	var list=obj.parentNode.getElementsByTagName("a");
	for (i=0;i<list.length;i++) {
		list[i].className=list[i].className.replace("current", ""); 
	}
	obj.className+="current"; 	
}

/* BOTTOM RED SLIDER */
/*
var position=0;
var status=1;
function redSlider(obj,side) {	
	obj.ondblclick=function() {
		 var selection = window.getSelection ();                                        
         selection.removeAllRanges ();
		 return false;
	}
	var slider = document.getElementById('red-slider');
	var larrow = document.getElementById('left-arrow');
	var rarrow = document.getElementById('right-arrow');
	
	var blocks = slider.getElementsByTagName("div");
	var block_width = blocks[0].offsetWidth;
	var visible_width=slider.parentNode.offsetWidth; 
	var slider_width=block_width*blocks.length; 
	slider.style.width=slider_width+"px"; 
	var start_margin=position*block_width; 
	
	if(	side==1&&start_margin!=0&&status==1 ||
		side==-1&&Math.abs(start_margin)+visible_width!=slider_width&&status==1
		) { 
		
		status=0;	
		position=position+side;
		var end_margin=position*block_width; 
		var IE='\v'=='v'; 
		if(IE)	var step=20; 
		else var step=10;				
		if(side==-1) var step=-step;
		var tmp_pos=start_margin; 	
		var slide=setInterval( 		
		function () {	
			if(Math.abs(step)>Math.abs(end_margin-tmp_pos))	step=end_margin-tmp_pos;
			tmp_pos+=step;
			slider.style.marginLeft=tmp_pos+"px";			
			if(tmp_pos==end_margin) {
				clearInterval(slide);
				status=1;
			}
		}, 10);	
	}		
	
	if(side==1&&end_margin==0||side==1&&start_margin==0) 	
			larrow.className="no-active";
	else 	larrow.className="active";
	
	if(side==-1&&Math.abs(end_margin)+visible_width==slider_width||side==-1&&Math.abs(start_margin)+visible_width==slider_width) 
			rarrow.className="no-active";
	else 	rarrow.className="active";	
	
	

}
*/
/* BOTTOM RED SLIDER */
function redSlider() {	
	if(document.getElementById('red-slider')) {
	var IE='\v'=='v'; // хак определяет IE	
	var position=0; // для переноса блоков в начало и в конец
	var status=1; // можно скролить 

	var slider = document.getElementById('red-slider');
	var larrow = document.getElementById('left-arrow');
	var rarrow = document.getElementById('right-arrow');
	
	var blocks = slider.getElementsByTagName("div");
	var block_width = blocks[0].offsetWidth;
	var visible_width=slider.parentNode.offsetWidth; 
	var total_width=block_width*blocks.length; 	
	var sm=-178; 
	var em;	
	slider.style.width=total_width+"px"; // зададим правильную ширину
	
	// функции перетаскивания
	function insertBefore (em) {		
		slider.style.marginLeft=-block_width+"px";	
		slider.insertBefore(blocks[blocks.length-1],blocks[0]);		
		blocks = slider.getElementsByTagName("div");		
		sm=em=em-block_width; 
	}	
	function insertAfter (em) {
		slider.appendChild(blocks[0]);
		blocks = slider.getElementsByTagName("div");
		slider.style.marginLeft=em+block_width+"px";
		sm=em=em+block_width;
	}
	
	// перетащим последний в начало и пересобирем массив с блоками
 	insertBefore (0);
	
	// слайдер
	var start_slide;
	var course;
	var stop;
	
	function slide(obj,course) {
		stop=0;
		obj.ondblclick=function () {drop_select()}			
		if(status==1) {
			if(IE) var step=10; 
			else var step=5; // шаг слайдера
			em=sm+block_width;				
			if(course==1) {
				step=-step;
				em=sm-block_width;											
			}
			var tmp_step=step;			
			status=0; // нельзя скролить 			
			start_slide=setInterval( 		
			function () {	
				drop_select(obj);
				if(Math.abs(tmp_step)>=Math.abs(em-sm))	tmp_step=em-sm;
				sm+=tmp_step;
				slider.style.marginLeft=sm+"px";			
				if(sm==em) {					
					if(course==-1) insertBefore(em);
					else insertAfter (em); 		
					tmp_step=step;
					if(stop==1) {
						clearInterval(start_slide);
						stop=0;
						status=1;
					}					
				}				
			}, 10);	
		}	
	}
	
	larrow.onmousedown=function() {slide(this,-1)};
	rarrow.onmousedown=function() {slide(this, 1)};
	
	larrow.onmouseup=function() {stop=1};
	rarrow.onmouseup=function() {stop=1};
	larrow.onmouseout=function() {stop=1};
	rarrow.onmouseout=function() {stop=1};
	larrow.onmousemove=function() {stop=1};
	rarrow.onmousemove=function() {stop=1};
	
	function drop_select(obj) {
		if(!IE)	{
			var selection = window.getSelection ();                                        
		    selection.removeAllRanges ();
			return false;			
		}	
	}
	}
}

/* fix png */
function fixPNG(element) {
if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
var src;
if (element.tagName=='IMG') {
if (/\.png$/.test(element.src)) {
src = element.src;
element.src = "0.gif"; }}
else {
src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
if (src) {
src = src[1];
element.runtimeStyle.backgroundImage="none"; }}
if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')"; }}

/* Счетчик символов в текст-ареа */
function getFreeLength (obj, maximum, where, e)	{
	if (obj.value.length >= maximum) {
		obj.value=obj.value.substr(0,maximum);
	}
	document.getElementById(where).innerHTML = maximum-obj.value.length; 
}

function ctrlEnter (event, formElem)
{
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD))) {
    	//alert('here');
    	formElem.submit.click();
    }
}

function clearText (obj) {
	obj.innerHTML = ''; 
}

