 
	/*
	* Zoompix v1.0 Alpha
	* @name $().zoompix
	* @author (c) 2008 Juan Pablo Lozano
	*                  - jplozano@warmupmedia.com
	*                  - @ Warmup Interactive
	*/
	 
	var documentBody = (document.all) ? window.body : document.body;

	jQuery.zoompix = function (options) {
	
		// public atributtes
	
		var settings = $.extend({	
			courtinBg: 'black',
			courtinOpacity: 0.7,
			pictureBorderColor: '#ffffff',
			displayInfoAtStart: false
		}, options || {});
		
		// private attributes
		
		// private methods
		
		createDivs = function(){

			$("<div id='alpha'></div>")
				.prependTo(documentBody)
				.css("width", "100%")
				.css("height", "100%")
				.css("top", "0px")
				.css("left", "0px")
				.css("position", "absolute")
				.css("z-index", "450")
				.css("background", settings.courtinBg)
				.css("display", "none")
				.opacity(settings.courtinOpacity);
			if(document.all){ 
				$("#alpha").css("width", $(window).width());
				$("#alpha").css("height", $(window).height());
			}
			$("<div id='preloader'></div>")
				.prependTo(documentBody)
				.css("width", "25px")
				.css("height", "25px")
				.css("top", "50%")
				.css("left", "50%")
				.css("margin-top", "-12px")
				.css("margin-left", "-12px")
				.css("background", "url('images/ajax-preloader.gif') no-repeat")
				.css("z-index", "800")
				.css("position", "absolute")
				.css("display", "none");
			$("<div id='text-container'></div>")
				.prependTo(documentBody)
				.css("width", "200px")
				.css("overflow", "auto")
				.css("position", "absolute")
				.css("z-index", "600")
				.css("color", "white")
				.hide()
		}
			
		posTextContainer = function(imageObj){
			var largePosition = imageObj.findPos();
			$("#text-container")
				.css("height", imageObj.height() + 16 + "px")
				.css("top", largePosition.y + "px")
				.css("left", (largePosition.x + imageObj.width() + 16 + 20) + "px");	
		}
		
		// constructor
	
		$("a.zoompix").each(function(i){
			$(this).attr("id", "gallery-" + i);
			var link = $(this);
			if(!settings.displayInfoAtStart) var text = $($(this).next(".info")).hide();
			link.get(0).onclick = function(){
				var rute = $(this).attr("href");
				var img = $($(this).children()[0]);
				var large = $("#large-gallery-" + i);
				if(large.length == 0){
					$("#alpha").show();
					//$("#alpha").fadeIn("slow", function(){
						$("#preloader").show();
						$("<iframe src='controller/controller.php?do=preloadImage&image=../" + rute + "'></iframe>")
							.appendTo(documentBody)
							.hide()
							.load(function(){
								large = $("<img src='" + rute + "' style='visibility:hidden; position:absolute;' />").prependTo(documentBody);
								setTimeout(function(){
									large
										.attr("title", "Cerrar")
										.attr("id", "large-gallery-" + i)
										.css("z-index", "500")
										.css("border", "8px solid " + settings.pictureBorderColor)
										.css("top", (($(window).height() / 2) - ($("#large-gallery-" + i).height() / 2)) + "px")
										.css("left", (($(window).width() / 2) - ($("#large-gallery-" + i).width() / 2)) + "px")
										.click(function(){
											$("#text-container").hide();
											$("#alpha").hide();
											$(this).fadeOut("slow");
										})
										.hover(
												function(){ 
													$("#text-container")
														.html(text.html())
														.fadeIn("slow");
												},
												function(){
													$("#text-container")
														.html(text.html())
														.hide();
												}
											)
										.css("visibility", "visible")
										.hide()
										.fadeIn("slow");
										$("#preloader").hide();
									posTextContainer(large);
								}, 100);
							});
					//});
				}else{
					$("#alpha").show();
					$("#large-gallery-" + i).fadeIn("slow", function(){
						posTextContainer($(this));
					});
				}
				return false;
			}
		});
		createDivs();

	}