/*  A utiliser avec jQuery & Colorbox
	Fonction phototheque: Sert pour la configuration & le lancement
	de la photothèque.
*/

function phototheque() {
	var cboxContentHeight;
	var UUID = null;
	var initNiveauId = null;
	
	if (arguments.length >= 1) {
		UUID = arguments[0];
		if (arguments.length >= 2) {
			initNiveauId = arguments[1];
		}
	}

	var options = {
		rel:"nofollow",
		scrolling: "false",
		iframe: true,
		innerWidth: "946px",
		innerHeight: "512px",
		overlayClose: false,
		onLoad: function () {
			var compositeColorbox = $("#cboxTopLeft, #cboxTopCenter, #cboxTopRight," +
				"#cboxBottomLeft, #cboxBottomCenter, #cboxBottomRight,"+
				"#cboxMiddleLeft, #cboxMiddleRight,#cboxClose");

			compositeColorbox.each(function() {
				if ($(this).css('display') != "none") {
					$(this).addClass('hiddenCompositeColorbox');
				}
				$('.hiddenCompositeColorbox').hide();
			});

			if ($("#cboxTopCenter").hasClass('hiddenCompositeColorbox')) {
				$("#colorbox").css({
					marginTop: $("#cboxTopCenter").height()
				});
			}
		},
		onComplete: function () {
			cboxContentHeight = $('#cboxContent').css("height");
			$('#cboxContent').css({height: 512});
		},
		onClosed: function () {
			$('#cboxContent').css({
				height: cboxContentHeight
			});
			$('.hiddenCompositeColorbox').show().removeClass('hiddenCompositeColorbox');
		}
	}

	if (UUID != null) {
		if (initNiveauId != null) {
			$.extend(
				options,
				{href:"/index.cfm/phototheque/UUID/" + UUID + "/initNiveauId/" + initNiveauId + "/notV2/true"}
			);
		} else {
			$.extend(
				options,
				{href:"/index.cfm/phototheque/UUID/" + UUID + "/notV2/true"}
			);
		}
		
		$.fn.colorbox(options);
	} else {
		$('.link-phototheque').colorbox(options);
	}
}
