﻿//# Управляет скролингом новостей на главной странице #


OtherPhotoGallery = function() {
  this.init();
};

OtherPhotoGallery.prototype = {

  init: function() {
    var t = this;
    t.point = 0;
	t.index = $(".Galery div.PhotoBlock").length;
	
	//ширина фотографии 
	widthDiv = $(".Galery div.PhotoBlock").css("width").replace(/px/,"");
	widthDivIndex = parseInt(widthDiv, 10) + 2;
	
	//ширина блока с фотографиями
	widthCont = $(".GaleryPos").css("width").replace(/px/,"");
	widthContIndex = parseInt(widthCont, 10);
	
	//количество видимых фотографий
	numberMove = Math.round(widthContIndex/widthDivIndex);
	
	  $(".ToRightGalery").click(function() {
      t.galleryNextToRightClick();
    });

	  $(".ToLeftGalery").click(function() {
      t.galleryPrevToLeftClick();
    });
	  
	 $(".GaleryPos .ToRightGalery").mouseover(function() {
      t.galleryMouseOverRG();
    });
	 
	 $(".GaleryPos .ToRightGalery").mouseout(function() {
      t.galleryMouseOutRG();
    }); 
	 
	$(".GaleryPos .ToLeftGalery").mouseover(function() {
      t.galleryMouseOverRL();
    });  
	
	$(".GaleryPos .ToLeftGalery").mouseout(function() {
      t.galleryMouseOutRL();
    });  
	 
		
  },

  galleryPrevToLeftClick: function() {
    var t = this;
    if (t.point <= 0) {
      return;
    }
    t.point--;
	
	if (t.point <= 0) {
			$(".ToLeftGalery img").addClass("DisplayNone");
			$(".ToLeftGalery img.GrayArrowGL").removeClass("DisplayNone");  
	  	}
	
	$(".ToRightGalery img").addClass("DisplayNone");
	$(".ToRightGalery img.BlackArrowGR").removeClass("DisplayNone");
	$("#Slide").animate({left: "+=" + widthDivIndex +"px"}, 500);
	

  },

  galleryNextToRightClick: function() {
    var t = this;
	
	  if (t.point >= t.index-numberMove) {
		return;
	  }		
	  
		t.point++;
		
		if (t.point >= t.index-numberMove) {
			$(".ToRightGalery img").addClass("DisplayNone");
			$(".ToRightGalery img.GrayArrowGR").removeClass("DisplayNone");  
	  	}	
		
	    $(".ToLeftGalery img").addClass("DisplayNone");
		$(".ToLeftGalery img.BlackArrowGL").removeClass("DisplayNone");
		$("#Slide").animate({left: "-=" + widthDivIndex +"px"}, 500);
  },
  
  galleryMouseOverRG: function() {
	var t = this;  
	if (t.point >= t.index-numberMove) {
		return;
	  }	  
	$(".ToRightGalery img").addClass("DisplayNone");
	$(".ToRightGalery img.RedArrowGR").removeClass("DisplayNone");

  },
  
  galleryMouseOutRG: function() {
	var t = this;
	if (t.point >= t.index-numberMove) {
		return;
	  }
	$(".ToRightGalery img").addClass("DisplayNone");
	$(".ToRightGalery img.BlackArrowGR").removeClass("DisplayNone");

  },
  
  galleryMouseOverRL: function() {
	  var t = this;
	  
	  if (t.point <= 0) {
      return;
    }
	 
	$(".ToLeftGalery img").addClass("DisplayNone");
	$(".ToLeftGalery img.RedArrowGL").removeClass("DisplayNone");

  },
  
  galleryMouseOutRL: function() {
	 var t = this;	
	 
	 if (t.point <= 0) {
      return;
    }	
	
	$(".ToLeftGalery img").addClass("DisplayNone");
	$(".ToLeftGalery img.BlackArrowGL").removeClass("DisplayNone");

  }
  
  
};


$(document).ready(function(){
  new OtherPhotoGallery();  

});
