function jaixm() {
	$("a[rel='category tag']").addClass("category");
}	

$(document).ready(function() {
    // Search value to ""
    $("#sidebar #searchsubmit").attr("value", "");
    
    if ( navigator.userAgent.indexOf("MSIE 6") != -1 ) {
        $("#single #sidebar").css("margin-right", "0px");
        $(".zoom-in").attr("width", "26");
        $("#social-bookmarks li img").css("background-repeat", "no-repeat");
    }

	// Jaixm Gallery powered by Juan Manuel Lemus
	var thumbsrc = new Object();
	var img      = new Object();
	var iclicked = 0;
	var ier      = 0;        // IE image reload

	// Addon on June 26, 2009: Height adjust
	if ( $("#sidebar").height() > (  $("#photos").height() + 50 ) ) {
		var ir  = Math.ceil( $("#sidebar").height() / 87 ); 
		var tnw = ( Math.floor( $(".thumb-src").size() / ir ) );  
		
		$("#single").width( (78 * tnw) + 340 ) ;
	
	}
	
	// Converting simple gallery to cuadratic gallery
		$(".thumb-src").each(function(i, o) {
			// Adapting thumb targets
			$(o).attr("target-url", $(o).parent().attr("href") );		
			
			// Cleaning HREF attribute (evit hyperlink)
			$(o).parent().attr("href", "#" + $(o).parent().attr("href").replace( $("#photos").attr("basedir"), "" ).replace("\.jpg", "") );							
		
			$(o).parent().prepend('<div class = "go-zoom"><img class = "zoom-in" src = "' + $("#zoom").attr("basedir") + '/images/fullsize-icon.png" width = "24" /><div class = "zoom-loading"><img src = "' + $("#zoom").attr("basedir") + '/images/fullsize-loading-spinner.gif" /></div></div>');
			
			// Making pretty effect
			$(o).parent().mousemove(function() {
				var axis  = $(this).position();
				
				    // Fixing for Internet Explorer, first thumb of each arrow have Y-top position of above row
				    var ytop = axis.top;
				    
				    if ( navigator.userAgent.indexOf("MSIE") != -1 ) {
				        if ( ( event.y - ytop ) > 50 )
				            ytop += 78;
				    }
				        
				
				var btop  = 63;
				var bleft = 3;
				
				if ( window.opera )
					btop  = 0;
				else if ( navigator.userAgent.indexOf("MSIE") != -1 ) {
				    btop  = -1;
				    bleft = 1;
				}
				
				if ( $(this).find(".zoom-loading").css("display") == "none" ) {
					$(this).find(".go-zoom").hide();
					$(this).find(".zoom-in").show();
					$(this).find(".zoom-loading").hide();
				}
				$(this).find(".go-zoom").css("left", (axis.left + bleft) + "px").css("top", (ytop - btop) + "px").css("display", "block");
				
			}).mouseout(function(i, o) {
				if ( $(this).find(".zoom-in").css("display") != "none" )
					$(this).find(".go-zoom").css("display", "none");
			});
		});
		
		// Erasing Title tag
		$("#photos").attr("title", "");
		
		// Go Zoom activate click function on parent
		$(".go-zoom").click(function(){
			$(".thumb-src").css('opacity', 1.0);
			$("#zoom").fadeOut();
		});
	
		/**
		 * Zooom Thumbnail
		 * @param  object
		 **/
		function zt( thumb ) {
			$("#zoom .zoom-photo").attr("src", $(thumb).attr("target-url") );	// Change Normal view image source
			
			if ( $("#zoom").css("display") != "none" )			// Fade Out effect (or other)
				$("#zoom").fadeOut("fast");
			
			var img     = new Image();						// Loading information about thumb-target
				img.src = $(thumb).attr("target-url");
			
			$(img).load(function(i, o) {					// Fade in (image was loaded)
				// Hidding loading
				$(thumb).parent().find(".go-zoom .zoom-loading").css("display", "none");
				
				// Checking if user don't click other picture
				if ( iclicked > 1 ) {
					iclicked = 0;
					return;
				}
				
				// Grabing Additional information
					if ( $(thumb).attr("url-link")        != null ) 
						$("#zoom img").attr("url-link",  $(thumb).attr("url-link") );
					else
						$("#zoom img").removeAttr("url-link");

						
					if ( $(thumb).attr("url-title")       != null ) 
						$("#zoom img").attr("url-title", $(thumb).attr("url-title") );
					else
						$("#zoom img").removeAttr("url-title");
					
					
					if ( $(thumb).attr("url-description") != null ) 
						$("#zoom img").attr("url-description", $(thumb).attr("url-description") );
					else
						$("#zoom img").removeAttr("url-description");
				
					// Ir URL-link, set cursor pointer
					if ( $("#zoom img").attr("url-link") != null ) {
						$("#zoom img").css("cursor", "pointer");
					} else {
						$("#zoom img").css("cursor", "inherit");
					}
				
				// Reseting var
				iclicked = 0;
				
				// Thumb Width
				var tw = $(thumb).width() + parseFloat( $(thumb).css("margin-left").replace("px", "") ) + parseFloat( $(thumb).css("margin-right").replace("px", "") );
				
				    // Type exact dimension on Internet Explorer, 
				    if ( navigator.userAgent.indexOf("MSIE") != -1 )
				        tw = 77;
				
				// Getting fraction part of number
				var d  = ( img.width / tw ) - ( Math.floor( img.width / tw )  );
				    
				// Thumb is adjusted to width thumbs
				if ( d > 0.5 )
					$("#zoom .zoom-photo").attr("width", ( Math.ceil ( img.width / tw ) * tw ) - parseFloat( $(thumb).css("margin-right").replace("px", "") ) - 1 );
				else
					$("#zoom .zoom-photo").attr("width", ( Math.floor( img.width / tw ) * tw ) - parseFloat( $(thumb).css("margin-right").replace("px", "") ) - 1 );
				
				var axis  = $(thumb).position();								// Getting information about X,Y position (thumb)
				
				var xleft = axis.left;						
				var ytop  = axis.top;
			
				if ( ( xleft + parseInt( $("#zoom .zoom-photo").attr("width") ) ) > $("#photos").width() )		// Adapting visualization to screen dimensions
					xleft = xleft + $(thumb).width() - parseInt( $("#zoom .zoom-photo").attr("width") );	
				
				    // MSIE and based browser miss 4px
				    if ( ( navigator.userAgent.indexOf("MSIE") != -1 ) && ( xleft != axis.left ) )
				        xleft += 4;
				
					// Revaluating position on X
					if ( xleft < 340 ) xleft = axis.left;
				
				// New Image Height
				var nih = ( img.height * parseInt( $("#zoom .zoom-photo").attr("width") ) ) / img.width;
				
				// Zoom Container Height is adapted to evit overflow	
				$("#zoom").css("height", ( ( Math.floor( nih / tw ) * tw ) - 1.5 ) + "px" );
				
				// Zoom Container Width is setted to avoid visualization bugs
				$("#zoom").css("width" , $("#zoom .zoom-photo").attr("width") + "px" );				
				
				    // IE don't show correctly width and height on first click, bug fixing it
				    if ( navigator.userAgent.indexOf("MSIE") != -1 ) {
				       // --> $("#zoom").css("width", $("#zoom .zoom-photo").css("width") );
				       // --> $("#zoom").css("height", ( ( ( Math.floor( ( $("#zoom .zoom-photo").css("width").replace("px", "") * img.height / img.width ) / tw ) * tw ) - 1.5 ) + "px" ) );
				    } 
				
					// Zoom height was adapted, now; fixing Zoom Image position top
					var fih = nih - parseInt( $("#zoom").css("height").replace("px", "") );
					$("#zoom .zoom-photo").css("top", "-" + ( fih / 2) + "px" );
				
				if ( ( ytop + nih ) > $("#photos").height() )
					ytop = ytop + $(thumb).height() - nih + fih;
					
					 // MSIE and based browser miss 4px
				    if ( ( navigator.userAgent.indexOf("MSIE") != -1 ) && ( ytop != axis.top ) ) 
				        ytop += 4;
					
					// Reluating position on Y
					if ( ytop < 0 ) ytop   = axis.top;
			
				$("#zoom").css("left", xleft + parseFloat( $(thumb).css("margin-left").replace("px", "") )  );
				$("#zoom").css("top" , ytop  + parseFloat( $(thumb).css("margin-top").replace("px", "") ) );
							
				
				ier = 1 - ier;
				if ( ( ier == 1 ) && ( navigator.userAgent.indexOf("MSIE") != -1 ) ) {
				    $("#zoom").css("width", "1px").css("height", "1px");
				    $("#zoom").fadeIn("fast");
				    $(thumb).click();
				} else {
				    ier = 0;
				    
				    $("#zoom").fadeIn("fast", function() { 
				
    					var zih = $("#zoom").position().top + $("#zoom img").height();
    					
    					if ( zih > $("#sidebar").height() )
    						$("#sidebar").height( zih );  
    				});
    				
    				// Make transparent
				    $(".thumb-src").css('opacity', 0.7);
				}
			});
			
			// Browser-hacks for Microsoft Internet Explorer
			if ( ( navigator.userAgent.indexOf("MSIE") != -1 ) || ( window.opera ) ) {
			    if ( img.complete )
			        $(img).load();
			}
		}
		
	
		// Thumb was clicked
		$(".thumb-src").click(function() {
			$(".thumb-src").css('opacity', 1.0);
			
			// Loading in process, eviting two loading image
			if ( iclicked > 0 )
				return;
			
			// Hidding Zoom-in and showing Zoom Loading
			$(this).parent().find(".go-zoom .zoom-in").css("display", "none");
			$(this).parent().find(".go-zoom .zoom-loading").css("display", "block");
		
			// Loading in process
			iclicked++;
		
			if ( $("#zoom").css("display") == "none" ) { zt( $(this) ); }
			else {
				thumbsrc = $(this); $("#zoom").fadeOut("fast", function() { zt( thumbsrc ); });
			}		
		});
		
		// User click on zoom object
		$("#zoom img").click(function() { 
		    if ( $("#zoom img").attr("url-link") != null ) {
				window.open( $("#zoom img").attr("url-link") );
			} else {
				$(".thumb-src").css('opacity', 1.0);
			
				$("#zoom").fadeOut(); 
			}
		});
});