//var strTitreDocument = 'Tourisme Suroît';
//document.title = strTitreDocument;
var strMessageMacOff = 'La carte interactive n\'est pas fonctionnelle dans Macintosh. Nous corrigerons sous peu.';

// Function pour la galerie (117/default.asp)
function AfficherTexteDescriptif(sTexteIn) {
	document.getElementById("descriptionimage").innerHTML = sTexteIn;
}

function ViewImage(sImagePathFile, sImageTitre, sImageDescription) {
	document.remplacement_photo.src= sImagePathFile;  // afficher l'image de la photo
	document.remplacement_photo.title= sImageTitre;   // afficher le titre en infobulle sur la photo
	AfficherTexteDescriptif(sImageDescription);       // afficher le texte descriptif de la photo
}
/*Fin Function pour la galerie*/

/*--------- SetFill ---------*/
function SetFill(NoSuivi, iLongueur, sCharFill) {
	// Parametre: NoSuivi: le no à afficher
	//			  iLongueur: la longeur SetFill
	//			  sCharFill: le caractere setting
	var intLongNoSuivi = 0;
	var i = 0;
	var str = '';

	sNoSuivi = new String(NoSuivi);
	intLongNoSuivi = sNoSuivi.length;
	do {
	  sNoSuivi = sCharFill + sNoSuivi;
	  intLongNoSuivi = intLongNoSuivi + 1;
	} while (intLongNoSuivi < iLongueur)
	
	return sNoSuivi;
}

function openWindow(url, w, h, iLeft, iTop, bScroll) {
	if (w==0) {
		var w=screen.width;
	}
	if (h==0) {
		var h=screen.height;
	}
    var options = "width=" + w + ",height=" + h + ",left=" + iLeft + ", top=" + iTop;
    options += "resizable=no,scrollbars=" + bScroll + ",status=no,";
    options += "menubar=no,toolbar=no,location=no,directories=no";
    var newWin = window.open(url, 'newWin', options);
    newWin.focus();
}

// rediriger le guide en ligne et verifier si c est un mac, car la carte ne fonctionne pas sous mac.
function openGuideEnLigne(sUrl){
	// convert all characters to lowercase to simplify testing
	var V=navigator.appVersion
	if (V.indexOf("Mac",0)>0) {
		is_mac = true;
	} else {
		is_mac = false;
	}

	// vérifier si c'est un MAC, car l'affiche des points sous la carte ne fonctionne pas.
	if (is_mac ) {
		alert(strMessageMacOff);
	} else {
		window.document.location = sUrl;
	}
}
/*function GuideEnLigneOpenFiche(iIDSousCategorie, iIDMembre) {
	modalWin('viewfichemembre.asp?idcm=' + iIDSousCategorie + '&id=' + iIDMembre, screen.width, screen.height);
}

function modalWin(sUrlModalWin, iWidthModalWin, iHeightModalWin) {
	if (window.showModalDialog) {
		window.showModalDialog(sUrlModalWin,"name", "dialogWidth:" + iHeightModalWin + "px;dialogHeight:" + iWidthModalWin + "px");
	} else {
		window.open(sUrlModalWin,'name','height=' + iHeightModalWin + ',width=' + iWidthModalWin + ',toolbar=no,directories=no,status=no, continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
} 

// Permet de centraliser l'ouverture des fiches dans le guide en ligne - nous avons normalisé les fiches au niveau des pictogrammes 
function GuideEnLigne(iIDSousCategorie, iIDMembre) {
	if ((iIDSousCategorie > 0) && (iIDMembre > 0)) {
//		alert('iIDSousCategorie : ' + iIDSousCategorie + '\niIDMembre : ' + iIDMembre);
		var sUrlReferenceGuideEnLigne = 'http://www.tourisme-suroit.qc.ca/guide_en_ligne/default.asp?idcm=' + iIDSousCategorie + '&id=' + iIDMembre;
		openFiche3(sUrlReferenceGuideEnLigne);
	}
}
//Ouverture des fiches des membres à partir du site www.tourisme-suroit.qc.ca
function openFiche3(sUrl) {
	if (document.location.href.indexOf('balades.ca') != -1) {
		sUrl += '&targetblank=true';
	}
	var intLargeurEcran = 800;
	var intHauteurEcran = screen.height - 75;
	winpopup =	window.open(sUrl,"Fiche", "scrollbars=yes,toolbar=no,menubar=no,location=bo,directories=no,status=no,resizable=yes',width=" + intLargeurEcran + ",height=" + intHauteurEcran + ", left=0,top=0");
	winpopup.focus();
}*/

function openFicheGrandeur(sUrl, iWidth, iHeight) {
		winpopup =	window.open(sUrl,"Fiche", "scrollbars=yes,toolbar=no,menubar=no,location=bo,directories=no,status=no,resizable=yes',width=" + iWidth + ",height=" + iHeight + ", left=0,top=0");
		winpopup.focus();
}

function OuvrirFicheProduit(sNiveau, sUrlFicheProduit) {
	var sUrlFicheProduitRedirect = ''; 
	sUrlFicheProduitRedirect = sNiveau + sUrlFicheProduit;

	window.close();
	window.opener.document.location = sUrlFicheProduitRedirect;
}

function AfficherSwf(sNameFile, sNameSwf, iWidth, iHeight) {
	var sOut = '';

/*	sOut += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" name="' + sNameSwf + '" width=' + iWidth + ' height=' + iHeight + ' id="' + sNameSwf + '">';
	sOut += '<param name=quality value=high>';
	sOut += '<param name="SRC" value="' + sNameFile + '">';
	sOut += '<embed src="' + sNameFile + '" width=' + iWidth + ' height=' + iHeight + ' quality=high type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" swliveconnect="true" name="' + sNameSwf + '">';
	sOut += '</embed></object>';*/
	sOut += '<object id="testid" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + iWidth + '" height="' + iHeight + '">';
	sOut += '<param name="movie" value="' + sNameFile + '">';
	sOut += '<param name="quality" value="high">';
	sOut += '<param name="allowScriptAccess" value="sameDomain">';
	sOut += '<embed src="' + sNameFile + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + iWidth + '" height="' + iHeight + '"></embed></object>';

	return sOut;
}

// afficher le bouton CONTACTEZ-NOUS
function AfficherMenuContactezNousEN(iSection, sNiveau) {
//alert(iSection);
	var sOut = '';
	var aryTitreDocument = new Array();
	aryTitreDocument[0] = new Array(2); 
	aryTitreDocument[1] = new Array(2); 
	aryTitreDocument[2] = new Array(2); 
	aryTitreDocument[3] = new Array(2); 
	aryTitreDocument[4] = new Array(2); 
	aryTitreDocument[5] = new Array(2); 
	aryTitreDocument[6] = new Array(2); 
	aryTitreDocument[7] = new Array(2); 
	aryTitreDocument[8] = new Array(2); 
	aryTitreDocument[9] = new Array(2); 
	aryTitreDocument[10] = new Array(2);
	aryTitreDocument[11] = new Array(2); 
	aryTitreDocument[12] = new Array(2); 
	aryTitreDocument[13] = new Array(2); 
	aryTitreDocument[14] = new Array(2); 
	aryTitreDocument[15] = new Array(2); 
	aryTitreDocument[16] = new Array(2); 
	aryTitreDocument[17] = new Array(2);
	aryTitreDocument[18] = new Array(2);

	aryTitreDocument[0][0]="1091"; aryTitreDocument[0][1]="Escapades champêtres - Forfaits 1";
	aryTitreDocument[1][0]="1092"; aryTitreDocument[1][1]="Escapades champêtres - Forfaits 2";
	aryTitreDocument[2][0]="1093"; aryTitreDocument[2][1]="Escapades champêtres - Forfaits 3";
	aryTitreDocument[3][0]="1094"; aryTitreDocument[3][1]="Escapades champêtres - Forfaits 4";
	aryTitreDocument[4][0]="1095"; aryTitreDocument[4][1]="Escapades champêtres - Forfaits 5"; 
	aryTitreDocument[5][0]="1096"; aryTitreDocument[5][1]="Escapades champêtres - Forfaits 6";
	aryTitreDocument[6][0]="1097"; aryTitreDocument[6][1]="Escapades champêtres - Forfaits 7";
	aryTitreDocument[7][0]="1101"; aryTitreDocument[7][1]="Escapades culturelles - Forfaits 1";
	aryTitreDocument[8][0]="1102"; aryTitreDocument[8][1]="Escapades culturelles - Forfaits 2";
	aryTitreDocument[9][0]="1103"; aryTitreDocument[9][1]="Escapades culturelles - Forfaits 3";
	aryTitreDocument[10][0]="1104"; aryTitreDocument[10][1]="Escapades culturelles - Forfaits 4";
	aryTitreDocument[11][0]="1111"; aryTitreDocument[11][1]="Escapades vélo - Forfaits 1";
	aryTitreDocument[12][0]="1112"; aryTitreDocument[12][1]="Escapades vélo - Forfaits 2";
	aryTitreDocument[13][0]="1113"; aryTitreDocument[13][1]="Escapades vélo - Forfaits 3";
	aryTitreDocument[14][0]="1114"; aryTitreDocument[14][1]="Escapades vélo - Forfaits 4";
	aryTitreDocument[15][0]="1115"; aryTitreDocument[15][1]="Escapades vélo - Forfaits 5"; 
	aryTitreDocument[16][0]="1116"; aryTitreDocument[16][1]="Escapades vélo - Forfaits 6";
	aryTitreDocument[17][0]="1117"; aryTitreDocument[17][1]="Escapades vélo - Forfaits 7";
	aryTitreDocument[18][0]="1118"; aryTitreDocument[18][1]="Escapades vélo - Forfaits 8";
	
	for (var i = 0; i < aryTitreDocument.length; i++) {
		if (aryTitreDocument[i][0] == iSection) {
			strTitreDocument += ' - ' + aryTitreDocument[i][1];
		}
	}


	if (iSection == '100') { // page 100/default.htm (contactez-nous)
		sOut += '<img src="' + sNiveau + 'imag_com/en_contact_02.gif" name="Image16" width="207" height="31" border="0"><a href="' + sNiveau + 'en_menu2.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image17\',\'\',\'' + sNiveau + 'imag_com/en_retour_02.gif\',1)"><img src="' + sNiveau + 'imag_com/en_retour_01.gif" name="Image17" width="153" height="31" border="0"></a><img src="' + sNiveau + 'imag_com/top_03.gif" width="406" height="31" border="0">';
	} else if (iSection == '999') { // page menu.htm et escapades_champetres_culturelles_velos
		sOut += '<a href="100/en_default.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image18\',\'\',\'' + sNiveau + 'imag_com/en_contact_02.gif\',1)"><img src="' + sNiveau + 'imag_com/en_contact_01.gif" name="Image18" width="207" height="31" border="0"></a><img src="' + sNiveau + 'images/top_02.gif" width="559" height="31">';
	} else {
		sOut += '<a href="' + sNiveau + '100/en_default.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image16\',\'\',\'' + sNiveau + 'imag_com/en_contact_02.gif\',1)"><img src="' + sNiveau + 'imag_com/en_contact_01.gif" name="Image16" width="207" height="31" border="0"></a><a href="' + sNiveau + 'en_menu2.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image17\',\'\',\'' + sNiveau + 'imag_com/en_retour_02.gif\',1)"><img src="' + sNiveau + 'imag_com/en_retour_01.gif" name="Image17" width="153" height="31" border="0"></a><img src="' + sNiveau + 'imag_com/top_03.gif" width="406" height="31" border="0">';
	}
	//document.title = strTitreDocument;
	return sOut;
}

/** Navigation dans la map **/

//prevent conflicts by wrapping plugin
(function($) {
    //private function (by scope)
    function QueryStringParser() {
        this.load();
    }

    //add methods to the QueryStringParser class
    $.extend(QueryStringParser.prototype, {
        load: function(suppliedQueryString) {
            //create a new object
            this.Values = new Object();

            //find the index of ? in the supplied string (for testing) or the current url
            var queryString = suppliedQueryString || document.URL;
            var qsIndex = (suppliedQueryString || document.URL).indexOf('?');
            //no query string...return
            if (qsIndex < 0)
                return;

            //strip out the query string only
            queryString = queryString.substring(qsIndex);            
            //no query string...no problem
            if (queryString.length <= 1) {
                return;
            }

            //split into pairs
            var pairs = queryString.split('&');
            //foreach pair
            for (var i = 0; i < pairs.length; i++) {
                //set the value (decode string just in case)
                this.Values[pairs[i].split('=')[0].toLowerCase()] = decodeURIComponent(pairs[i].split('=')[1]);
            }
        },
        get: function(key) {
            return (this.Values[key.toLowerCase()]) ? this.Values[key.toLowerCase()] : '';
        },
        set: function(key, value) {
            this.Values[key.toLowerCase()] = value;
            //chain...in true jQuery fashion
            return this;
        }
    });

    //the $.extend method doesn't appear to allow overriding toString on prototypes
    QueryStringParser.prototype.toString = function() {
        var params = [];

        for (var prop in this.Values) {
            //add the encoded value
            params.push(prop + "=" + encodeURIComponent(this.Values[prop]));
        }

        //return a complete query string
        return '?' + params.join('&');
    };

    //set the global property
    $.Params = new QueryStringParser();
})(jQuery);

$(document).ready(function () {    
	if($.Params.Values['posy'] != undefined && $.Params.Values['posx'] != undefined){
		var pos_y = $.Params.Values['posy'].split('#');
		var pos_x = $.Params.Values['posx'].split('#');
		pos_y = pos_y[0];
		pos_x = pos_x[0];
		$('#CarteMembres').scrollLeft(pos_x);
		$('#CarteMembres').scrollTop(pos_y);
	}
	$('#CarteMembres').mousedown(function (event) {
		$(this)
			.data('down', true)
			.data('x', event.clientX)
			.data('y', event.clientY)
			.data('scrollLeft', this.scrollLeft)
			.data('scrollTop', this.scrollTop);              
		return false;
	}).mouseup(function (event) {
		$(this).data('down', false);
	}).mousemove(function (event) {
		if ($(this).data('down') == true) {
			this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
			this.scrollTop = $(this).data('scrollTop') + $(this).data('y') - event.clientY;
		}
	}).mouseout(function (event) {
		 $(this).data('down', false);
	}).css({
		'overflow' : 'hidden',
		'cursor' : '-moz-grab'
	});
});

$(window).mouseout(function (event) {
	if ($('#CarteMembres').data('down')) {
		try {
			if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
				$('#CarteMembres').data('down', false);
			}                
		} catch (e) {}
	}
});