$(function(){

   $(".frame").each(function(index){
     // $(this).css('background','#'+rgb2hex((index*64),0,0)); 
   });
   
   $(".frame").each(function(i){
       $(this).mouseover(function(){
          //$(".frame").css('z-index',1);
          $(".frame").each(function(j){
              z = 1;
              if(i+j==3) z = 4;
              $(this).css('z-index',z);
          });
          $(this).css('z-index',5);
       });
   });

$(".frame").hover(function(){
       $(this).children(".innerCover").fadeIn('slow');
   },function(){
       $(this).children(".innerCover").fadeOut('slow');
   });
});


function rgb2hex(r,g,b) {
		var hexVal = function(n) {
			var data = "0123456789ABCDEF";
			if (n==null) return "00";
			n=parseInt(n); 
			if (n==0 || isNaN(n)) return "00";
			n=Math.round(Math.min(Math.max(0,n),255));
			return data.charAt((n-n%16)/16) + data.charAt(n%16);
		}
		return hexVal(r)+hexVal(g)+hexVal(b);
	}
