UlCenter = function(id_ul){
	var ul = document.getElementById(id_ul);
	if(ul == null){
		return true;
	}

	ul.style.width = '100%';
	
	var list = [];
	var summ = 0;
	var ul_w = $("#"+id_ul).innerWidth();
	
	var IE = ChekIE();
	
	$("#"+ id_ul +" li").each(
		function(){
			li_w = $(this).outerWidth();
			list[list.length] = li_w;
			summ += li_w;
		}
	);
	var free_width = ul_w - summ;
	if(free_width > 0){		
		var margin =  Math.ceil(free_width / (list.length + 1)) - 1;		
		if(margin > 0){
			$("#"+ id_ul +" li").css({
				'margin-left':margin + 'px',
				'margin-right':'0px'
			});
		}
		if(IE == 6) $("#"+ id_ul + " li:first").css('margin-left', Math.ceil(margin/2)+'px');
	}
	
	function ChekIE(){
		var IEversion = navigator.userAgent.match(/MSIE (\d)\.\d/);
		if(IEversion){
			return IEversion[1];
		}
		return false;
	}
}
getPosition = function (elem){
	var w = elem.offsetWidth;
    var h = elem.offsetHeight;	
    var l = 0;
    var t = 0;	
    while (elem){   
		l += elem.offsetLeft;
       	t += elem.offsetTop;
		elem = elem.offsetParent;  }
	return {"left":l, "top":t, "width": w, "height":h};
}
InputBlurText = function(elem_id,default_text){
	var id = elem_id;
	var text = default_text;
	var def_color = "#c4b5a0";
	var text_color = "#000000";
	var notext = 0;
	var elem = document.getElementById(id);
	if(elem == null) return true;
	
	if(elem.value == "" || elem.value==text) SetBlurText();
	$(elem).blur(function(){ if(this.value=="") SetBlurText(); });
	$(elem).focus(function(){ if(this.value==text) ClearBlurText(); });
	
	function SetBlurText(){
		//$(elem).css('color',color);
		elem.style.color = def_color;
		elem.value = text;
		notext = 1;
	}
	function ClearBlurText(){
		elem.style.color = text_color;
		elem.value = "";
		notext = 0;
	}
}
var ReszTimeoutId = false;
DocumentResize = function(){
	var H = $(window).height();
	var HeaderH = $("#header").height();
	var MaindocH = $("#maindoc").height();
	var FooterH = $("#footer").height();
	
	if(H > (HeaderH + MaindocH + FooterH)){
		$("#footer").css({'position':'absolute', 'bottom':'0px'});
	}else{
		$("#footer").css({'position':'static', 'bottom':'0px'});
	}
	$(window).resize(function () {
		if(ReszTimeoutId != false) clearTimeout(ReszTimeoutId);
		ReszTimeoutId = setTimeout( function () { DocumentResize(); } , 200);
	});
}
OpenCloseVideo = function(button_id,conteiner_id,strart){
	var button = document.getElementById(button_id);
	var VidCont = document.getElementById(conteiner_id);
	
	if(button==null ||VidCont==null){
		alert("нет id");
		return false;
	}
	var IntervalId = false;
	
	var EndH = $(VidCont).height();
	var time = 500;
	var interval = 40;
	var count = time/interval;
	var pos = EndH/count;
	
	if(strart){
		var Open = 1;
		var curentH = EndH;
	}else{
		var Open = 0;
		var curentH = 0;
	}
	SetPosition(curentH);
	
	$(button).click(function(){
		if(IntervalId) clearInterval(IntervalId);
		if(Open) CloseVideo(); else OpenVideo();
	});
	
	function SetPosition(h){
		VidCont.style.top = Math.round(h - EndH) + "px";
		curentH = h;
	}
	function OpenVideo(){
		Open = 1;
		IntervalId = setInterval(function(){
			var nextH = curentH + pos;
			if(nextH>=EndH){
				SetPosition(EndH);
				clearInterval(IntervalId);
				return true;
			}else{
				SetPosition(nextH);
			}
		},interval);
	}
	
	function CloseVideo(){
		Open = 0;
		IntervalId = setInterval(function(){
			var nextH = curentH - pos;
			if(nextH<=0){ 
				SetPosition(0);
				clearInterval(IntervalId);
				return true;
			}else{
				SetPosition(nextH);
			}
		},interval);
	}
}
function ChekQuestionForm(){
	if($('#in_question').val()=="" || $('#in_question').val()=="Вопрос"){
		alert("Вы не заполнили поле Вопрос!");
		$('#in_question').focus();
		return false;
	}
	if($('#in_name').val()=="" || $('#in_name').val()=="Имя"){
		alert("Вы не указали свое Имя!");
		$('#in_name').focus();
		return false;
	}
	if($('#in_phone').val()=="" || $('#in_phone').val()=="Телефон"){
		alert("Вы не заполнили поле Телефон!");
		$('#in_phone').focus();
		return false;
	}
	if($('#in_capcha').val()=="" || $('#in_capcha').val()=="Код"){
		alert("Вы не ввели Код с картинки!");
		$('#in_capcha').focus();
		return false;
	}
}

$(function(){
	DocumentResize();
	UlCenter("top_menu");
	UlCenter("foot_menu");
	
	/*var va_height=$("div#video_animate").height();
	$("div#video_animate").data("hidden","1");
	$("a#VideoOpenClose").bind("click",function(){
		var m=$("div#video_animate").data("hidden");
		if(m=="1"){
			$("div#video_animate").animate({top:0},500,function(){$(this).data("hidden","0");});
		} else {
			$("div#video_animate").animate({top:-va_height},500,function(){$(this).data("hidden","1");});
		}
	});*/
});
