/*
 * 
 * jQuery EZJax v. 1.0.1
 * http://www.thecreativeoutfit.com
 * 
 * 
 */

jQuery.fn.ezjax = function(o) {
  
  obj = jQuery(this).attr('class'); 
  
  // Defaults
  var o = jQuery.extend( {
    container: '#ezjax_content',
    title : null,
    description : null,
	initial: null,
	effect: null,
	speed: 'slow',
	easing: null,
	bind: '.'+obj
  },o);
  
  // Load initial
  
	if(o.initial!=null){
		jQuery(o.container).load(o.initial,function(){
		bind();
	});
	}
  
  // Re-bind for any links internal to the content
  
	function bind(){
		jQuery(o.container+' '+o.bind).ezjax({
			container: o.container,
			title : o.title,
			description : o.description,
			initial: null,
			effect: o.effect,
			speed: o.speed,
			easing: o.easing
		});
	}
  
  // Main functionality
  
  return this.each(function() {
  
  	jQuery(this).click(function(){
		var url = jQuery(this).attr('href');
		
		// Check for transition effect
		
		if (o.effect != null) {

				$(o.container).fadeOut("slow", function(){	
					$(o.container).before('<img id="loader" src="/templates/images/ajax-loader.gif"/>');	
					$(o.container).load(url, function(){
						$("#loader").remove();
						$(o.container).fadeIn(o.speed);
						bind();
					});
				});		
		}
		else {
			// Standard load (no effect)
			//$(o.container).animate({ opacity: 0 }, 200);
			jQuery(o.container).hide();
			document.title = o.title;
			jQuery(o.container).before('<img id="loader" src="/templates/images/ajax-loader.gif"/>');
			jQuery(o.container).load(url,function(){			
				$("#loader").remove();
				jQuery(o.container).show();
				if($("#category34nav").length > 0)
				{
					$("#category34nav").scrolldiv();
				}
				if($(".cmspage").length > 0)
				{
					$(".cmspage").equalizeCols();
				}
				//$(o.container).animate({ opacity: 1 }, 500);
				bind();
			});
		}
		
		// Keeps the href from firing
		return false;
		
	});
  
  });
  
};