$(document).ready(function(){
  
  
	
  // lavaLamp
	$('#menu .selected').addClass('selectedLava');
  $('#menu').lavaLamp({
    fx: 'easeOutBack',
    speed:500
  });
  
  // dd_belated_png
	$("#top-light ")
		.add("#top h1 a")
		.add("ul#info li")
		.add("li.backLava")
		.add(".details-outer")
		.add(".col-beta h2")
		.addClass("png_bg");
    
  
  
  $("#top h1 span").css("opacity","0");  
  $("#top h1 span").hover(function () {
    $(this).stop().animate({opacity: 1}, 250);
  }, function(){
    $(this).stop().animate({opacity: 0}, 250);
  });
  
  

  
  $("a.read-more span").hover(function(){
      $(this).addClass('hover')
    },function(){
      $(this).removeClass('hover');
  });
  
  $('.zoomoutmenu').zoomtabs(10); 
  
  // form vvalidation
	//------------------------//
		$("#cf_field_1").attr('class', '').addClass("validate[required]");
		$("#cf_field_2").attr('class', '').addClass("validate[required,custom[email]]");
		$("#cf_field_3").attr('class', '').addClass("validate[required]");
		
		/*
		$("[class^=validate]").validationEngine({
			success :  false,
			failure : function() {}
		});*/
		$("#cformsform").validationEngine({
			success :  false,
			failure : function() {}
		});	
		
		
	//=========================//
	


  $('.technologies span[title]').qtip({
    style: {
      name: 'dark',
      padding: 7,
      margin: 0,
      background: '#0b0b0b',
      color: '#737373',
      textAlign: 'center',
      fontSize: '12px',
      border: {
         width: 1,
         radius: 1,
         color: '#646464'
      }
    },
    show: { delay: 0, effect: { type: 'slide' } },
    hide: { effect: { length: 430 } },
    position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
   }
  
  });
  
  $('.panels a').fancybox({
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'overlayShow': true
	});

	$(".lady-bovary").defuscate(); ////
});


jQuery.fn.defuscate = function() {
   return this.each(function(){
		string = $(this).html().
			replace(/\s*\[.+\]\s*/, ".").
			replace(/\s*\{.+\}\s*/, ".").
			replace(/\s*\(.+\)\s*/, "@");
		$(this).before('<a href="mailto:' + string + '">' + string + "</a>").remove();
   });
}; 


$.fn.zoomtabs = function (zoomPercent, easing) {
	
        if (!zoomPercent) zoomPercent = 10;
				
        return this.each(function () {
            var $zoomtab = $(this);
            var $tabs = $zoomtab.find('.tabs');
            var height = $tabs.height();
						
						var $panels = $zoomtab.find('.panels a')
						

            
            $zoomtab.find('> div').scrollTop(0);
            
            
            function zoomImages(zoomType, speed) {
                $(images).each(function () {
                    var $image = $(this);
                    if ($image.is(':visible')) {
                        $image.stop().animate($image.data(zoomType), speed, easing);
                    } else {
                        $image.css($image.data(zoomType), speed);
                    }
                });
            }
                        
            $tabs.height(0).hide(); // have to manually set the initial state to get it animate properly.
            
            // this causes opear to render the images with zero height and width for the hidden image
            // $panels.hide().filter(':first').show();
            var speed = 200;
            
            $zoomtab.hover(function () {
                $tabs.stop().animate({ height : height }, speed, easing);
            }, function () {
                $tabs.stop().animate({ height : 0 }, speed, easing, function () {
                  $tabs.hide();
                });
            });
            
            var hoverIntent = null;
            $tabs.find('a').hover(function () {
              
              var link = $(this);
                clearTimeout(hoverIntent);
                var el = this;
                hoverIntent = setTimeout(function () {
                  $tabs.find('a').each(function(){$(this).removeClass('hover');});
                    link.addClass('hover');
										link_href = link.attr('href').substring(1,link.attr('href').length);
										
                    $panels.hide().filter(function() {
											
											panel_id = $(this).attr('id');
											//alert(link_href+" "+panel_id);
											if(link_href == panel_id ) {
													return true;
											}
											else
													return false;
										}).show();
                }, 100);
            }, function () {
              
                clearTimeout(hoverIntent);
            }).click(function () {
                return false;
            });
        });
    };