// The Xplanation (Blog)
// © 2010 MBS Direct
// 01.29.2010 dh

// no conflict jQuery / mootools  
// rds 20100327  1632EST  jQuery.noConflict(); 


jQuery(document).ready(function(){

	// Archive Widget - By Topic
	jQuery("#bytopic li").click(function(){
		if (jQuery("#bytopic li ul").is(":hidden")){
				jQuery("#bytopic li ul").slideDown("fast");
      		} 
			else{
        	jQuery("#bytopic li ul").slideUp("fast");
     	}		
	});
	
	jQuery("#bytopic").mouseleave(function(){
		jQuery("#bytopic li ul").animate({ opacity:"100" }, 1000);								  
		jQuery("#bytopic li ul").slideUp("fast");
	});
	
	// Archive - By Month
	jQuery("#bymonth li").click(function(){
		if (jQuery("#bymonth li ul").is(":hidden")){
				jQuery("#bymonth li ul").slideDown("fast");
      		} 
			else{
        	jQuery("#bymonth li ul").slideUp("fast");
     	}		
	});
	
	jQuery("#bymonth").mouseleave(function(){
		jQuery("#bymonth li ul").animate({ opacity:"100" }, 1000);								  
		jQuery("#bymonth li ul").slideUp("fast");
	});
	
	/* Columnize - Three Column
	jQuery('.three-column ol li').addClass("dontsplit"); //Don't split ordered list items across columns
	jQuery('.three-column ul li').addClass("dontsplit"); //Don't split unordered list items across columns
	jQuery('.three-column h3').addClass("dontend"); //Don't leave headers at the end of a column
	jQuery('.three-column').columnize({columns: 3, lastNeverTallest: true});
	
	Columnize - Two Column w/ Side
	jQuery('.two-column-side ol li').addClass("dontsplit"); //Don't split ordered list items across columns
	jQuery('.two-column-side ul li').addClass("dontsplit"); //Don't split unordered list items across columns
	jQuery('.two-column-side h3').addClass("dontend"); //Don't leave headers at the end of a column
	jQuery('.two-column-side').columnize({columns: 2, lastNeverTallest: true});
		
	Columnize - Two Column 50/50
	jQuery('.two-column ol li').addClass("dontsplit"); //Don't split ordered list items across columns
	jQuery('.two-column ul li').addClass("dontsplit"); //Don't split unordered list items across columns
	jQuery('.two-column h3').addClass("dontend"); //Don't leave headers at the end of a column
	jQuery('.two-column').columnize({columns: 2, lastNeverTallest: true}); */
	
	
	// Image Scaling - One Column
	jQuery('img.alignleft, img.alignright').each(function() {
        var maxWidth = 300; // Max width for the image
        var maxHeight = 620;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = jQuery(this).width();    // Current image width
        var height = jQuery(this).height();  // Current image height
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            jQuery(this).css("width", maxWidth); // Set new width
            jQuery(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            jQuery(this).css("height", maxHeight);   // Set new height
            jQuery(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
	
	// Image Scaling - Two Column
	jQuery('img.aligncenter, img.alignnone').each(function() {
        var maxWidth = 618; // Max width for the image
        var maxHeight = 620;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = jQuery(this).width();    // Current image width
        var height = jQuery(this).height();  // Current image height
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            jQuery(this).css("width", maxWidth); // Set new width
            jQuery(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            jQuery(this).css("height", maxHeight);   // Set new height
            jQuery(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });

	
});

//Cufon.replace('p.author-category, .article-preview h5, .widget-dropdown li, #site-footer', {hover:true});
//Cufon.replace('#masthead li a, #blog-article h2, p.post-date, #blog-infograb h5, #blog-sidebar h3, .article-preview h4, body.archive #masthead li.archives a', {hover:true});
