var $globals = new Array();
/*Event.observe(window, 'load', function(){
	initPage();	
});*/

$(document).ready(function() {
    alert('page loadée');
});

function initPage()
{
	alert();
	
}

function lazyLoad()
{
    alert('lazyload');
	$("img").each(function(el) {
        alert (el.readAttribute('lazysrc'));
        alert (el.readAttribute('loaded'));
		if (el.readAttribute('lazysrc') && !el.readAttribute('loaded')) {

			var position = Position.page(el);
			var viewportHeight = document.viewport.getHeight();
			
			if (position[1] < viewportHeight) {

				var img = new Image();
				img.src = el.readAttribute('lazysrc');
	
				if (img.complete) {
					el.hide();
					el.src = img.src;
					el.writeAttribute('loaded', 1);
					if ($globals['is_mobile'])
						el.show();
					else
						Effect.Appear(el, { duration: 0.25 } );
				} else {
					img.onload = function() {
						el.hide();
						el.src = img.src;
						el.writeAttribute('loaded', 1);
						if ($globals['is_mobile'])
							el.show();
						else
							Effect.Appear(el, { duration: 0.25 } );
					};
				}
			}
		}
	});	
	
    $(window).scroll( lazyLoad() );
	//$(window).scroll(window, 'scroll', lazyLoad, false);	
}

/*function initForms()
{
	$$('input[type="text"],input[type="password"], textarea').each( function(el) {
		if (el.alt) {
			Event.stopObserving(el);
			Event.observe(el, 'focus', fieldChange);
			Event.observe(el, 'blur', fieldChange);
			if (el.value != el.alt)
				fieldInit(el);
		}
	} );
	$$('form').each( function(form) {
		Event.observe(form, 'submit', function(event) {
			form.select('input[type="text"],input[type="password"], textarea').each( function(el) {
				if (el.alt) {
					if (el.value == el.alt)
						el.value = "";
				}
			} );
			//startWait();
		} );
	} );
	$$('.recept').each( function(el) {
		var radio = el.select('input')[0];
		if (radio)
			Event.observe(radio, 'click', radioBoxChange);
	} );
}

function radioBoxChange(event)
{
	$$('input[name=' + this.name + ']').each( function(el) {
		var o = el.up().up();
		o.removeClassName('r-select');		
		if (el.checked)
			o.addClassName('r-select');
	} );
}

function initLinks()
{
	$$('a[login="1"],img[login="1"]').each( function(el) {
		Event.stopObserving(el, 'click', loginLink);
		Event.observe(el, 'click', loginLink);
	} );
	$$('a[confirm="1"],img[confirm="1"]').each( function(el) {
		Event.stopObserving(el, 'click', confirmLink);
		Event.observe(el, 'click', confirmLink);
	} );
}

function displayLogin(return_url)
{
	document.location = $globals['url_login'] + (return_url ? "?return_url=" + encodeURIComponent(return_url) : '');
	*//*$globals['popup-login'] = new Display.Popup( {
		mode: 'div',
		url: $globals['url_ajax_login'] + (return_url ? "?return_url=" + encodeURIComponent(return_url) : ''),
		divId: 'div-popup',
		classDiv: 'popcontent',
		loadingHTML: $globals['lang_loading'],
		onFinish: initPage
	} );*//*
}

function loginLink(event)
{
	if (!$globals['is_logged']) {
		Event.stop(event);
		var url = this.href;
		if (url.indexOf('javascript:') != -1)
			url = "";
			
		displayLogin(url);
	}
}
function confirmLink(event)
{
	Event.stop(event);
	var url = this.href;
	if (url.indexOf('javascript:') == -1 && confirm(this.readAttribute('confirm_text')))
		document.location = url;
}
function submitLogin()
{
	var form = $('form-login');
	form.request( {
		onComplete: function(transport) {
			//alert(transport.responseText);
			var data = transport.responseText.evalJSON();
			Effect.Fade(form, {to: 0.5, duration: 0.25} );

			if (data.result == "1") {
				if (data.return_url)
					document.location = data.return_url;
				else			
					document.location.reload();
			} else {
				initForms();
				Effect.Appear(form, {from: 0.5, duration: 0.25} );
				new Display.Popup( {
					mode: 'div',
					divId: 'div-msg',
					haveCache: false,
					autoClose: true,
					contentHTML: $globals['lang_error_login'],
					classDiv: 'div-msg'
				} );
			}
		}
	});
	return false;
}

function lastOrder()
{
	$globals['popup-last-order'] = new Display.Popup( {
		mode: 'div',
		url: $globals['url_ajax_last_order'],
		divId: 'div-popup',
		classDiv: 'popcontent',
		loadingHTML: $globals['lang_loading'],
		onFinish: initPage
	} );
}
*/
/**
 * Declenchements lors d'actions qui demande du temps
 */
/* var w = null;
function startWait()
{
	w = new Display.Popup( { mode: "div", loadingHTML: "", contentHTML: "Veuillez patienter ..." } );
} // fin de startWait

function stopWait()
{
	w.close();
} // fin de stopWait

function fieldChange(event)
{
	fieldInit(this);
}
function fieldInit(el)
{
	if (el.value == el.alt) {
		el.value = "";
	} else if (el.value == "") {
		el.value = el.alt;
	}
}*/
