jQuery(document).ready(function(){

	//Sidebar Accordion Menu:

	jQuery(".sub-level-0 ul").hide(); // Hide all sub menus
	jQuery("ul#nav-sub li.here").parent().show(); // Slide down the current menu item's sub menu
	jQuery("ul#nav-sub li.here ul").show(); // Slide down the current menu item's sub menu if its a parent

	jQuery(".sub-level-0 ul").parent().find(":first").click( // When a top menu item that has a sub-nav is clicked...
		function () {
			jQuery(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
			jQuery(this).next().slideToggle("normal"); // Slide down the clicked sub menu
			return false;
		}
	);


    // Alternating table rows:
	jQuery('tbody tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows


	// FancyBox IFrame
	jQuery("a.fancyboxIframe").fancybox({
		autoScale		: false,
		'width'			: '70%',
		'height'		: '90%',
		'type'			: 'iframe'
	});

	// FancyBox
	jQuery("a.fancyboxImage").fancybox({
		autoScale		: false,
		titlePosition	: 'outside'
	});
	
	
   // Greyscale swap
   jQuery("img.grey-swap")
        .mouseover(function() {
            var src = jQuery(this).attr("src").replace("greyscale", "color");
            jQuery(this).attr("src", src);
			jQuery(this).parent().parent().parent().find("h2 a").addClass("hover");
        })
        .mouseout(function() {
            var src = jQuery(this).attr("src").replace("color.", "greyscale.");
            jQuery(this).attr("src", src);
			jQuery(this).parent().parent().parent().find("h2 a").removeClass("hover");
        });

	jQuery(".grid_3_half h2")
        .mouseover(function() {
            var src = jQuery(this).parent().find(".grey-swap").attr("src").replace("greyscale", "color");
            jQuery(this).parent().find(".grey-swap").attr("src", src);
        })
        .mouseout(function() {
            var src = jQuery(this).parent().find(".grey-swap").attr("src").replace("color.", "greyscale.");
            jQuery(this).parent().find(".grey-swap").attr("src", src);
        });

	jQuery('.fadeSlideShow').cycle({
		speed: 'slow',
		timeout: 0,
		next: '#next2',
		prev: '#prev2',
		before: getHeightTitleDownload
	});

	// gets height of image and makes the slideshow container the same size
	function getHeightTitleDownload() { 
		jQuery('.fadeSlideShow').css("height",this.height); // adjust height of container to prevent clipping
		jQuery('#image-caption').html(this.alt); // set the caption of the picture
		if (this.id != "") { // setup the hi-res download link 
			jQuery('#image-download').html('<a target="_blank" href="' + this.id + '">Download this image in high resolution</a>');
		} else {
			jQuery('#image-download').html("");
		}
	};

	jQuery('.homepageSlideShow').cycle({
		speed: 'slow',
		timeout: 6000,
		next: '#next2',
		prev: '#prev2'
	});


	jQuery().ready(function() {
		jQuery('.kwicks').kwicks({
			min : 65,
			spacing : 1,
			isVertical : true,
			duration : 500
		});
	});


	var searchBox2Default = "Search";

	//Effects for both searchbox
	jQuery("#keywords").focus(function(e){
		jQuery(this).addClass("active");
	});
	jQuery("#keywords").blur(function(e){
		jQuery(this).removeClass("active");
	});

	//Searchbox2 show/hide default text if needed
	jQuery("#keywords").focus(function(){
		if(jQuery(this).attr("value") == searchBox2Default) jQuery(this).attr("value", "");
	});
	jQuery("#keywords").blur(function(){
		if(jQuery(this).attr("value") == "") jQuery(this).attr("value", searchBox2Default);
	});


});

