$(document).ready(function () {
    $("a[rel*=external]").live("click", function () {
        var opts = "";
        opts += "width=" + (screen.availWidth - 100) + ",height=" + (screen.availHeight - 100) + ",­screenX=0,screenY=0";
        window.open($(this).attr("href"), "_blank", opts);
        return false;
    });
    preventdefault();
    var nbCount = countLiensUtiles();
    if (nbCount > 0) {
        $('.liens-utiles-sep').show();
        $('.liens-utiles-hold').show();
        var arrayNav = createArrayNav(nbCount);
        displayform('.section-liens-utile', arrayNav[1], arrayNav);
        $('.nextlink').click(function (event) {
            nextLiensUtiles(nbCount, arrayNav);
        })
        $('.previouslink').click(function (event) {
            prevLiensUtiles(nbCount, arrayNav);
        })
    }
});

function riddle(riddlerarray)
{
/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/

//var emailriddlerarray=[121,111,117,64,121,111,117,114,100,111,109,97,105,110,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email 
for (var i=0; i<riddlerarray.length; i++)
 encryptedemail_id32+=String.fromCharCode(riddlerarray[i])

//document.write('<a href="mailto:'+encryptedemail_id32+'">Contact Us</a>')
document.write(encryptedemail_id32)
}

function riddle2(riddlerarray)
{
/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/

//var emailriddlerarray=[121,111,117,64,121,111,117,114,100,111,109,97,105,110,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email 
for (var i=0; i<riddlerarray.length; i++)
 encryptedemail_id32+=String.fromCharCode(riddlerarray[i])

//document.write('<a href="mailto:'+encryptedemail_id32+'">Contact Us</a>')
window.location.assign(encryptedemail_id32)
}

/* bannières */
function feedBan(HtmlDivID, flash, image, alt, link, banWidth, banHeight, target) {
	var ctnr = document.getElementById(HtmlDivID);
	var img = '';
	if (target != '') {
		img = '<a href="' + link + '" target="' + target + '"><img src="' + image + '" alt="' + alt + '" />';
	} else {
		img = '<a href="' + link + '"><img src="' + image + '" alt="' + alt + '" />';
	}


	if (flash == "") {
		ctnr.innerHTML = img;
	} else {
		var so = new SWFObject(flash, "banner", banWidth, banHeight, "7.0.0", "#FEFCF1");
		so.write(HtmlDivID);
		if (so.write(HtmlDivID) == false) ctnr.innerHTML = img;
	}
	ctnr.style.display = "block";
}


/*sfHover = function() {
	
	var sfEls = document.getElementById("NavList").getElementsByTagName("LI");
	for (var i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " sfhover";
		}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);*/



/* social bookmarks */
var strTitle = encodeURIComponent(document.title);
var strUrl = encodeURIComponent(document.location.href);

function deli_click() {
	window.open('http://delicious.com/save?v=5&noui&amp;jump=close&url=' + strUrl + '&title=' + strTitle, 'delicious', '');
	return false;
}

function digg_click() {
	window.open('http://digg.com/submit?url=' + strUrl + '&title=' + strTitle, 'digg', '');
	return false;
}

function fbs_click() {
	window.open('http://www.facebook.com/sharer.php?u=' + strUrl + '&t=' + strTitle, 'sharer', 'toolbar=0,status=0,width=626,height=436');
	return false;
}

function SetSelected(strField) {
	var field = document.getElementById(strField);
	if (field) {
		field.select();
	}
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

//
//$(document).ready(function(){
//$('#zonePub').addClass('actif');
//});


// banniere 'zonePub' en haut de la page


function initzonePub() {

	$('#zonePub').addClass('actif');
	
   
}

function showzonePub() {

	$('#zonePubToggle').unbind('click');
	$('#zonePub').animate({ 'height': '150px' }, 1000);
	$('#zonePubToggle').html('<span class="masquer">Masquer</span>');
	$('#zonePubToggle').click(function() {
	hidezonePub();
		return false;
	});
}

function hidezonePub() {
	$('#zonePubToggle').unbind('click');
	$('#zonePub').animate({ 'height': '0' }, 1000);
	$('#zonePubToggle').html('<span class="montrer">Afficher</span>');
	$('#zonePubToggle').click(function() {
	showzonePub();
		return false;
	});
}



window.onload = function(e) {
	var cookie = readCookie("ZonepubTCQ");
	if (cookie == "true") {
		$(document).ready(function() { hidezonePub(); });
	} else {
	setTimeout("showzonePub()", 1000);
	}
}

window.onunload = function(e) {
	createCookie("ZonepubTCQ", "true", 1);
}

var cookie = readCookie("ZonepubTCQ");
if (cookie == "true") {
	$(document).ready(function() { hidezonePub(); });
} else {
setTimeout("showzonePub()", 1000);
}


function showDescription() {
	document.getElementById('BoxDescription').style.display = "block";
	document.getElementById('BoxForfaits').style.display = "none";
	document.getElementById('BoxPhotos').className = "invisible";
	document.getElementById('BoxProxim').className = "invisible";
	document.getElementById('descrip').className = "On";
	document.getElementById('forfait').className = " ";
	document.getElementById('photos').className = " ";
	document.getElementById('proxim').className = " ";
	
	document.getElementById('colonneDroite').style.display = "block";
   
	
}
function showForfaits() {
	document.getElementById('BoxDescription').style.display = "none";
	document.getElementById('BoxForfaits').style.display = "block";
	document.getElementById('BoxPhotos').className = "invisible";
	document.getElementById('BoxProxim').className = "invisible";
	document.getElementById('descrip').className = " ";
	document.getElementById('forfait').className = "On";
	document.getElementById('photos').className = " ";
	document.getElementById('proxim').className = " ";
	
	document.getElementById('colonneDroite').style.display = "block";

}

function showPhotos() {
	document.getElementById('BoxDescription').style.display = "none";
	document.getElementById('BoxForfaits').style.display = "none";
	document.getElementById('BoxPhotos').className = "visible";
	document.getElementById('BoxProxim').className = "invisible";
	document.getElementById('descrip').className = " ";
	document.getElementById('forfait').className = " ";
	document.getElementById('photos').className = "On";
	document.getElementById('proxim').className = " ";

	document.getElementById('colonneDroite').style.display = "none";

}

function showProxim() {
	
	document.getElementById('BoxDescription').style.display = "none";
	document.getElementById('BoxForfaits').style.display = "none";
	document.getElementById('BoxPhotos').className = "invisible";
	document.getElementById('BoxProxim').className = "visible";
	document.getElementById('descrip').className = " ";
	document.getElementById('forfait').className = " ";
	document.getElementById('photos').className = "";
	document.getElementById('proxim').className = "On";

	document.getElementById('colonneDroite').style.display = "none";

}




/***********************************************
* Vidéos/
* **********************************************/
var lang = 'fr';

function playVideoHome(element, target) {        
	var so = new SWFObject("/player/player-licensed.swf", "videoplayer", "322", "370", "8.0.0");

	so.addVariable("file", "/medias/fr/videos/" + element);    
	so.addVariable("shuffle", "false");
	so.addVariable("playlist", "bottom");
	so.addVariable("playlistsize", "125");
	so.addVariable("repeat", "list");
	so.addVariable('playlist.thumbs', 'false');
	document.getElementById(target).className += " vidList";
		
	so.addParam('wmode', 'opaque');                   
	so.addVariable('title', 'jump');    
	so.addVariable("height", "370");

	so.addVariable('skin', '/player/styleplayer.swf&frontcolor=ffffff&lightcolor=A1A477&playlistsize=122&playlist=bottom&stretching=fill&backcolor=A1A477');
	so.addVariable("width", "322");
	so.addVariable("volume", "100");
	so.addVariable("usefullscreen", "true");
	so.addParam("allowfullscreen", "true");
	so.addVariable("backcolor", "0x536420");
	so.addVariable("frontcolor", "0xffffff");
	so.addVariable("lightcolor", "0xA1A477");

	so.write(target);
	//if (wmode == true) so.addParam("wmode", "opaque");
	//if (autoplay) so.addVariable("autostart", "true");
	so.write(target);
	if (so.write(target) == false) disableVideo(target);       
}


function disableVideo(target) {
	var ctnr = document.getElementById(target);
	var txt = '<span>Le lecteur Adobe Flash doit être installé sur votre navigateur pour visualiser nos vidéos.<br /><br /><a href="http://www.adobe.com/go/getflashplayer" target="_blank">Téléchargez la dernière version ici</a></span>';
	if (lang == "en") txt = '<span>Adobe Flash Player must be installed on your browser to watch our videos.<br /><br /><a href="http://www.adobe.com/go/getflashplayer" target="_blank">Download the latest version here</a></span>'
	ctnr.className += " vidBoxMsg";
	ctnr.innerHTML = txt;
}


function feedmenu(control, strHTML) {

	var divContainer = $(control).parent().parent().parent().parent().parent().parent();
	var controlDiv = $(divContainer).find('.subContentPub');
	if (controlDiv) {
		controlDiv.html(strHTML);
		}
}

function english() {
	alert("coming soon!");
}

/***********************************************
* Via Explora/
* **********************************************/

Iframesrc = "http://www.viaexplora.com/app/iframe.html?membre=CentreDuQuebec&zoom=9&amp;lat=46.0&amp;lng=-72.2&force=1&controls=DirectionsF,Defaut"
function setReq(astr) {
    var nb = $("div[id$=divSaisonsExplora]").size();

    if (nb > 0) {
        var strLink = Iframesrc + '&' + astr;

        $("iframe[id$=iframeExplora]").attr("src", strLink);
        $("a[id$=abtnAgrandir]").attr("href", strLink); 
    }
}


/**Liens utiles**/
function preventdefault() {

    var arrayAPrevent = ['.previouslink', '.nextlink'];

    for (i = 0; i < arrayAPrevent.length; i++) {
        var temp = arrayAPrevent[i];
        $(temp).each(function (index) {
            $(this).click(function (event) {
                event.preventDefault();
            })
        });
    }

}


function getClassVisibleContent() {
    var thisContentId = '';

    $('.section-liens-utile').each(function (index) {
        if ($(this).is(':visible')) {
            thisContentId = ($(this).attr('id'));
        }
    });
    return thisContentId;
}


function countLiensUtiles() {
    var count = 0;
    $('.section-liens-utile').each(function (index) {
        count++;
    });
    return count;
}

function createArrayNav(nbCont) {
    var arrayNav = new Array();
    for (x = 1; x <= nbCont; x++) {
        arrayNav[x] = "#lienutile" + x;
    }
    return arrayNav;
}

function nextLiensUtiles(nbCont, arrayNav) {
    var thisActiveContent = "#"+getClassVisibleContent();
    for (x = 1; x <= nbCont; x++) {
        if (thisActiveContent == arrayNav[x]) {
            displayform('.section-liens-utile', arrayNav[x + 1], arrayNav);
        }
    }
}


function prevLiensUtiles(nbCont, arrayNav) {
    var thisActiveContent = "#" + getClassVisibleContent();
    for (x = 1; x <= nbCont; x++) {
        if (thisActiveContent == arrayNav[x]) {
            displayform('.section-liens-utile', arrayNav[x - 1], arrayNav);
        }
    }
}

function displayform(classegenerique, nomclasse, arrayNav) {
    $(classegenerique).each(function (index) {
        $(this).hide();
    });
    $(nomclasse).show();

    hideNavigation(arrayNav);
}


function hideNavigation(arrayNav) {
    var thisActiveContent = "#"+getClassVisibleContent();

    if (thisActiveContent == arrayNav[arrayNav.length-1])
        $('.nextlink').hide();
    else
        $('.nextlink').show();

    if (thisActiveContent == arrayNav[1])
        $('.previouslink').hide();
    else
        $('.previouslink').show();
}

/*fonctions utilisées dans cartes postales*/

function getUrlVar(requestedKey) {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    if (typeof requestedKey == 'undefined') {
        return vars;
    } else {
        return vars[requestedKey];
    }
}

function showDiv(divclass) {
    if (divclass <= 5)
        $(".dest" + divclass).show();
    if (divclass == 2)
        $("a.ajoutami").css("padding-bottom", "25px");
    if (divclass == 5)
        $("a.ajoutami").hide();
}

function changeMessage(classselectmessage, classchampsmessage) {
    $(classselectmessage).change(function () {
        var temp = $(this).attr('selectedIndex');
        if (temp != 0) {
            var str = "";
            str = $(this + "option:selected").text() + " ";

            $(classchampsmessage).val(str);
        }
        else
            $(classchampsmessage).val("");
    })

}


function getModal(src) {
    $.modal('<iframe src="' + src + '" height="600" width="800" frameborder="0" allowTransparency="true" style="border:none 0;background-color:transparent">', {
        containerCss: {
            height: 600,
            padding: 0,
            width: 800
        },
        closeClass: "modalClose",
        closeHTML: "<a href='#'>[ Fermer ]</a>"
    });

}
