// JavaScript Document

$(document).ready(function(){
	$("#skip_nav a").bind("focus", function(){
		$(this).parents("#skip_nav").css({'left':'50px', 'top':'28px'});
		//DOCF.keybord = true;
    });
	
	$(".sort .submit").hide();
	$(".sort select, .sort input").bind("change", function(){
		$(this).parents(".sort").submit();
	});
	//$('#mainnav').data('color', $('#mainnav').css("background-color"));
	
	//preloads images
	$(".thumbnails li").each(function(){
		var image = new Image();
		image.src = $(this).find("a").attr("rel");
	})
	$(".thumbnails li").click(function(){
		$(this).addClass("on");
		$(this).siblings().removeClass("on");
		var url = $(this).find("a").attr("rel");
		var legend = $(this).find("a img").attr("alt");
		var cut_legend = legend.split("/");
		if(url == "") return false;
		var motif = 'vimeo';
		$(".image").empty();
		$(".legend").empty();
		var new_legend = cut_legend[0];
		if(cut_legend.length>1) new_legend += '<span class="credit">'+cut_legend[1]+'</span>&nbsp;';
		$(".legend").html(new_legend);
		if(url.match(motif)){		
			$(".image").html('<iframe width="550" height="367" frameborder="0" src="'+url+'"></iframe><span class="pattern">&nbsp;</span>');
		}else{
			$(".image").html('<img src="'+$(this).find("a").attr("rel")+'" height="367" alt="" />');
		}	
		return false;
	});
	var speed = 3000 + Math.round(Math.random()*8000);
	
	
	function opacityDown (){
		$("#player .zone").animate({opacity: 0.2}, speed, 'linear', opacityUp );
	}
	function opacityUp (){
		$("#player .zone").animate({opacity: 1}, speed, 'linear', opacityDown);
	}
	opacityDown();
	$("#player .zone ").hover(
		function(){
			//console.log("over .zone");
			
			$(this).parent().find(".tracks").css({display: 'block', opacity : 0});
			
			$(this).parent().find(".tracks").animate({opacity: 1}, 1000, 'linear');
			return false;
		},
		function(){ //console.log("out .zone (vide)");
		}
	)
	$("#player").hover(
		function(){
			//
			//console.log("over #player (vide)");
		},
		function(){
			//console.log("out #player");
			$(this).parent().find(".tracks").animate({opacity: 0.1}, 1000, 'linear', function(){ $("#player .tracks").css({'display':'none'})});
			return false;
		}
	)
	$("#player .zone ").click(function(){
		$("#flash").empty();
	})
	
	$("#player .tracks li").click(function(){
		if($(this).hasClass("on")){
			$(this).removeClass("on");
			$("#flash").empty();
		}else{
		
			$(this).siblings().removeClass("on");
			$(this).addClass("on");
			$("#flash").empty();
			var rel = $(this).find("a").attr("rel");
			$('#flash').flash({
				src: 'images/player.swf',
				width: 1,
				height: 1,
				flashvars:{url_son:rel},
			})
		}
		return false;
	})
	$(".thumb_video").css({opacity: 0.5});
	$(".thumbnails li").hover(
		function(){
			$(this).find(".thumb_video").css({opacity: 0.8});
		},
		function(){
			$(this).find(".thumb_video").css({opacity: 0.5});
		}
	)
})

