 jQuery(document).ready(function($){
   
   function randomBetween(a,b){
			rndNumber=a+Math.floor(Math.random()*(b-a+1));
			return rndNumber;
		}
		
	function getRandomColor(){
	var backgrounds=["#CECECE","#f8f8f8","#f3f3f3","#e8e8e8","#dadada"];
        var n=randomBetween(0,4);
	return backgrounds[n];
	}
		
	function setRandomBackgroundColor(){
   	$("div.galleria > ul > li").each(function (i) {
       var color= getRandomColor();

           $(this).css("background-color",  color);
       $(this).find("div.item").css("border-color",color);
      
      });
    
	}
		
	function getNextLi(current, n){
    var i=0;
    var next=current.nextSibling;
    
    while(i<n && next!=null)
    {
    if(next.nodeName=="LI")i++;
    if (i<n)next=next.nextSibling;
    }
    return next;
    }

	function getPrevLi(current, n){
    var i=0;
    var prev=current.previousSibling;
    
    while(i<n && prev!=null)
    {
    if(prev.nodeName=="LI")i++;
     if (i<n)prev=prev.previousSibling;
    }

    return prev;
    }
            	
	function hoverGallery(){
	$("div.galleria > ul > li").hover(
      function () {
        $(this).css("background-color","#fff");


     /*   this.style.backgroundColor = "#838383";
        var color2= "#afafaf";
        var color3= "#c7c7c7";
        var locations=[2,4,2,4];
      if (getNextLi(this,locations[0])!=null)getNextLi(this,locations[0]).style.backgroundColor = color2;
         if (getNextLi(this,locations[1])!=null)  getNextLi(this,locations[1]).style.backgroundColor = color3;
         if (getNextLi(this,locations[2])!=null)  getNextLi(this,locations[2]).style.backgroundColor = color2;
         if (getNextLi(this,locations[3])!=null)  getNextLi(this,locations[3]).style.backgroundColor = color3;
         if (getPrevLi(this,locations[0])!=null) getPrevLi(this,locations[0]).style.backgroundColor = color2;
         if (getPrevLi(this,locations[1])!=null) getPrevLi(this,locations[1]).style.backgroundColor = color3;
         if (getPrevLi(this,locations[2])!=null)  getPrevLi(this,locations[2]).style.backgroundColor = color2;
         if (getPrevLi(this,locations[3])!=null)  getPrevLi(this,locations[3]).style.backgroundColor = color3;

       */
      }, 
      function () {
        var color= getRandomColor();

        $(this).css("background-color",  color);
      //    $(this).find("div.item").css("background-color",color);

        
 /*       var locations=[2,4,2,4];

        this.style.backgroundColor = getRandomColor();
         if (getNextLi(this,locations[0])!=null) getNextLi(this,locations[0]).style.backgroundColor = getRandomColor();
         if (getNextLi(this,locations[1])!=null)getNextLi(this,locations[1]).style.backgroundColor = getRandomColor();
          if (getNextLi(this,locations[2])!=null)getNextLi(this,locations[2]).style.backgroundColor = getRandomColor();
           if (getNextLi(this,locations[3])!=null)  getNextLi(this,locations[3]).style.backgroundColor = getRandomColor();
         if (getPrevLi(this,locations[0])!=null)   getPrevLi(this,locations[0]).style.backgroundColor = getRandomColor();
        if (getPrevLi(this,locations[1])!=null) getPrevLi(this,locations[1]).style.backgroundColor = getRandomColor();
         if (getPrevLi(this,locations[2])!=null)  getPrevLi(this,locations[2]).style.backgroundColor = getRandomColor();
            if (getPrevLi(this,locations[3])!=null)  getPrevLi(this,locations[3]).style.backgroundColor = getRandomColor();

 
*/

      }
    );


	}
	
	
    
      //jQuery.noConflict();
     setRandomBackgroundColor();
     hoverGallery();
     
     
      
    });
     

