function strstr( haystack, needle, bool ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '

    var pos = 0;

    haystack += '';
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}


 this.imagePreview = function(){	
 
 
 		var viewportwidth;
		var viewportheight;
		
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		
		if (typeof window.innerWidth != 'undefined')
		{
			 viewportwidth = window.innerWidth,
			 viewportheight = window.innerHeight
		}
		
	   // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	   
		else if (typeof document.documentElement != 'undefined'
			&& typeof document.documentElement.clientWidth !=
			'undefined' && document.documentElement.clientWidth != 0)
		{
			  viewportwidth = document.documentElement.clientWidth,
			  viewportheight = document.documentElement.clientHeight
		}
		
		// older versions of IE
		
		else
		{
			  viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			  viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}	


		var halfwaypointx = viewportwidth / 2;
		var halfwaypointy = viewportheight / 2;
 
 
   /* CONFIG */
	   
	   xOffset = 10;
	   yOffset = 30;
	   
	   // these 2 variable determine popup's distance from the cursor
	   // you might want to adjust to get the right result
	   
   /* END CONFIG */
   $("img.preview").hover(function(e){
   
   		if(e.pageX > halfwaypointx)
   		{
   			yOffset = -300;
   		}
   		else
   		{
   			yOffset = 10;
   		}
   		
   		if(e.pageY > halfwaypointy)
   		{
   			xOffset = 300;
   		}
   		else
   		{
   			xOffset = 10;
   		}
   		
	   this.t = this.title;
	   this.title = "";	
	   var bigsrc = this.src;
	   
	   var imagedim = "";
	   
	   if(strstr(bigsrc, 'small'))
	   {
	   		bigsrc = bigsrc.replace("small","large");
	   		imagedim = " width='400' height='400' ";
	   }
	   else
	   {
	   		bigsrc = bigsrc.replace("thumbs","small");
	   		imagedim = " width='300' height='300' ";
	   }
	   
	   var c = (this.t != "") ? "<br/>" + this.t : "";
	   $("body").append("<p id='preview'><img " + imagedim + " src='"+ bigsrc +"' alt='Image preview' />"+ c +"</p>");								 
	   $("#preview")
		   .css("top",(e.pageY - xOffset) + "px")
		   .css("left",(e.pageX + yOffset) + "px")
		   .fadeIn("fast");						
   },
   function(){
	   this.title = this.t;	
	   $("#preview").remove();
   });	
   $("a.preview").mousemove(function(e){
	   $("#preview")
		   .css("top",(e.pageY - xOffset) + "px")
		   .css("left",(e.pageX + yOffset) + "px");
   });			
   
};

