$(function(){
	var yOffset = 10;
	var xOffset = 30;
	var thumb_selector = "a.thumb-with-preview"; 
	var preview_id = "full-preview";
	
	var setOffsets = function(e)
	{
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		var left = e.pageX + xOffset;
		var top = e.pageY - yOffset;
		
		var width = $('#' + preview_id).outerWidth();
		var height = $('#' + preview_id).outerHeight("margin");

		if (left + width > xScroll + windowWidth) {
			left = e.pageX - xOffset - width;
		}
		
		if (top + height > yScroll + windowHeight) {
			top = e.pageY + yOffset - height;
		}
		
		$('#' + preview_id)
			.css("top",top + "px")
			.css("left",left + "px");
	};

	$(thumb_selector).hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='" + preview_id + "'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
		setOffsets(e);
		$('#' + preview_id).css("z-index", 100).bgiframe().show();//.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$('#' + preview_id).remove();
    });	
	
	$(thumb_selector).mousemove(setOffsets);			
});

$(function(){
	$("a.thumb-with-lightbox").lightBox({
		//'fixedNavigation':	true,
		'imageLoading': '/images/lightbox/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
		'imageBtnPrev': '/images/lightbox/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
		'imageBtnNext': '/images/lightbox/lightbox-btn-next.gif', // (string) Path and the name of the next button image
		'imageBtnClose': '/images/lightbox/lightbox-btn-close.gif', // (string) Path and the name of the close btn
		'imageBlank': '/images/lightbox/lightbox-blank.gif'
	});
	
	$("a.thumb-with-preview").click(function(){return false});	
});


