//	function getPageScroll() {
//		var xScroll, yScroll;
//		if (self.pageYOffset) {
//			yScroll = self.pageYOffset;
//			xScroll = self.pageXOffset;
//		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
//			yScroll = document.documentElement.scrollTop;
//			xScroll = document.documentElement.scrollLeft;
//		} else if (document.body) {// all other Explorers
//			yScroll = document.body.scrollTop;
//			xScroll = document.body.scrollLeft;
//		}
//		return new Array(xScroll,yScroll)
//	}
//
//	function getPageHeight() {
//		var windowHeight
//		if (self.innerHeight) {	// all except Explorer
//			windowHeight = self.innerHeight;
//		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
//			windowHeight = document.documentElement.clientHeight;
//		} else if (document.body) { // other Explorers
//			windowHeight = document.body.clientHeight;
//		}
//		return windowHeight
//	}

$(function(){
	var currentUrl=document.location.href;

	$('.openpopup').click(function(){
		var link = $(this).attr('href');

		if($('#diaporama_contenu').length>0) {
			$('#diaporama_contenu').mouseover();
		}

		speed = Math.max($('html').scrollTop(), $('body').scrollTop());

		$('.popup_content').load(link, {ajax : true}, function(){
			if($("#prov_url").length>0) $("#prov_url").val(currentUrl);

			_gaq.push(['_setAccount', 'UA-1062333-26']);
			_gaq.push(["_trackPageview", "/"+link ]);

			$('input.autocomp').each(function(){
				var table = $(this).attr('name');
				$(this).autocomplete({
					source : "demande-devis/autocomp.html?input="+table
				});
			});
			
			$('.popup').fadeIn('fast', function(){
				if(speed>0) $('html, body').animate({scrollTop : 0}, speed, 'swing');
				initPopupSlider();
			});
		});
		
		return false;
	});
	
	$('.closepopup').click(function(){
		$('.popup').fadeOut('fast', function(){
			$('.popup_content').html('');
			if($('#diaporama_contenu').length>0) $('#diaporama_contenu').mouseout();
		});

		return false;
	});

	//fermeture de la popup avec la touche 'escape'
	var keypressaction = function(event){
		if(event.keyCode == 27 && $('.closepopup:visible').length>0)
			$('.closepopup').click();
	}
	$(document).bind('keypress', keypressaction);
});
