function resizeFont()
{
	var minSize = 12;
	var maxSize = 14;
	
	var increment = 1;
	var currentValue = parseInt($("body").css("font-size"));
	var newValue = currentValue + increment;
	if (newValue > maxSize)
		newValue = minSize;
	
	$("body").css("font-size", newValue + "px");
	$.cookie("font_size", newValue + "px");
}

function printDiv(elementId)
{
	win = window.open(document.location.href);
	win.focus();
	//$(newWin).css("display", "none");
	//alert($("#coupon", window.opener.document).html());
	//alert($(window.opener.document).find("#coupon").html());
	win.onload = function(){
		clonedElement = $(win.document).contents().find("#"+elementId).clone();
		$(win.document).contents().find(":not(body)").css("display", "none");
		clonedElement.appendTo($(win.document).contents().find("body"));
		$(win.document).contents().find("body").css("background", "none");
		win.print();
		win.close();
	}
}

function obtenirListeTerrainParRegion(el)
{
	var region_id = el.value;
	$.ajax({
		type: "POST",
		url: "/ag_terrain/obtenirListeTerrainParRegionId/"+region_id,
		dataType: 'json',
		success: function(response){
			$("#terrain_id option:not(#terrain_id option:first-child)").remove();
			var arrObj = response;
			var options = "";
			for(var i=0; i<arrObj.length; i++)
			{
				options += '<option value="'+arrObj[i].terrain_id+'">'+arrObj[i].terrain_nom+'</option>\n';
			}
			$(options).appendTo("#terrain_id");
		}
	});
}

function vote(terrain_id)
{
	$.ajax({
		type: "POST",
		url: "/ag_vote/add/"+terrain_id+".html",
		async: false,
		success: function(response){
			if ($(response).find("code").html() == "ok")
				alert($(response).find("message").html());
			else
				alert($(response).find("message").html());
		}
	});
}

$(document).ready(function (){
	
	$.ajax({
		type: "POST",
		url: "/ag_image_fond/getImageFond",
		async: true,
		dataType: "json",
		success: function(response){
			$("#main").css("background-image", "url("+response.backgroundImage+")" );
			$("#main").css("background-color", response.backgroundColor );
		}
	});
	
	var font_size = $.cookie("font_size");
	if(font_size != null)
		$("body").css("font-size", font_size);
	
	
	if ( $.browser.msie ) {
		if ($.browser.version < 7) {
			$("#menu-nav > LI").mouseenter(function (){
				$(this).find(".submenu").show();
			});
			$("#menu-nav > LI").mouseleave(function (){
				$(this).find(".submenu").hide();
			});
			//$(".submenu > LI").css("z-index", "1");
			$(".submenu > LI").bgiframe();
		}
	}
	
	if($("#recherche input.recherche").length)
	{
		$.ajaxSetup( { type: "POST" } );
		$("#recherche input.recherche").autocomplete({
			source : "/search/ajaxSearch/fr/10",
			minLength: 3
		});
	}
	
	if($("#communique").length)
	{
		/*var keywords = $("meta[name='keywords']").attr("content");
		$.ajax({
			type: "POST",
			url: "/ag_communique/getCommunique",
			data: "keywords="+keywords,
			async: false,
			success: function(response){
				$("#liste_communique").html(response);
			}
		});*/
	}
	
	$("img.loading").ajaxStart(function(){
		$(this).css("display","block");
	});
	$("img.loading").ajaxStop(function(){
		$(this).css("display","none");
	});
	
	$("img[align='left']").css("float","left");
	$("img[align='right']").css("float","right");
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook', overlay_gallery:false, slideshow:4000, autoplay_slideshow:true});
	
});

$(window).load(function() {
	
	if ($(".album_photo li").length > 0) {
		$(".album_photo").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			speed: 1000,
			circular: false,
			visible: 4,
			scroll: 1,
			auto: null
		});
	}
	
});
