$(document).ready(function(){
						   
	 // Navigation smooth fade effects. Note relies upon jQuery which needs to be pre-included. 
	var wp_caption= $("input#rascals-wp-caption").val();
	
	if (wp_caption==1) {	

    //var
    var x = 20;
    var y = -20;
    var toolTip_text_width = 300;
	
    $('a:not(div#nav-content a)').each(function() {
	var caption = $(this).attr("title").length; 
		if (caption!=0 ) {	
			 $(this).addClass('wp-caption');
			 } 
	 });
	
	
    $(".wp-caption").hover(function(e){
        this.toolTip_text = this.title;
        this.title = "";
		this.image_title = $(this).find("img").attr("title");
		$(this).find("img").attr("title","");
		this.image_alt = $(this).find("img").attr("alt");
		$(this).find("img").attr("alt","");
		
		
        if (this.toolTip_text) {
            var t = "<p>" + this.toolTip_text + "</p>";
        }
        else {
            var t = "";
        }
        if (this.rel) {
            $("body").append("<div id='wp-caption'><img src='" + this.rel + "' alt='' />" + t + "</div>");	
        }
        else {
        
            $("body").append("<div id='wp-caption'>" + t + "</div>");
            $("#wp-caption p").css("padding", "0");
            if ($("#wp-caption p").text().length >= 40) {
                $("#wp-caption p").css("width", toolTip_text_width + "px");
            } else {
 		$("#wp-caption p").css("width", $('#wp-caption').width() + "px");

		}
            
        }
        
        $("#wp-caption").css("top", (e.pageY - y) + "px").css("left", (e.pageX + x) + "px").slideDown(400);

    }, function(){
        this.title = this.toolTip_text;
		$(this).find("img").attr("alt",this.image_alt);
		$(this).find("img").attr("title",this.image_title);
        $("#wp-caption").remove();
    });
   
    
    $(".wp-caption").mousemove(function(e){
        $("#wp-caption").css("top", (e.pageY - y) + "px").css("left", (e.pageX + x) + "px");
		var toolTip_image_width = $("#wp-caption").width();
        var window_width = $(window).width();
        if (e.pageX + $("#wp-caption").width() >= window_width - 40 - x) {
        var toolTip_width = toolTip_image_width+40;
        $("#wp-caption").css("top", (e.pageY - y) + "px").css("left", window_width - toolTip_width+ "px");
        }
    });
    
} //end if
	
	
    //RASCALS "FADE" MENU
    
    //var
    $("ul#nav li a").before("<span></span>");
    
    $("ul#nav li:last-child").find("ul li ul").css("left", "-100%")
    
    $("ul#nav li").not(".current_page_item").find("span").css("opacity", "0");
    
    $("ul#nav li").hover(function(){
        $(this).find('ul:first').css("display", "none").slideDown("400").css({
            "visibility": "visible"
        });
        
        $(this).find("span:first").stop().animate({
            opacity: 1
        }, 300);
        
    }, function(){
        $(this).find('ul:first').css({
            "visibility": "hidden"
        });
        
        $(this).not(".current_page_item").find("span:first").animate({
            opacity: 0
        }, 300);
        
    });
    
   

})


