/*
 *	Built for jQuery library
 *	http://jquery.com
*/

$(document).ready(function(){
	// EVENT
    	// FOOTER HEIGHT
    	$(window).resize(function(){ resizeBgFooter(); });
    	$(window).scroll(function(){ resizeBgFooter(); });
    	
    	// HOVER TITLE HOMEPAGE
    	$('#container h2 span').hover(
    		function(){
    			widthTitle = $('#container h2 span').width();
  				$('#social').css({ 'right': -widthTitle + 'px' }).stop(true, true).fadeIn(200);
    		}, function(){
    			$('#social').stop(true, true).fadeOut(500);
    		}
    	);
    	
    	
    	
     	// EFFECT ON WORK GALLERY
     	if($.browser.msie && parseInt($.browser.version, 10) == 7) {
    	} else {
			$('#content #list li').hover(function(){
    			$(this).find('span').stop().css({'top': '-220px'}).animate({'top': '0px'});
    			$(this).find('img.perso_icon').attr('src','images/perso_icon2.png');
    			$(this).find('img').not('img.perso_icon').stop().fadeTo(200, '0.5');
    		 	
    		}, function(){
    			$(this).find('span').stop().animate({'top': '440px'});
    			$(this).find('img.perso_icon').attr('src','images/perso_icon.png');
    			$(this).find('img').stop().fadeTo(200, '1');
    		});
    		
		}
	
	// INITIALISE
	$('body').removeClass('nojs');
	
	$('a._blank').each(function(e){
		$(this).attr('target','_blank').removeClass('_blank');
	});
	
	emailContent= 'julien@harkor.be';
	$('a.mail').each(function(){
		$(this).html(emailContent).attr('href','mailto:'+emailContent);
	});
	
	$('ul#sub_works_pagination li a.disabled').each(function(e){
    	$(this).find('img').css({ 'opacity':0.5 });
    });
	
		// TIPSY
    	$('a.tooltip, h3 img.perso_icon').tipsy({ live: true, gravity: 's', opacity : 1, offset: 5 });
    	$('.col_2.engage li, .col_2.processus li').tipsy({ gravity: 's', opacity : 1, html : true });
    	$('#content #list li img.tooltip, #content #list li a.tooltipSpec').tipsy({ live: true, gravity: 's', opacity : 1, offset: 10 });
    	
    	// SOCIAL MEDIA HOMEPAGE
	    var content = '';
	    content += '<ul id="social">';
	    content += $('#social').html();
	    content += '</ul>';
	    $('#intro #social').remove();
    
	  	$('#container h2 span').append(content);
     
     
	resizeBgFooter();
	setHome();
    
});

	function resizeBgFooter(){
		hNewHeight = $('#header').outerHeight();
	 	cNewHeight = $('#content').outerHeight();
     	tNewHeight = hNewHeight + cNewHeight;
     	
     	if($(window).height() - tNewHeight > 180){
     		$('#footer_container').css({ 'height': $(window).height() - tNewHeight +'px' });
     	}
	}
	
	function setHome(){
		
		element = $('#intro #container');
		containerHauteur = element.outerHeight();
		containerLargeur = element.outerWidth();
				
		element.css({
			'position':'absolute',
			'left' : '50%',
			'margin':'0',
			'margin-left' : '-'+(containerLargeur/2)+'px',
			'top' : '50%',
			'margin-top' : '-'+(containerHauteur/2)+'px'
		});
		
		$('#light').css({
			'background-position':'center 90%'
		});
	}
