// ------------------------------------------------------------------------

/**
 * Fairhaven Spam Protected Mailto Link
 *
 * Create a spam-protected mailto link written in Javascript
 *
 */
function safe_mail (part1, part2, text, aclass) {
	seperator = '@';
	complete = part1 + seperator + part2;
	if (text.substring(0,4) == 'IMG-') {
		path = '<img src="' + text.substring(4, text.length) + '" border="0" alt="Send Email" />';
		text = path;
	}
	if (text.length == 0) {
		text = complete;
	}
	document.write ('<a href="mailto:' + complete + '"');
	if (aclass.length > 0) {
		document.write(' class="' + aclass + '"');
	}
	document.write ('>' + text + '</a>');
}


// ------------------------------------------------------------------------

/**
 *
 * Controls the open/close of the navigation and related links
 *
 */

var toggled=false;
var section = '';

$(document).ready(function(){
	
	/*
	Initialize the menu as closed
	
	if (section) {
		$('#nav > li ~ ul:not(#'+section+')').css({'display' : 'none'});
	} else {
		$('#nav > ul').css({'display' : 'none'});
	}*/
	
	/*
	Controls navigation menu toggling
	
	$("#nav > li").click(function(){
		if ($(this).next().is('ul')) {
			$(this).next().slideToggle("fast");	
		}
	});*/
	
	show_text = "[+] Show Details";
	hide_text = "[-] Hide Details";
	$("a.show_hide").html(show_text);
	$("a.show_hide").show();
	$(".show_hide_content").hide();
	$("a.show_hide").click(function(){
		
		if ($(this).next().is('.show_hide_content')) {
			$(this).nextAll(".show_hide_content:first").slideToggle();
		} else {
			$(this).parent().nextAll(".show_hide_content:first").slideToggle();
		}
		
		if($(this).html() == show_text) {
			$(this).html(hide_text);
		} else {
			$(this).html(show_text);
		}
		
	});
	
	
	
	
	if (section) {
		$('#nav .submenu:not(#'+section+')').hide();
	} else {
		$(".submenu").hide();
	}
	
	$("ul#nav div p").click(function(){
	
			if($(this).is(".active")) {
			    $(this).toggleClass("active");
			    $(this).parent().next(".submenu").slideToggle();
			    return false;
			} else {
				/*
				$(".submenu:visible").slideUp("slow"); // close all visible divs with the class of .content
								$("p.active").removeClass("active");  // remove the class active from all p's with the class of .active*/
				
				$(this).toggleClass("active");
				$(this).parent().next(".submenu").slideToggle();
				return false;
			}
	
	});
	
	
	
	//Execute the slideShow
	slideShow();
	
});



// ------------------------------------------------------------------------

/**
 *
 * Fixes CSS for browsers that have Java ENABLED
 *
 */
function java_warning() {
	document.getElementById('no_js').className = 'js_enabled';
	document.getElementById('wrapper').className = 'no_top_margin';
}





function slideShow() {

	$('#thumbs img').before('<div></div>');

	//Set the opacity of all images to 0
	$('#slides div').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#slides div:first').css({opacity: 1.0});
	$('#slideshow #thumbs a:first div').addClass('selected');
		
	//Call the gallery function to run the slideshow, and the time between slide changes (milliseconds)
	setInterval('slides()', 6000);
	
}


function slides() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#slides div.show') ?  $('#slides div.show') : $('#slides div:first'));
	var currentThumb = ($('#thumbs div.selected') ?  $('#thumbs div.selected') : $('#thumbs a:first div'));
	var currentText = ($('#text div.show') ?  $('#text div.show') : $('#text div:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = (current.next().length ? current.next() : $('#slides div:first'));
	var nextThumb = (current.next().length ? $('#thumbs div.selected ').parent().next().children('div') : $('#thumbs a:first div'));
	var nextText = (currentText.next().length ? currentText.next() : $('#text div:first'));
	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
	
	
	//Switch the selected class on the thumbs	
	currentThumb.removeClass('selected');
	nextThumb.addClass('selected');
		
	
	//Set the fade in effect for the next image, show class has higher z-index
	nextText.addClass('show');
	currentText.removeClass('show');
		
}





