
// sIFR3
var boton = { src: './js/boton.swf' };
sIFR.activate(boton);
sIFR.replace(boton, {
  selector: 'h2',
  css: '.sIFR-root { background-color: transparent; color: #FFFFFF; }',
  wmode: 'transparent'
});
sIFR.replace(boton, {
  selector: 'h3',
  css: '.sIFR-root { font-size:24px; background-color: transparent; color: #FFFFFF; }',
  wmode: 'transparent'
});

sIFR.replace(boton, {
  selector: 'h4.title',
  css: '.sIFR-root { font-size:17px; background-color: transparent; color: #CCCCCC; }',
  wmode: 'transparent'
});
sIFR.replace(boton, {
  selector: 'h4',
  css: '.sIFR-root { font-size:20px; background-color: transparent; color: #FFFFFF; }',
  wmode: 'transparent'
});




$(document).ready(function () {
	//setHeight();
	
	
	// Smooth scrolling
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	$('a[href*=#]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) {
			var hashname = this.hash.replace(/#/,'');
			var $target = $("a[name='" +hashname+ "']").next(), target = this.hash;
			if (target) {
				var targetOffset = $target.offset().top;
				$(this).click(function(event) {
					event.preventDefault();
					$('html, body').animate({scrollTop: targetOffset}, 400, function() {
						location.hash = target;
					});
				});
			}
		}
	});
	
	
	// read more functionality
	$('div div.detail').hide(); 
	$('div div.detail').before('<a href="#" class="more">Read more</a>');
	$('div a.more').click(function(event) {
		event.preventDefault();
		$('div a.more:hidden').show();
		$('div div.detail:visible').hide();
		$(this).hide();
		var targetOffset = $(this).parent().offset().top;
		$('html, body').animate({scrollTop: targetOffset}, 'slow');
		$(this).next().fadeIn('slow', function() {
			sIFR.replace(boton, {
			  selector: 'h4',
			  css: '.sIFR-root { font-size:20px; background-color: transparent; color: #FFFFFF; }',
			  wmode: 'transparent'
			});
			
		});
	}).next().hide();
	
	// check for hashtag in url
	if (location.hash) { 
		var hashname = location.hash.replace(/#/,'');
		var $anchor = $("a[name='" +hashname+ "']");
		
		// check to see if anchor exists, if it does then open container and hide read more link
		if ($anchor) {
			$anchor.parent().show().prev('a.more').hide();
			var targetOffset = $anchor.offset().top;
			$('html, body').animate({scrollTop: targetOffset}, 'slow');
		}
	}
	

	$('span.email').emailShow();
	
	
});

    
// email obfuscation
$.fn.emailShow = function() {
    var at = / at /;
    var dot = / dot /g;
    this.each( function() {
        var addr = $(this).text().replace(at,"@").replace(dot,".");
        var title = $(this).attr('title')
        $(this)
            .after('<a class="email" href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
            .remove();
    });
};


// set container height to window, not using this right now
function setHeight() {
	var targetHeight = $(window).height();
	var padding = parseInt($('#mainContent').css('padding-top'));
	padding += parseInt($('#mainContent').css('padding-bottom'));
	targetHeight -= 50;
	$('#mainContent').css('min-height', targetHeight);
}

