(function($){
	$.fn.simpleButton = function(){
		this.mousedown(function(){
			$(this).addClass('m-down');
		}).mouseup(function(){
			$(this).removeClass('m-down');
		}).mouseleave(function(){
			$(this).removeClass('m-down');
		});
	};
})(jQuery);

  var iy = '';
  var className;


$(function(){
	$('.s-button').simpleButton();
	
	$("a[rel=gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Картинка ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	$("a[rel=cadr-gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'showNavArrows'   : false
	});
	
	
	  $('#show-present').click(function(event){
	     event.preventDefault();
       $('#presentation').show();
	  });
	  
	  
	$('#fcancel').click(function(event){
		event.preventDefault();
		$('#presentation').hide();
		if(resetForm){
			resetForm($('#presentation form'));
		}
	});  
	$('#ffcancel').click(function(event){
		event.preventDefault();
		$('#presentation').hide();
		if(resetForm){
			resetForm($('#presentation form'));
		}
	}); 
	
    $('#fsend').click(function(event){
      event.preventDefault();
      $("form:first").submit();
	  }); 	
	
	  $(".fast-navigation li").mouseover(function(){
     $(this).addClass('active');
     $("#note-0").hide();
     $(".spnotes").hide();
     var enter_value = $(this).attr('id').split('-');
     var _bl = enter_value[1];
     $("#note-" + _bl).show();
     $(".shead").addClass($(this).attr('id'));
     
    }).mouseout(function(){
      $(this).removeClass('active');
      $("#note-0").show();
      $(".spnotes").hide();
      $(".shead").removeClass($(this).attr('id'));
    }).click(function(){
      document.location.href=$(this).find('a').attr('href');
    });

	
	
  $(".wblock ul li a").append('<i class="iWl"></i><i class="iWr"></i><i class="iWc"></i>');
  $(".wblock ul li").mouseover(function(){
      $(this).addClass('activeX');
  }).mouseout(function(){
      $(this).removeClass('activeX');
  });
  $(".v-block").append('<span class="is_block"></span>');



  var superArray = []
  for (i=0; i <= 70; i++)
  {
    superArray[i] = [Math.floor(Math.random()*4),Math.floor(Math.random()*4),2,2,2]
  }

  cub(superArray);
  $(".fast-navigation li").prepend('<i class="cubes" id="c-fast">' + iy + '</i>');

  var superArray2 = []
  for (i=0; i <= 120; i++)
  {
    superArray2[i] = [Math.floor(Math.random()*2),Math.floor(Math.random()*2), 4,4,4]
  }
  cub(superArray2);
  
  /*$(".inn-header").append('<i class="cubes" id="c-header">' + iy + '</i>');  */
  /*var cubes = $(".cubes .cp i");
  jQuery.each(cubes, function() {
  $(this).delay(Math.floor(Math.random()*2000)).animate({ 
          opacity: 1
        }, 1000 );
  }); */
  
                                             
});

function cub(superArray, obj) {
  iy = '';
  jQuery.each(superArray, function() {
        var ix = '';
        
        jQuery.each(this, function() {
        
        switch (parseInt(this)) {
          case 1:
            className = 'wq'; 
            break;
          case 2:
            className = 'rq';
            break;
          case 3:
            className = 'bq'; 
            break;
          case 4:
            className = 'wq'; 
            break;
          case 5:
            className = 'wq'; 
            break;
          default:
            className = 'tq';  
        }
          ix +=  '<i class="'+ className +'"></i>';
        });
        iy += '<i class="cp">' + ix  + '</i>';
  });
}

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 150;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});

