jQuery.fn.jLightbox = function(settings) {

	settings = jQuery.extend({}, jQuery.fn.jLightbox.defaults, settings);
	$(this).unbind("click");



	$(this).bind("click", function() {


		$src = "http://imagens.cyrela.com.br/";
        
		if (settings.showTitle) {
			$("#divLightboxImagem li.meio h2").show();
			$("#divLightboxImagem li.meio h2 img").attr("src", $src + settings.titleImage).attr("alt", settings.altTitle).show();
		}
		else {
			$("#divLightboxImagem li.meio h2").hide();
		}

		if (settings.showTopText) {
			$("#divLightboxImagem .boxImagem h3").text($(this).attr("title")).show();
		}
		else {
			$("#divLightboxImagem .boxImagem h3").hide();
		}

		if (settings.showBottomText) {
			$jParent = $(this).parent().parent().parent().parent().parent().parent().parent().attr("id");
			
			if($("#" + $jParent + " > p").hasClass("legendaPlantas"))
			{
				var textBottom = $("#" + $jParent + " > p").text();
			} 
			else 
			{
				var textBottom = $("img", $(this)).attr("alt");
			}
			$("#divLightboxImagem li.meio p").show().text(textBottom);
		}
		else {
			$("#divLightboxImagem li.meio p").hide();
		}

		if (settings.showBottomButton) {

			$("#divLightboxImagem .btBottom").show();

			$("#divLightboxImagem .btBottom a").attr("href", settings.bottomButtonLink).show();

			$("#divLightboxImagem .btBottom a img").attr("src", $src + settings.bottomButtonImage);

		}
		else {
			$("#divLightboxImagem .btBottom").hide();
		}

		$("#divLightboxImagem .boxImagem > img").attr("src", $src + $(this).attr("href")).load(function() {

			var fixImg = ((this.height + 121) / 2) * (-1);
			var newtop = ($(window).height() / 2) + $(window).scrollTop();
			$("#divLightboxImagem").css({
				top: newtop >= 0 ? newtop + "px" : 0,
				marginTop: fixImg + "px"
			});
		});

       
		
		$("#divOverlay").show();


		$("#divLightboxImagem").slideDown().show();

		if (settings.callback) {
			eval(settings.callback);
		}

		return false;
	});
};

jQuery.fn.jLightbox.defaults = {
	animateTo : "slideDown",
	showTitle : false,
	altTitle : "",
	titleImage: "pt-BR/titImprimirImagem.gif",
	showTopText : false,
	showBottomText : false,
	showBottomButton : false,
	bottomButtonImage: "pt-BR/btImprimir.gif",
	bottomButtonLink : "#",
	callback : null
};