
$(document).ready(function(){
	

	
	
	// Раскрытия подпунктов меню	
	$("#menu li i").hover(
		//alert('sss');
			  function () {
			  //	alert('sss');
			  	$('.menu-active').hide();
			  	$('#menu li:hidden:not(.menu-active)').show();
			  	var id=$(this).attr('id').replace("menu", '');
			  	$('#menu-active'+id).show();
			  	$(this).parent('li').hide();
			  	
		  });
			  
			  
	// Наведение на главной на партнеров	
	$(".partners li").hover(
			  function () {
			  	$(this).find('.pt').css({"background":"url(/images/projects_bg.gif) no-repeat 100% 0px"});
			  	$(this).find('.pb').css({"background":"url(/images/projects_bg.gif) no-repeat 100% 100%"});
			  	$(this).find('.pc').css({"background":"#f7fbfd"});
			  	$(this).find('.logo-normal').hide();
			  	$(this).find('.logo-hover').show();
			  }, 
			  function () {
			  	$(this).find('.pt').css({"background":"url(/images/projects_bg.gif) no-repeat 0 0px"});
			  	$(this).find('.pb').css({"background":"url(/images/projects_bg.gif) no-repeat 0 100%"});
			  	$(this).find('.pc').css({"background":"white"});
			  	$(this).find('.logo-hover').hide();
			  	$(this).find('.logo-normal').show();
			  	
			  });
			  
	$(".partners li").click(
		function () {
			  	//location=$(this).attr('title');
			  	//$(this).target=$(this).attr('title');
			  	var newWindow = window.open($(this).attr('title'), '_blank');
			  	if (newWindow) {
					if (newWindow.focus) {
						newWindow.focus();
				}}
	
			  });	
	
	if ($("#left-bar").length)
		var menu_position=$("#left-bar").offset().top+$("#left-bar").height();
		
	// проверяем положение контакт формы, если оно ниже меню то подвинем
	if ($('.contact-wrapper').length)
		if ($(".contact-wrapper").offset().top<menu_position)	{
			$(".contact-wrapper").css({"padding-top":(menu_position-$(".contact-wrapper").offset().top)+"px"});	
		}	  		  
	 	  
	if ($('.vrezka-wraper').length) 
	if ($(".vrezka-wraper").offset().top<(menu_position+80))	{
			$(".vrezka-wraper").css({"padding-top":(menu_position-$(".vrezka-wraper").offset().top)+80+"px"});	
		}	
	
			
var allImgs = [];	
var i=0;		
$( ".logo-hover" ).each(		
	function( intIndex ){
		allImgs[i] = new Image(); 
	    allImgs[i].src =  $(this).attr('src');
	}	
);

});	

// проверка контакт формы
function check_contact_form() {
	var result=true;
	$('.c-form input, .c-form textarea').each(
		function( intIndex ){
 			if ($(this).val()=='')
 			 { 
 			 	alert($(this).attr('error'));
 			 	$(this).focus();
 				result=false;
 				return false;
 			 }	
 		});
	
	return result;
}


$(window).resize(function() {
				var arrPageSizes = __getPageSize();
				$('#black-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				
			});

/* Вы не дозвонились ? */
$.pupupimage = function(url, width, height, obj, id) {

  $("#black-overlay").click(function () {
  		  $.modalimageclose();
  });
  
  //alert($(obj).parent('div').hide()); 
  
  
  
   var Total = $(obj).parent('div').find('a').length;
   var Current = $(obj).parent('div').find('a:eq('+id+')');
   var new_w=parseInt(Current.attr('width_big'));
   var new_h=Current.attr('height_big');
   var src=Current.attr('imgbig');
   
   
   //alert(Current);
   //$( '.photos img:eq(' + id + ')' );
  
  // var new_w=parseInt(Current.attr('width_big'))+40;;
  	//	     var new_h=Current.attr('height_big');
  // alert(Total+' - '+id+' '+new_w+' '+new_h+' '+src);
   
   
   
   
   
  
  
  $("#prev_p, #next_p").unbind('click');    
  
  
  if (id==0)
  		     	{
  		     		$("#prev_p").click(function () { 
      					$.pupupimage('', '', '', obj, parseInt(Total-1));
      					return false;
    				});
  		     	}
  		     else
  		     	{
  		     		$("#prev_p").click(function () { 	
  		     			$.pupupimage('', '', '', obj, parseInt(id-1));
      					return false;
    				});
  		     	}	
  		     if (id==(Total-1))
  		     	{
  		     		$("#next_p").click(function () { 
      					$.pupupimage('', '', '', obj, parseInt(0));
      					return false;
    				});
  		     	}
  		     else
  		     	{
  		     		$("#next_p").click(function () { 	
      					$.pupupimage('', '', '', obj, parseInt(id+1));
      					return false;
    				});
  		     	}
  		    
  		     if (Total==1)
  		     	{
  		     		$("#prev_p, #next_p").hide();
  		     	}	
  
  
  
  
  
  
  
  // размер страницы,   
  var arrPageSizes = __getPageSize();       
  $('#black-overlay').css({
			backgroundColor:	"#000000",
			opacity:			0.4,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).show();
	
		
	 //$('.modal-img img').hide();
 	
	 $('.modal-img').html("<img src='"+src+"' onload='this.style.display=\"\";'/>");
	
	  
	 $('.modal-img').css({ 
	 	height : new_h+'px'});


	if ((new_w+100)>=$(window).width())
	  new_w=$(window).width()-200;
	
	if ((new_h+150)>=$(window).height())
	  new_h=$(window).height()-250;  
	  
	  	 	   
	 $('.modal-image').css({ 
	 	top: "10px",
	 	position : "fixed",
	 	width : (new_w+40)+"px",
	 	marginLeft : '-'+((new_w+50)/2)+'px'
	 }).show();	
	    
	
	 	
	 
	 //alert($('.modal-image').width());
   		 
   		  if ( ($.browser.msie && $.browser.version.substr(0,1)<7) || document.documentElement.clientHeight<$('.modal-image').width())
           { 
           		$(".modal-image").css("top",'50px');
           		//alert($('.modal-image').css('position'));
           		if (width!='' || $('.modal-image').css('position')=='fixed')
           		scroll(0, 45);
           	    $(".modal-image").css("position","absolute");	
       	   }
       	   	
  
};
$.modalimageclose = function(id) {
  		$(".modal-image").hide();
  		$('#black-overlay').hide();

  	};
  	
	
/* Вы не дозвонились ? */
$.modalshow = function() {

			 // для класса close_gallery ставим закрытие
  		     $("#black-overlay").click(function () {
  		      	$.modalclose();
  		       });
             
  		     // размер страницы, для белой хрени        
  		     var arrPageSizes = __getPageSize();       
  		       $('#black-overlay').css({
				backgroundColor:	"#000000",
				opacity:			0.4,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).show();
		 				
		$('.modal').show();
			  
         var winW = $(window).width();   
         var winH=$(window).height()/2;

        
         $(".modal").css("top",'50px');
   		 $(".modal").css("position","fixed");
   		 
   		  if ( ($.browser.msie && $.browser.version.substr(0,1)<7))
           { 
           		$(".modal").css("top",'50px');
           		scroll(0, 45);
           		$(".modal").css("position","absolute");	
       	   }
   		 	
  	};
  	
  	// закрытие галереи
  	$.modalclose = function(id) {
  		$(".modal").hide();
  		$('#black-overlay').hide();

  	};

/* Ральный размер сраницы */
function __getPageSize() {
			var xScroll, yScroll;
		  // alert(document.body.clientHeight);
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				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
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					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;
			}	
			//alert(document.body.scrollHeight);
			// 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 = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			
			if ($.browser.opera) 
				pageHeight=parseInt($("#footer-w").offset().top+157);
			if ($.browser.safari)
				{
					pageHeight=parseInt($("#footer-w").offset().top+195);
				} 
				//
			//alert('ololo');
			
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
}

