$(function(){

 function getS(){
   var ah = getPageSize();
  if(ah[0]<1200){
	$('#leftpic').hide();
	$('#rightpic').hide();
  }else{
  	$('#leftpic').show();
	$('#rightpic').show();
  }
  return false;
 }


    $('#midMenu .lis').hover(
               function(){
                  $(this).addClass('hov');
                  $(this).find('.subMenu').fadeIn(200);
               },
               function(){
                   $(this).removeClass('hov');
                   $(this).find('.subMenu').hide();
               })

getS();

$(window).resize(function(){
 getS();
});
	


$(".swpic").click(function(){
	var vs=$(this).attr("bim");
	$('body').append('<div id="popup"><div class="black"></div><div class="bx"><img src="/gallery/'+vs+'_500.jpg"></div></div>');
    var sth = getPageSize();
    //alert(sth);
    $('#popup').css("height",sth[1]+"px");
    $('.black').css("height",sth[1]+"px");
   // alert($('.black').css("height"));
//	$('body').append('<img src="/gallery/'+vs+'_500.jpg">');
//	return false;
});


$(".bx").live("click",function(){
	$(this).parent().remove();
	})

$(".internal").attr("left","0");

	$('.rightb a').click(function(){
		var x = $(this);
		var n = $(this).parent().parent().find(".internal");
		totx = $(n).css("width");
		curx = $(n).attr("left");
		
		totx = parseFloat(totx);
		curx = parseFloat(curx);
		
	//	alert(totx + curx);
	//	$(this).disable();


		
		if(totx + curx - (188*5) >10){
		curx-=188;
		$(n).attr("left",curx);
		$(n).animate( {marginLeft:"-=188px"}, 800);
		}
		return false;
	});

	$('.leftb a').click(function(){

		var n = $(this).parent().parent().find(".internal");
		
		totx = $(n).css("width");
		curx = $(n).attr("left");
		
		totx = parseFloat(totx);
		curx = parseFloat(curx);
		
		//alert(curx);
		
		if(curx <0){
		curx+=188;
		$(n).attr("left",curx);
		$(n).animate( {marginLeft:"+=188px"}, 800 );
		}
			return false;
	});



    $('#topMenu a').hover(
            function(){
               var ssrc = $(this).find('img').attr('class');
               $(this).find('img').attr('src','/img/'+ssrc+'b.png');
            },
            function(){
                var ssrc = $(this).find('img').attr('class');
                $(this).find('img').attr('src','/img/'+ssrc+'.png');
            })

    $('#midMenu a').hover(
             function(){
                var ssrc = $(this).find('img').attr('pic2');
                $(this).find('img').attr('src','/menu/'+ssrc);
             },
             function(){
                 var ssrc = $(this).find('img').attr('pic1');
                         $(this).find('img').attr('src','/menu/'+ssrc);
                })
    



    $('#sendfaq').click(function(){
            sendData();
    });

   function sendData(){
     var dof = "true";
     $('#out').empty();   
     $('input, textarea').removeClass('red_b');

        if($('#faqform input[name=name]').val()==""){
          dof = "false";
            $('input[name=name]').addClass('red_b');
        }

    
       if($('#faqform textarea[name=q]').val()==""){
          dof = "false";
           $('textarea[name=q]').addClass('red_b');
        }

         if(dof=="true"){
             $('#sendfaq').attr('disabled','disabled');
             $('#out').empty();
             $('#out').append("<img src='/img/ajax-loader.gif'><br>");
             $('#out').append("Отправка данных / Sending data");
             var str = $("#faqform").serialize();

        $.ajax({
   type: "POST",
   url: '/ajax/sendfaq.php',
   data: str,
   success: function(ex){
      $('#out').empty();
      $('#sendform').slideUp("fast");
	  $('#out').append("<h2>Спасибо, ваш отзыв отправлен</h2><i>Thank you. Your comment has been sent.</i>");
			},
   error: function(xhr){
       $('#out').empty();
       $('#out').append("Ошибка соединения / Error connection");
       $('#sendfaq').attr('disabled','');
	 	   }
         });
             }

    }

    function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
    }
// for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
    pageHeight = windowHeight;
    } else {
    pageHeight = yScroll;
    }

// for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
    pageWidth = windowWidth;
    } else {
    pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    return arrayPageSize;
    }


})




