/*
    $Id: frontend_programme.js 1722 2009-12-21 10:22:50Z vpicot $
*/
dojo.require("dojo.NodeList-fx");

var pages = new Object();

var currentPage = '';

/**
 Initialisation de la page
 */
var init = function()
{
	if (currentPage == '')
	{
		if (document.location.href.lastIndexOf("/page/") != -1)
		{
			currentPage = document.location.href.substring(document.location.href.lastIndexOf("/page/") +6 );
		}
		else if (document.location.href.lastIndexOf("&page=") != -1)
		{
			currentPage = document.location.href.substring(document.location.href.lastIndexOf("&page=") +6 );
		}
		else
		{
			currentPage = 'residence';
		}
	}
	
		// Redirection des liens des miniatures pour affichage du grand format
		dojo.query('.vign').query('a').connect('onclick', function(e) {
		// désactive l'action par défaut
		e.preventDefault();
		// récuperation du nom de l'image
		target = e.target.src.substring(e.target.src.lastIndexOf("/") +1 );

		// mise à jour de l'adresse de la grande image
		image = dojo.query('.programme_image img')[0];
		image.src = image.src.substring(0, image.src.lastIndexOf("/") + 1) + target;

		// Traitement des grandes images pour faire le zoom 
		var aImages	= document.getElementsByTagName('img');

		for (i in aImages)
		{
			if (aImages[i].className == "image_to_up grande_image")
			{
				aImages[i].onclick = function () {
					window.open(this.src, 'image', config='height=500, width=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
				};
			}
		}	
	 });
	
	// A l'initialisation on récupère l'image à afficher en grand du nouvel onglet
	image = dojo.query('.programme_image img')[0];
	image_new = dojo.query('#' + currentPage + 'Vign0')[0];
	
	if (image_new == null)
	{
		// Récupère l'image à afficher en grand du nouvel onglet
		image_new = dojo.query('#residenceVign0')[0];
	}
	if (image_new != undefined)
	{
		source_new = image_new.src.substring(image_new.src.lastIndexOf("/") + 1, image_new.src.length);
		// Affiche l'image en grand du nouvel onglet
		image.src = image.src.substring(0, image.src.lastIndexOf("/") + 1) + source_new;
	}
	
	// A l'initialisation on rend zoomable la première image
	// Traitement des grandes images pour faire le zoom 
	imageZoom = dojo.query('.programme_image img')[0];
	imageZoom.className = '';
	imageZoom.onclick = function (e) {
		target = this.src.substring(this.src.lastIndexOf("/") + 1);
		imagesrc = this.src.substring(0, (this.src.substring(0, this.src.lastIndexOf("/"))).lastIndexOf("/") + 1);
		imageSrcZoom = document.getElementById('hidPopUp').value + fct_urlEncode(fct_urlEncode(imagesrc + 'images_700_500/' + target));
        window.open(imageSrcZoom, 'image', config='height=500, width=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
	};
};

function fct_urlEncode(text)
{
	var txt = text;
	txt = escape(txt);
	
	txt = txt.replace(/[/]/g,"%2F");
	txt = txt.replace(/[+]/g,"%2B");
	txt = txt.replace(/[ ]/g,"+");
	return txt;
}

dojo.addOnLoad(init);