 var hoverColour = "#ffbc66";
 var newData="";
// параметры для выравнивания всплывающих блоков
function popupValue(obj) {
	if (obj == 'width') {
		return window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
	}
	if (obj == 'height') {
		return window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
	}
	if (obj == 'top') {
		return window.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
	}
} 
 function popupLoad() {
	var top = popupValue('top');
	var width = popupValue('width');

	$('#loading').css({ top: top+140, left: width/3+100 });
}
 

$(function(){
	$("a.hoverBtn").show("fast", function() {
		$(this).wrap("<div class=\"hoverBtn\">");
		$(this).attr("class", "");
	});
	
	//display the hover div
	$(".hoverBtn").show("fast", function() {
		//append the background div
		$(this).append("<div></div>");
		
		//get link's size
		var wid = $(this).parent("li").width();
		var hei = $(this).parent("li").height();
		
		//set div's size
		$(this).width(wid);
		$(this).height(hei);
		$(this).children("div").width(wid);
		$(this).children("div").height(hei);
		
		//on link hover
		$(this).children("a").hover(function(){
			//store initial link colour
			if ($(this).attr("rel") == "") {
				$(this).attr("rel", $(this).css("color"));
			}
			//fade in the background
			$(this).parent().children("div")
				.stop()
				.css({"display": "none", "opacity": "1"})
				.fadeIn("fast");
			//fade the colour
			$(this)	.stop()
				.css({"color": $(this).attr("rel")})
				.animate({"color": hoverColour}, 350);
		},function(){
			//fade out the background
			$(this).parent().children("div")
				.stop()
				.fadeOut("slow");
			//fade the colour
			$(this)	.stop()
				.animate({"color": '#1a1106'}, 250);
		});
	});
});

function loadPage (docid,link,pageid){
$.ajax({
    url: '/ajax-news.html',
	type: "POST",
    dataType: 'html',
	data:{id:docid,page:pageid},
    beforeSend: function(xhr){
	    popupLoad();
	  $('#teni').show();
      $('#loading').show();
    },
    success: function(data){
	  $('#loading').hide();
	  $('#teni').hide();
	  $.scrollTo(0,300);
      //$('.newsBlock').html(data);
	  window.catalogAjax.data = data;
	  window.catalogAjax.docId = docid;
	  window.catalogAjax.saveHistory();
	  window.catalogAjax.fetchContent();
     

    }
	});
}
function activeMenu(selector){
   $("#menu li .active").removeClass("active");
   $(selector).addClass("active");
}

function openDialog (dialogTitle){
		 $('#popUp').dialog({ 
				modal:true,
				title:dialogTitle,
				minHeight: 660,
				minWidth: 515,
				resizable:false,
				buttons: {
					'Отправить': function() {
						parseForm();
					}
			    },
				open: function(){
				    $('#thanks').css({'display':'none'});
				    $('.checkBoxImg').css({'background-position':''});
				    $(".ui-dialog-buttonset button").button( "disable" ) ;
				    $('#QapTcha').empty().QapTcha();
				    $('#sendForm :input').not('input[name="iQapTcha"]').val('');
					$("div.ui-dialog-buttonset button").blur();
				 }

		 });

}
function setRadio(id,auto){
$("#checkBoxBlockInput :input").each(function(e){
    if(e!=id){
	   $(this).parent().css({"background-position":""});
	   $("#order"+e+"").val("");
	}else{
	   $(this).parent().css({"background-position":"96% 96%"});
	   $("#order"+e+"").val("1");
	}
  
});
}

function parseForm (){
var name = $('#sendForm input[name="username"]').val();
var mail = $('#sendForm input[name="mail"]').val();  
var tema="";
$('#sendForm input[name="tema[]"]').each(function(e){
   if($(this).val()==1) tema=1;
});
var message = $('#sendForm :input[name="message"]').val();
if(name==""){alert("Зполните поле Имя");return false;}
if(mail==""){alert("Зполните поле E-mail");return false;}
if(tema==""){alert("Выберите тему письма");return false;}
if(message==""){alert("Зполните поле Текст письма");return false;}
sendForm('sendForm');
}
function sendForm(id){
$.ajax({
    url: '/send.html',
	type: "POST",
    dataType: 'text',
	data:$('#'+id).serialize(),
    beforeSend: function(xhr){
	    popupLoad();
	  $('#teni').show();
      $('#loading').show();
    },
    success: function(data){
	    if(data=='0')alert('Что-то не так');
		if(data=='1'){
		   alert('Отправилось');
		    $('#popUp').dialog('close'); 
		   }  
	  $('#loading').hide();
	  $('#teni').hide();
	  $('.ui-dialog-buttonset').empty();
      $('#thanks').css({'display':'block'});
      setTimeout('$("#popUp").dialog("close");', 6000);	  
    }
	});
}
function slideToogleVakans(id){
  if(id==false || id=='')return false;
  var slideTitle= $('#title'+id);
  var slideText = $('#slideText'+id);
  var slideBlock = $('#slideBlock'+id);
      if(slideBlock.css('display')=='none'){
	    slideBlock.slideDown(300);
		slideText.css({'background-position':'-1px 3px'});
        slideTitle.css({'border-radius': '5px 5px 0px 0px'});		
		return false;
	  }
	  if(slideBlock.css('display')!='none'){
         	    slideBlock.slideUp(300);
		        slideText.css({'background-position':'-40px 3px'});
                slideTitle.css({'border-radius': '5px 5px 5px 5px'});				
		return false;	
	  }			
}

