var $ = jQuery.noConflict();

//Menu
$(document).ready(function() {
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#nav li .sub").css({'display':'none'});
	$("ul#nav li").hoverIntent(config);

});

//Post images max size
jQuery(document).ready(function($){ 
    //Configuration Options
    var max_width = 560;    //Sets the max width, in pixels, for every image
    var selector = 'div.single img'; //Sets the syntax for finding the images.  Defaults to all images.
    $(selector).each(function(){
        var width = $(this).width();
        var height = $(this).height();
        if (width > max_width) {
            //Set variables for manipulation
            var ratio = (height / width );
            var new_width = max_width;
            var new_height = (new_width * ratio);

            //Shrink the image and add link to full-sized image
            $(this).height(new_height).width(new_width);
            $(this).hover(function(){
                $(this).attr("title", "This image has been scaled down.  Click to view the original image.")
                $(this).css("cursor","pointer");
            });

            $(this).click(function(){
                window.location = $(this).attr("src");
            });
        } //ends if statement
    });
});




/*
//Cufon
jQuery(document).ready(function($){Cufon.replace('',{ hover: true});});


//Make ampersands lush
$(document).ready(function() {
    $("*:contains('&')", document.body)
        .contents()
        .each(
            function() {
                if( this.nodeType == 3 ) {
                    $(this)
                        .replaceWith( this
                            .nodeValue
                            .replace( /&/g, "<cite class='amp'>&</cite>" )
                        );
                }
            }
        );
});

//Pre and ap ends
jQuery(document).ready(function($){$(".addclass").prepend('add stuff');});


//Add class
jQuery(document).ready(function($){$('').addClass("none");});

//Fade in
jQuery(document).ready(function($){$('').fadeIn(2000);});


//Open in external windows
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

//JQuery Plugin: "EqualHeights" by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com) Copyright (c) 2008 Filament Group. Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
jQuery(document).ready(function($){ 	
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	equalHeight($ ( "add stuff" ) );
	
});

*/