/******************************************
* Javascript by Alexis Creuzot - All right reserved
* 2011
*
* displaySite(int,int)
* createTabs(void)	
* generateNoise(float)
******************************************/

$(document).ready(function() {
	createTabs();
  scrollToTop();
	displaySite();
});

/**
* Display site
*/
function displaySite(){
	$('#page').fadeIn(1000,function(){
  		$("#tabs").fadeIn(800);
  		$("#footer").fadeIn(800);
  	});
}

/**
* Create tabs 
*/
function createTabs(){
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.idTabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.idTabs li").click(function() {
		if(! $(this).hasClass("active")){
			$("ul.idTabs li").removeClass("active");
			$(this).addClass("active");
			$(".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active content
		}
		return false;
	});
}


function scrollToTop(){

  $().UItoTop({ 
    min: 500,
    scrollSpeed: 1200,
    easingType: 'easeInOutQuart' 
  });

}

/**
* Generate noise 
*/
function generateNoise(opacity) {
   if ( !!!document.createElement('canvas').getContext ) {
      return false;
   }
 
   var canvas = document.createElement("canvas"),
   ctx = canvas.getContext('2d'),
   x, y,r;
   canvas.width = 100;
   canvas.height = 100;
   ctx = canvas.getContext("2d");
 
   for ( x = 0; x < canvas.width; x++ ) {
      for ( y = 0; y < canvas.height; y++ ) {
        r = Math.floor( Math.random() * 80 );
        ctx.fillStyle = "rgba(" + r + "," + r + "," + r + "," + opacity + ")";
        ctx.fillRect(x, y, 1, 1);
      }
   }
   document.body.style.backgroundImage = "url(" + canvas.toDataURL("image/png") + ")";
}
