
var long = 0;
var latt = 0;

$(function(){
	//load_datas("#boutonCinema");
	
	$(document).ready(function() {
		$.getScript('http://j.maxmind.com/app/geoip.js', function() {
			long = geoip_longitude();
			latt = geoip_latitude();
			$.cookie("px_location", latt+","+long, { expires: Math.pow(2, 15), path: '/' });
		});
		
	});
	
	$('.changeOnClick').click(function(){
		var elem = this;
		if (!$(elem).hasClass('active')){
			$('.changeOnClick').removeClass('active');
			$(elem).addClass('active');
			$("#contenu-img").attr('src',"images/contenu-img-"+$(elem).attr('rel')+".png");
			load_datas(elem)
		}
		return false;
	});
	
	$('#formLogin').submit(function(){
		$("#errorLogin").hide().html("Les identifiants sont incorrects").fadeIn("slow");;
		
		return false;
	});
	
	$('.autofillin').each(function(){
		$(this).val($(this).attr("alt"));
		$(this).focus(function(){
			if ($(this).val() == $(this).attr("alt")){
				$(this).val('');
			}
		});
		$(this).blur(function(){
			if ($(this).val() == ''){
				$(this).val($(this).attr("alt"));
			}
		});
	});
		
});

//function setPositionOnLink(position){
//	if (long != 0){
//		$('a.webview').each(function(){
//			$(this).attr("href",$(this).attr("href")+"?location="+latt+","+long);
//		});
//	}
//}

function load_datas(elem){
	var loading = '<div class="loading"><img src="/images/loading.gif" alt="loading" /><p>Chargement en cours</p></div>';
	$('#dernieres-sorties2').html(loading);
	$.ajax({
		type: "GET",
		url: 'ajax/switchCategory.php',
	 	data: {'type':$(elem).attr('rel')},
		success: function(msg){
	 		$('#dernieres-sorties2').html(msg);
	 	},
	 	error: function(xhr, ajaxOptions, thrownError){
	 	}
	});
}
