$(document).ready(function() {
	

	$('.click').click(function(){		
		
		// alert( $(this).nextAll('.source').first().attr('alt')) ;
		if( $(this).nextAll('.source').first().attr('alt') )
		{
			$(this).attr('src' , $(this).nextAll('.source').first().attr('alt')) ;
			$(this).nextAll('.source').first().removeClass('source');
			$(this).removeClass('first_hover');
			
			// $(this).next('.click').fadeIn('fast');
			// if ( $(this).hasClass('fade')) $(this).hide().fadeIn(1500);
			if ( $(this).hasClass('slide_all')) $(this).hide().slideDown('fast');
			if ( $(this).hasClass('slide_down')) $(this).hide().css('display' ,'block').css('width', '100%').css('height' ,'0px').animate({height: "430px"}, 200 );
			if ( $(this).hasClass('slide_left')) $(this).hide().css('display' ,'block').css('width', '0%').css('height' ,'430px').animate({width: "100%"}, 200 );
		}
		else 
		{
			$(this).nextAll('span').addClass('source');
			$(this).click();
			
		}
		
		// if( $(this).next('.click').attr('src') )
		// {
			// $(this).hide();
			// $(this).next('.click').fadeIn('fast');
		// }
		// else if( $(this).siblings().first().attr('src') )
		// {
			// $(this).hide();
			// $(this).siblings().first().fadeIn('fast');
			
		// }
		
		
		
	
	});
	
	//$(".first_hover").hover(
		//function(){		// alert("meuh");
			//if( $(this).hasClass('first_hover') )
			//{
				//$(this).attr('src' , $(this).nextAll('.source').first().attr('alt')) ;
				//$(this).nextAll('.source').first().removeClass('source');
			//}
		//} ,
		//function(){
			//if( $(this).hasClass('first_hover') )
			//{
				//$(this).attr('src' , $(this).nextAll('.hide').first().attr('alt')) ;
				//$(this).nextAll('.hide').addClass('source');
				//$(this).nextAll('.hide').first().removeClass('source');
				
			//}
		//}


		//);
	
	$("img").lazyload({ threshold : 100 });
	
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		var full_url = this.href;
		
		pageScroll( full_url );
		
		
	});

	
	// alert(navigator.platform);
	
	
	$(window).scroll( function(){
		var height = $(window).height();
		var scrollTop = $(window).scrollTop();
	
		// headerScroll( scrollTop );
	
	});
	
	
	
	
	function pageScroll( full_url )
	{
		var headerSize = 70;
		if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
		{
			headerSize = 0 ;
		}

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top-headerSize;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').stop().animate({scrollTop:target_top}, 500 , 'easeInOutCirc' );
		// $(window).scrollTop(target_top)
		
		
		/*
			easeInOutCirc
			easeInOutBack
			easeInOutSine
			
		
		
		*/
		// headerScroll( target_top );
	}
	
	function headerScroll( scrollTop )
	{
		
		
		
		
	}
	
	
	if(navigator.platform == 'iPad' )
	{
		 // $("#header").css("position", "absolute");
		 // $("#header").css("height", "125px");
		 // $("#header").css("top", scrollTop+"px");
		 $(".wrapper").css("padding", " 0 65px");
		 // $("#rubrique_studio").css("margin-top", "0px");
	};
	// if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	// {
		 
		 // $("#rubrique_studio").css("margin-top", "0px");
	// };

	
	$("#menu > ul > li").hover(function(){			// alert("meuh");
			// $(this).children('.submenu').show();
			// $('.submenu').stop().slideUp();
			$(this).children('.submenu').stop(true,true).slideDown(500);
		}
	,	function(){
			// alert("meuh");			
			// $(this).children('.submenu').slideUp();
			$(this).children('.submenu').stop(true,true).slideUp(500);
		}
	);
	
	
	var full_url = document.location.hash;
	pageScroll( full_url );
	
	
});



