// DOCUMENT JAVASCRIPT PRINCIPAL

$(document).ready(function(){
	if(jQuery.support.opacity){
		//ACCUEIL
		$("#hunterHover, #fisherHover, #hunterSign, #fisherSign").css({"display":"inline"}).fadeOut(0);
		$("#hunterSign, #fisherSign").css("top",55);
		$("#hunterDiv").hover(
			function(){
				$("#hunter").fadeOut(250);
				$("#hunterSign").fadeIn(250).animate({top:250},{duration:250,easing:"swing",queue:false});
				$("#hunterHover").fadeIn(250);
			},
			function(){
				$("#hunter").fadeIn(250);
				$("#hunterSign").fadeOut(250).animate({top:55},{duration:250,easing:"swing",queue:false});
				$("#hunterHover").fadeOut(250);
			}
		);
		$("#fisherDiv").hover(
			function(){
				$("#fisher").fadeOut(250);
				$("#fisherSign").fadeIn(250).animate({top:250},{duration:250,easing:"swing",queue:false});
				$("#fisherHover").fadeIn(250);
			},
			function(){
				$("#fisher").fadeIn(250);
				$("#fisherSign").fadeOut(250).animate({top:55},{duration:250,easing:"swing",queue:false});
				$("#fisherHover").fadeOut(250);
			}
		);
	}else{
		$("#hunterHover, #fisherHover, #hunterSign, #fisherSign").css({"display":"inline"}).hide();
		$("#hunterDiv").hover(
			function(){
				$("#hunter").hide();
				$("#hunterSign").show();
				$("#hunterHover").show();
			},
			function(){
				$("#hunter").show();
				$("#hunterSign").hide();
				$("#hunterHover").hide();
			}
		);
		$("#fisherDiv").hover(
			function(){
				$("#fisher").hide();
				$("#fisherSign").show();
				$("#fisherHover").show();
			},
			function(){
				$("#fisher").show();
				$("#fisherSign").hide();
				$("#fisherHover").hide();
			}
		);
	}
	
	if($(".dataTables_table").length){
		if($("#outfitters").length){
			oTable = $("#outfitters").dataTable({
				//Tri initial
				"aaSorting":[[0,'asc']],
				//Auto width
				"bAutoWidth": true,
				//Columns Settings
				"aoColumns": [
							//Nom
							{"sType":"html","sWidth":"100%"},
							//Ville
							{"bVisible":false},
							//ID Territoire
							{"bVisible":false},
							//Nom Territoire
							{"bVisible":false},
							//Especes
							null
						],
				//Positionnement des éléments
				"sDom": "itp"
			});
		}
		$("#territoires").change(function(){
			if($(this).val() != ''){
				$(this).addClass('critereOn');
				oTable.fnFilter("^"+$(this).val()+"$",2,false);
			}else{
				$(this).removeClass('critereOn');
				oTable.fnFilter("",2);
			}
		});
		$('.dataTables_criteres input[type="checkbox"]').change(function(){
			if($('.dataTables_criteres input[type="checkbox"]:checked').length){
				var especes = new Array();
				$('.dataTables_criteres input[type="checkbox"]:checked').each(function(){
					especes.push($(this).val());
				});
				filter = especes.join(" ");
				oTable.fnFilter(filter);
			}else{
				oTable.fnFilter("");
			}
		});
		$("#keywords").keyup(function(){
			if($(this).val() != ''){
				$(this).addClass('critereOn');
			}else{
				$(this).removeClass('critereOn');
			}
			oTable.fnFilter($(this).val());
		});
	}

	//Sidebar tooltip
	$(".info").tooltip({
		effect: "fade",
		offset:[-20,27],
		position:'top center',
		relative:true,
		predelay: 500,
		delay: 500
	});
	
	//scrollTo
	$("#lireIntro").click(function(){
		$.scrollTo('#intro',750);
		return false;
	});
	
	//Resize lateral
	var hwindow = $(window).height();
	var hbody = $("body").height();
	if(hbody < hwindow){
		$("#contenu").css({"height":$("#contenu").height()+(hwindow-hbody)});
	}
	var hcontenu = $("#contenu").height();
	var lcontenu = $("#lateral").height();
	if(lcontenu < hcontenu){
		$("#lateral").css({"height":hcontenu});
	}
	/*var lcontenu = $("#outfitters").height();
	if(lcontenu < hcontenu){
		$("#outfitters").css({"height":hcontenu});
	}*/
	
	// CHAMP RECHERCHE GOOGLE
	$("#cse-search-box input.text").focus(function(){
		if($(this).val()=="SEARCH"){
			$(this).val("");
		}
	});
	$("#cse-search-box input.text").blur(function(){
		if($(this).val()==""){
			$(this).val("SEARCH");
		}
	});
	
	//Fancybox init
	if($("a.fancybox").length){
		$('a.fancybox').fancybox({'autoScale':false,'centerOnScroll': false,'hideOnContentClick': true,titlePosition:'inside'});
	}
	
	//External Window Click
	$("#localOutfitter").click(function(){
		window.open(this.href, "extWindow","menubar=0,scrollbars=0,toolbar=0,resizable=0,width=850,height=723");
		return false;
	});
});