﻿// Ouverture de popup
//--------------------
function NewWindowsScroll(mypage, myname, w, h, pos, infocus) {
	NewWindowScroll(mypage, myname, w, h, pos, infocus);
	return false;
}

function NewWindowScroll(mypage, myname, w, h, pos, infocus) {
	if (pos == "random") {
		myleft = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
		mytop = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
	}

	if (pos == "center") {
		myleft = (screen.width) ? (screen.width - w) / 2 : 100;
		mytop = (screen.height) ? (screen.height - h) / 2 : 100;
	} else if ((pos != 'center' && pos != "random") || pos == null) {
		myleft = 0;
		mytop = 20;
	}
	settings = "width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=1,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win = window.open(mypage, myname, settings);
	win.focus();
}


// Traitement du préloading des images
//-------------------------------------
(function ($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function () {
		var args_len = arguments.length;
		for (var i = args_len; i--; ) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	},

	$.affiche = function (id) {
		if ($(id).is(":hidden"))
			$(id).show();
		else
			$(id).hide();
	}
})(jQuery)

// Traitement des favoris
//---------------------------------
$().ready(function () {
	// add a "rel" attrib if Opera 7+
	if (window.opera) {
		if ($("a.jqbookmarkprive").attr("rel") != "") { // don't overwrite the rel attrib if already set
			$("a.jqbookmarkprive").attr("rel", "sidebar");
		}
		if ($("a.jqbookmarkpro").attr("rel") != "") { // don't overwrite the rel attrib if already set
			$("a.jqbookmarkpro").attr("rel", "sidebar");
		}
	}

	$("a.jqbookmarkprive").click(function (event) {
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = 'http://www.1001salles.com/prive/';
		var title = 'www.1001salles.com - Organisation d\'événements privés';

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url, "");
		} else if (window.external) { // IE Favorite
			window.external.AddFavorite(url, title);
		} else if (window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			alert('Pour cela, cliquez simplement sur le bouton \'Signets / Ajouter un signet\' juste à coté de votre barre d\'adresses !');
		}
	});
	$("a.jqbookmarkpro").click(function (event) {
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = 'http://www.1001salles.com/pro/';
		var title = 'www.1001salles.com - Organisation d\'événements professionnelles';

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url, "");
		} else if (window.external) { // IE Favorite
			window.external.AddFavorite(url, title);
		} else if (window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			alert('Pour cela, cliquez simplement sur le bouton \'Signets / Ajouter un signet\' juste à coté de votre barre d\'adresses !');
		}
	});
});


// Gestion, d'ouverture des fenêtre modales
//-------------------------------------------
	$(function () { // FancyBox
		$(".mailconseil").fancybox({
			'width': 640,
			'height': 450,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe'
		}),
		$(".mailcontact").fancybox({
			'width': 640,
			'height': 450,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe'
		}),
		$(".mappyzoom").fancybox({
			'width': 800,
			'height': 420,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe',
			'titleShow': false
		}),
		$(".fbInscription").fancybox({
			'width': 800,
			'height': 420,
			'frameWidth': 800,
			'frameHeight': 420,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'ajax',
			'href': './Avertissement.htm',
			'titleShow': false
		}),
		$(".fbInscriptionp").fancybox({
			'width': 800,
			'height': 420,
			'frameWidth': 800,
			'frameHeight': 420,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'ajax',
			'href': './Avertissement.htm',
			'titleShow': false
		});
	});

	$(function () { // FancyBox
		$(".popupVideoTour").fancybox({
			'width': 640,
			'height': 640,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe'
		}),
		$(".popupVideoTour").fancybox({
			'width': 640,
			'height': 640,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'type': 'iframe'
		});

	});

	$(function() { // Nyromodal
		$.nyroModalSettings({
			processHandler: function(settings) {
				var url = settings.url;
				//if (url && url.indexOf('http://www.youtube.com/watch?v=') == 0) {
					$.nyroModalSettings({
						height: 320,
						width: 640,
						minWidth: 400, // Largeur minimale
						minHeight: 300 // Hauteur minimale
						//url: url.replace(new RegExp("watch\\?v=", "i"), 'v/')
					});
			},
			endShowContent: function(elts, settings) {
				$('.resizeLink', elts.contentWrapper).click(function(e) {
					e.preventDefault();
					$.nyroModalSettings({
						width: Math.random()*1000,
						height: Math.random()*1000
					});
					return false;
				});
				$('.bgLink', elts.contentWrapper).click(function(e) {
					e.preventDefault();
					$.nyroModalSettings({
						bgColor: '#'+parseInt(255*Math.random()).toString(16)+parseInt(255*Math.random()).toString(16)+parseInt(255*Math.random()).toString(16)
					});
					return false;
				});
			}
		});
	});


// Traitement pour l'affichage des éléments
//-------------------------------------------
function affiche_Cache(id) {
	if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

function affiche_Cache2(id) {
	if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
		document.getElementById(id).style.display = 'inline';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}



jQuery.preLoadImages("/images/prive/panier-fond-fiche.gif");
$("#panier").ready(
	function () {
		$("#panier ul > li").css({ "cursor": "pointer" }),
		$("#panier ul > li").click(
			function () {
				window.location = $(this).find("a").attr("href");
			}
		),
		$("#panier ul li").each(
			function () {
				$(this).find(".trash").hide();
				$(this).find(".fiche").html($(this).find(".fiche").text().split('(')[0] + "(<span>" + $(this).find(".fiche").text().split('(')[1].split(')')[0] + "</span>)");
			}
		),
		$("#panier ul li").hover(
			function () {
				$(this).addClass("li-hover");
				$(this).find(".trash").show();
			},
			function () {
				$(this).removeClass("li-hover");
				$(this).find(".trash").hide();
			}
		)
	}
);
