Cufon.replace('h2');

$.fn.noSpam = function() {
	var at = '@';
	return this.each(function(){
		var e = null;
		$(this).find('span').replaceWith(at);
		e = $(this).text();
		$(this).attr('href', 'mailto:' + e);
	});
};

$.fn.topLink=function(settings){
	settings=$.extend({min:1,fadeSpeed:200,scrollSpeed:1000,topPos:0,ieOffset:50},settings);
	return this.each(function(){
		var el=$(this);
		$(window).scroll(function(){
			if(!jQuery.support.hrefNormalized)el.css({'position':'absolute','top':$(window).scrollTop()+$(window).height()-settings.ieOffset}); //ie 6 fix
			if($(window).scrollTop()>=settings.min)el.fadeIn(settings.fadeSpeed);
			else el.fadeOut(settings.fadeSpeed);
		});
		el.click(function(){
			$('html,body').animate({scrollTop:settings.topPos},settings.scrollSpeed);
			return false;
		});
	});
};


function slideSwitch() {
	var ct = $('#slideshow > *').length;
    var $active = $('#slideshow li.active');
    if ( $active.length == 0 ) $active = $('#slideshow li:last');
    var $next =  $active.next().length ? $active.next() : $('#slideshow li:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function accordion() {
	var hash = location.hash;
	hash = hash.replace(/^.*#/, '');
	if (hash == "") {
		$("dt a:not(:first)").each(function(){$(this).addClass("close");});
		$("dt a:first").addClass("open");
		$("dd:not(:first)").hide();
	}
	else {
		$("dt a").addClass("close");
		$("dd").hide();
		$("dt a").each(function(){
			if($(this).attr('href').indexOf(hash) > -1) {
				$(this).removeClass().addClass("open");
				$(this).parent().next("dd").show();
				return false;
			}
		});
	}
	$("dt a").click(function(){
		$("dt a").removeClass().addClass("close");
		$(this).addClass("open");
		$("dd:visible").toggle();
		$(this).parent().next().toggle();
		return false;
	});
}


$(document).ready(function() {
	$("a[rel='lightbox']").fancybox();
	$('a.email').noSpam();
	$('a.scrollToTop').topLink();
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
		$(this).attr('target','_blank');
	});
});

