function showPortfolio() {
	$blogList.slideUp();
	$aboutList.slideUp();
	$portfolioList.slideDown();
}
function showBlog() {
	$portfolioList.slideUp();
	$aboutList.slideUp();
	$blogList.slideDown();
}
function showAbout() {
	$portfolioList.slideUp();
	$blogList.slideUp();
	$aboutList.slideDown();
}
function restoreNavi() {
	//if (page == 'portfolio') {
	//	$blogList.slideUp();
	//	$portfolioList.slideDown();
	//} else {
	//	$portfolioList.slideUp();
	//	$blogList.slideDown();
	//}
}
function iPhoneDial() {
		/* check for iPhone */
	var agent = navigator.userAgent.toLowerCase();
	var is_iphone = ((agent.indexOf('iphone')!=-1));
	if (is_iphone) {
	
		/* iPhone telephone number formatting */
		/* adds 'tel:' schema formatted phone number to all microformatted telephone number on the page */
		$('.tel').each(function(){
			origNo = $(this).text();
			var telNo = origNo.replace(/\(.*\)/,'').replace(/\s+/g,'');
			var wrapLink = '<a href="tel:'+telNo+'" class="tel">'+origNo+'</a>';
			$(this).replaceWith(wrapLink);
		});
	
	}
}
function submitLink() {
	text = ($('#submit').val());
	$('#submit').replaceWith('<a id="submit" href="#">'+text+'</a>');
	$('#submit').click(function(){
		$("form:first").submit();
		return false;
	});
}
function scrollAnchor() {
    function filterPath(string) {
        return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if ($(this.hash).length) {
                    $(this).click(function(event) {
                        var targetOffset = $(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        $(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}
function interact() {
	page = $('body').attr('id');
	$portfolioList = $('#portfolioList');
	$blogList = $('#blogList');
	$aboutList = $('#aboutList');
	if (page == 'blog') {
		$portfolioList.hide();
		$aboutList.hide()
	} else if (page == 'about') {
		$blogList.hide();
		$portfolioList.hide();
	} else {
		$blogList.hide();
		$aboutList.hide();
	}
	$('img', $portfolioList).css({opacity: 0.75}).hover(function() { $(this).stop().fadeTo('normal', 1); }, function() { $(this).stop().fadeTo('normal', 0.75); });
	$portfolioLink = $('#portfolioLink').hoverIntent({over: showPortfolio, out: restoreNavi, interval: 250});
	$blogLink = $('#blogLink').hoverIntent({over: showBlog, out: restoreNavi, interval: 250});
	$blogLink = $('#aboutLink').hoverIntent({over: showAbout, out: restoreNavi, interval: 250});
	iPhoneDial();
	submitLink();
	scrollAnchor();
}
$(document).ready(function() {interact();});