var $ = jQuery.noConflict();

//--------------------------------------------------------------

// Tooltip script powered by jQuery (http://www.jquery.com) written by Alen Grakalic (http://cssglobe.com)
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -20;
		yOffset = 5;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});


//--------------------------------------------------------------


//Post images max size
jQuery(document).ready(function($){ 
    //Configuration Options
    var max_width = 520; //Sets the max width, in pixels, for every image
    var selector = '.the_main_content img'; //Sets the syntax for finding the 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).attr("class", "thickbox")
                $(this).css("cursor","pointer");
            });

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


//--------------------------------------------------------------

//Tabs

//Species
$(function() { $('#species_singular #container > ul').tabs();});

//News
$(function() { $('.tabbed_tax#container > ul').tabs();});
$(function() {
	$(".tabbed_tax#container").tabs({
		event: 'mouseover',
		cache: true 
	});
});

//Homepages
$(function() { $('.tabbed_3#container > ul').tabs();});
$(function() {
	$(".tabbed_3#container").tabs({
		cache: true
	});
});



//Auto rotate - kinda bad for videos
//$(document).ready(function(){
	//$(".tabbed_3#container").tabs().tabs('rotate', 30000, true);
	//$(".tabbed_3#container").hover(
	//function() {
	//$(".tabbed_3#container").tabs("rotate",0,true);
	//},
	//function() {
	//$(".tabbed_3#container").tabs("rotate",30000,true);
	//}
	//);
//});



//--------------------------------------------------------------


//Toggles for more details
$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click
	$(".trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$(".trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("fast");
	});

});

//--------------------------------------------------------------

//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($ ( ".menu_slab.triple .slb" ) );
	
});



//--------------------------------------------------------------


//To Top
$(document).ready(function() {
	var defaults = {
		containerID: 'moccaUItoTop', // fading element id
		containerHoverClass: 'moccaUIhover', // fading element hover class
		scrollSpeed: 1200,
		easingType: 'linear' 
	};
	
	$().UItoTop({ easingType: 'easeOutQuart' });
	
});


//--------------------------------------------------------------

//Flickr
jQuery(document).ready(function($){   
	jQuery(".flickr_pictures .gallery").flickr({     
	 api_key: "908e1657847346b6d3967bb608c76ef7",
	 type: "photoset",
	 thumb_size: 's', 
	 per_page: 15,
	 photoset_id: "72157622868302306/",
	 size: "b"  
	}); 
});

jQuery(document).ready(function($){   
	jQuery(".aside.flickr .gallery.fl").flickr({     
	 api_key: "908e1657847346b6d3967bb608c76ef7",
	 type: "photoset",
	 thumb_size: 's', 
	 per_page: 21,
	 photoset_id: "72157622868302306/",
	 size: "b"  
	}); 
});

//--------------------------------------------------------------


//Horizontal Sliding
jQuery(document).ready(function($){  

$('.lead_col').hover(function(){
	$(".cover", this).stop().animate({top:'-270px'},{queue:false,duration:200});
}, function() {
	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:200});
});
});



