function DESemail(emailname,emailserver) {
	document.write("<a href='mailto:" + emailname + "@" + emailserver +"'>");
	document.write(emailname + "@" + emailserver); 
	document.write("</a>"); 
}

// Accessible Pop Ups
function DESopen(url,width,height,toolbar,scroll) {
	window.open(url, "", "scrollbars="+scroll+",toolbar="+toolbar+",height="+ height +",width="+width);
	return false;
}



$(document).ready(function(){
   
	// Main Navigation Dropdown */
   $("#nav_wrap li").hoverIntent(
		function() {
			$(this).find("a:first").addClass("open");
			$(this).find("ul:first").show("fast");
		},
		function() {
			$(this).find("a:first").removeClass("open");
			$(this).find("ul:first").hide("fast"); 
		}
	);
	
	$('#slide_show').cycle({
		fx:     'fade', 
	   delay:    -4000,
      cssBefore: { opacity: 1 },
      animOut:   { opacity: 0 }

	});
	
	$('#pause').click(function() { $('#folio_slide').cycle('pause'); return false; });
    $('#play').click(function() { $('#folio_slide').cycle('resume'); return false; });
    
    $('#viewer').hover(
        function() { $('#controls').show(); },
        function() { $('#controls').hide(); }
    );



	$('#folio_slide').cycle({
		fx:     'fade',
		sync:		false,
		speed:    1000,
		//delay:    -2000,
      //cssBefore: { opacity: 1 },
      //animOut:   { opacity: 0 }
	   timeout: 5000,
      pager:  '#folio_thumbs', 
	   pagerAnchorBuilder: function(idx, slide) { 
	       // return selector string for existing anchor 
	       return '#folio_thumbs li:eq(' + idx + ') a'; 
	   },
	   next:   '#next',
      prev:   '#prev'


	});
	
	$('#play').css("display","none");
	
	$('#play').click(function() {
	
		$('#play').hide();
		$('#pause').show();  
	});
	
	$('#pause').click(function() {
	
		$('#play').show();
		$('#pause').hide();  
	});
	
	$('#folio_thumbs li a').click(function() {
		$('#folio_slide').cycle('pause'); 
		$('#play').show();
		$('#pause').hide();  
	});
	
	// --------------------------------
	// Thumbnail Image Gallery
	// --------------------------------
	
	
	
	$("#pimages a").click(function() {
		
		$("#pimages a").removeClass("current"); // remove all current classes
		$(this).addClass("current"); // add a current class to specific thumb
		
		// hide the picture div
		$("#viewer_pic").css("display","none");
		
		// add a spinner
		$("#viewer_pic").after('<img src="/img/design/spinner.gif" width="32" height="32" id="folio_spinner" />');
		
		// random number
		var randomnumber=Math.floor(Math.random()*150)
		
		// src from thumb link
		var newSrc = $(this).get(0).href;
		
		/*
			Add a random number to image to make browser load again
			Ensures .onload works in IE/Opera
			Rubbish hack, would like to improve
		*/
		var newSrc = ''+newSrc+'?ran='+randomnumber+'';
		
		// create a new image
		var newPic = document.createElement('img');
		$(newPic).attr("src",newSrc);

		// if new image has loaded
		newPic.onload = function() {
			$("#viewer_pic").html(newPic); // add the new image html
			$("#folio_spinner").remove(); // remove the spinner
			$("#viewer_pic").fadeIn("fast"); // fade in the pic
		}
		
		return false;
	});

}); // End jQuery

