dojo.addOnLoad( function() {
	mytimer = new dojox.timing.Timer(20000);
	mytimer.onTick = function (){
		var anim = dojo.fadeOut({
	    	node: "grandvoyage",
	    	onEnd: function(){
				dijit.byId('grandvoyage').forward();
				dojo.fadeIn({ node: "grandvoyage" }).play();
	    	}
		}).play();
	};
	mytimer.start();
	if (dojo.isIE) { 
		if (window.location.hostname=='www.locatour.fr')
			dojo.byId("scrollimg").src="/images/visuel_HP_locatour.jpg"; 
		else
			dojo.byId("scrollimg").src="/images/visuel_HP_snotour.jpg"; 
	} else {
	var img = dojo.byId("scrollimg");
	var anim  = dojox.fx.slideBy({node: img, left: -400 , top: 0, unit: "px", duration: 13000});
	var anim2 = dojox.fx.slideBy({node: img, left: 0 , top: 0, unit: "px", duration: 13000});
	dojo.connect(anim, "onEnd", function() {
		dojo.connect(anim2, "onEnd", function() {
			anim.play();
		});
		anim2.play();
	});
	anim.play();
	}
	getAllItems(16);
});

function ongletOn(id) {
	for (i=1;i<4;i++) {
		dojo.removeClass('ong_'+i,'on');
   }
	dojo.addClass("ong_"+id, "on");
}
function getAllItems(store) {
	var itemsList = "";
	var liste = dojo.byId("listeI");
	var themesStore = new dojo.data.ItemFileReadStore({url: '/index/listeproduit/IDTHEM/'+store+'/LANG/FR' });
	var listeStore = themesStore;
	pageSize = 10;
	var totalItems = 0;
	var request = null;
	var listerch = null;
	var currentStart = 0;
	var searchObj= {};
	var recherche='';
	var tri = null;
	var sel = {};
	var sort = {};
    var filteringSelect = null;
    var regionStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'CODREG', items:[]}});
    var stationStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'CODSIT', items:[]}});

    function selsai() {
		if (dojo.byId('ETE').checked && dojo.byId('HIVER').checked) sel['SAISON'] = '*';
		else if (!dojo.byId('ETE').checked && dojo.byId('HIVER').checked) sel['SAISON'] = 'H1';
		else if (dojo.byId('ETE').checked && !dojo.byId('HIVER').checked) sel['SAISON'] = 'E1';
		request.query = sel;
		request= themesStore.fetch(request);
	}

    function selreg() {
    	sel['CODREG']=dijit.byId('REG').attr('value');
    	listerch = themesStore.fetch( {query: sel, onComplete: traitementStation });
    	request = themesStore.fetch( {query: sel, onBegin : clearOldList , onComplete : gotItems, start: currentStart, count: pageSize, queryOptions: { }, sort: {} } );
	}
    function selsta() {
    	sel['CODPRO']=dijit.byId('STA').attr('value')+'*';
    	request = themesStore.fetch( {query: sel, onBegin : clearOldList , onComplete : gotItems, start: currentStart, count: pageSize, queryOptions: { }, sort: {} } );
    }
    var traitementListe = function(items, request){
    	var itemsList = new Array();
    	regionStore.newItem({CODREG: '*', LIBREG: 'Toutes les régions'});
    	stationStore.newItem({CODSIT: '*', LIBSIT: 'Toutes les stations'});
    	
    	dojo.forEach(items, function(i){
    		if (!itemsList[themesStore.getValue(i, "CODREG")]) {
    			itemsList[themesStore.getValue(i, "CODREG")]=themesStore.getValue(i, "LIBREG");
    			regionStore.newItem({CODREG: themesStore.getValue(i, "CODREG"), LIBREG: themesStore.getValue(i, "LIBREG")});
    		}
    		if (!itemsList[themesStore.getValue(i, "CODPRO").substr(0,3)]) {
    			itemsList[themesStore.getValue(i, "CODPRO").substr(0,3)]=themesStore.getValue(i, "LIBSIT");
    			stationStore.newItem({CODSIT: themesStore.getValue(i, "CODPRO").substr(0,3), LIBSIT: themesStore.getValue(i, "LIBSIT")});
    		}
    	});
    	var gotError = function(error, request){
    	  alert("Problème. " +  error);
    	};
    	dijit.byId('REG').store=regionStore;
    	dijit.byId('STA').store=stationStore;
    	dijit.byId('REG').attr('value','*');
    	dijit.byId('STA').attr('value','*');
    };
    var traitementStation = function(items, request){
    	var itemsList = new Array();
    	stationStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'CODSIT', items:[]}});
    	stationStore.newItem({CODSIT: '*', LIBSIT: 'Toutes les stations'});
    	
    	dojo.forEach(items, function(i){
    		if (!itemsList[themesStore.getValue(i, "CODPRO").substr(0,3)]) {
    			itemsList[themesStore.getValue(i, "CODPRO").substr(0,3)]=themesStore.getValue(i, "LIBSIT");
    			stationStore.newItem({CODSIT: themesStore.getValue(i, "CODPRO").substr(0,3), LIBSIT: themesStore.getValue(i, "LIBSIT")});
    		}
    	});
    	var gotError = function(error, request){
    	  alert("Problème. " +  error);
    	};
    	dijit.byId('STA').store=stationStore;
    	dijit.byId('STA').attr('value','*');
    };
	function trireg() {
		request.sort = [{attribute: 'LIBREG'}];
		request= themesStore.fetch(request);
	}
	function trista() {
		request.sort = [{attribute: 'LIBSIT'},{attribute: "PRIXPRO",descending: true}];
		request= themesStore.fetch(request);
	}
	function triprx() {
		request.sort = null;
		request= themesStore.fetch(request);
	}
	function clearOldList(size, request) {
		if (liste) {
			while (liste.firstChild) {
				liste.removeChild(liste.firstChild);
			}
		}
		totalItems = size;
	}
	function nextPage() {
		if ((currentStart + currentCount) < totalItems ) {
			request.start += currentCount;
			request = themesStore.fetch(request);
		}
	}
	function previousPage() {
		if (currentStart > 0) {
			request.start -= currentCount;
			request = themesStore.fetch(request);
		}
	}
	function itemsLoaded(items, request){
		if (items.length < pageSize){
			outOfItems = true;
		} else {
			outOfItems = false;
		}
	}
	function gotItems(items, request) {
		currentStart = request.start;
		currentCount = request.count;
		
		if (parseInt(currentStart + pageSize) >= parseInt(totalItems)) {
			dojo.style('pagesui','display','none');
		} else { 
			dojo.style('pagesui','display','');
		}
		if (parseInt(currentStart - pageSize) < 0) {
			dojo.style('pagepre','display','none');
		} else { 
			dojo.style('pagepre','display','');
		}		
		if (liste) {
			var i;
			itemsList='';
			for (i = 0; i < items.length; i++) {
				var item = items[i];
	   			if (themesStore.getValue(item,"PRIXBPRO")!='0')
					prixb = " <span class='prixbarre'>" + themesStore.getValue(item,"PRIXBPRO")+" €</span>";
				else
					prixb = '';
				if (themesStore.getValue(item,"REMISE")!='')
					promo = "	<p class='promo'>" + themesStore.getValue(item,"REMISE")+"</p>";
				else
					promo = '';
				if (themesStore.getValue(item,"SAISON")=='H1') { saison=' (Hiver) '; imgsai='<img src="/images/icone_hiver.gif" align="right">'; } else { saison=' (Eté) '; imgsai='<img src="/images/icone_ete.gif" align="right">' };
				itemsList+="<div class='item' id='close'>"+
	"	<p class='chemin'>"+
	"		<a href='/r"+themesStore.getValue(item,"CODREG")+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLREG")+"' title='"+themesStore.getValue(item,"URLREG")+"'>"+themesStore.getValue(item,"LIBREG")+"</a> " +
	" > <a href='/tld"+themesStore.getValue(item,"CODPRO").substr(0,3)+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='" +themesStore.getValue(item,"URLSIT")+ "'><span class='bold'>" +themesStore.getValue(item,"LIBSIT")+ "</span></a>" + 
	" > <a href='/h"+themesStore.getValue(item,"CODPRO")+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='" +themesStore.getValue(item,"URLRES")+ "'>" +themesStore.getValue(item,"LBLPRO")+ "</a>" +
	"	</p>" +
	"	<br clear='all' /><a href='/h"+themesStore.getValue(item,"CODPRO")+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='" +themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+ "'><img src='/photo/"+themesStore.getValue(item,"SAISON")+"/130/"+themesStore.getValue(item,"CODPRO")+"1/"+themesStore.getValue(item,"URLREG")+"_"+themesStore.getValue(item,"URLSIT")+"_"+themesStore.getValue(item, "URLRES")+".jpg' class='photo' /></a>" +
	promo +
	"	<h3>"+imgsai+"<a href='/h"+themesStore.getValue(item,"CODPRO")+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"'>"+themesStore.getValue(item,"LBLPRO")+"</a></h3>" +
	"	<p class='txt'>"+themesStore.getValue(item,"TXTPRO")+"</p>" +
	"	<p class='prix'>"+themesStore.getValue(item,"PRXDPRO")+" <span class='orange'>"+themesStore.getValue(item,"PRIXPRO")+" €</span> "+prixb+" "+themesStore.getValue(item,"PRXFPRO")+"</p>" +
	"	<p class='txt'><a href='h"+themesStore.getValue(item,"CODPRO")+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='Voir les dispos' class='voir'>Voir les dispos</a></p>" +
	"	<a href='/h"+themesStore.getValue(item,"CODPRO")+"-"+themesStore.getValue(item,"SAISON")+themesStore.getValue(item,"LANGPRO")+"-"+themesStore.getValue(item,"URLRES")+"-"+themesStore.getValue(item,"URLSIT")+"-"+themesStore.getValue(item,"URLREG")+"' title='info-réservation' class='info'><img src='/images/bt_info-reservation.gif' alt='info/réservation' class='info'/></a>" +
	"</div>";
			}
		liste.innerHTML=itemsList;
		recherche='*';
		}
	}
	listerch = themesStore.fetch( {onComplete : traitementListe } );
	request = themesStore.fetch( {query: sel, onBegin : clearOldList , onComplete : gotItems, start: currentStart, count: pageSize, queryOptions: { }, sort: tri } );
	
	dojo.byId('ETE').checked=true;
	dojo.byId('HIVER').checked=true;

	dojo.connect(dojo.byId('forward'), 'onclick', nextPage);
	dojo.connect(dojo.byId('back'), 'onclick', previousPage);
	dojo.connect(dojo.byId('trireg'), 'onclick', trireg);
	dojo.connect(dojo.byId('trista'), 'onclick', trista);
	dojo.connect(dojo.byId('triprx'), 'onclick', triprx);
	dojo.connect(dojo.byId('ETE'), 'onclick', selsai);
	dojo.connect(dojo.byId('HIVER'), 'onclick', selsai);
	dojo.connect(dijit.byId('REG'), 'onChange', selreg);
	dojo.connect(dijit.byId('STA'), 'onChange', selsta);
}