jQuery.fn.stripTags = function() { return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); };

$(document).ready(function() {

	//masthead and footer scrolling
	var xAdd = 0;
	var scrollInterval = setInterval(function(){
		xAdd++;
		$('.dynamic').css('background-position',xAdd + 'px bottom');
		$('#contact_panel_wrapper').css('background-position',xAdd + 'px bottom');
	},100);

	//lightbox initialize
	$('.project > a').lightBox();
	
	//Clean up Twitter RSS output
	$('#about_twitter h3 > a > span').stripTags();
	
	//Header Nav
	$(window).scroll(function() {
		if ($(this).scrollTop() >= $("#divider_masthead").offset().top) {
			$("#header").css("background-image" , "url(img/bg_nav.png)").css("height" , "92px");
			$("#header_nav:hidden").show();
		}
		else {
			$("#header_nav:visible").hide();
			$("#header").css("background-image" , "none").css("height" , "0");
		}
	});

	// Contact Panel Toggle	
	$('#contact_open').click( function() {
		$('#contact_open').hide();
		$('#contact_close').css('display' , 'block');
		$('#contact_panel_wrapper').slideDown('slow');
	});
	$('#contact_close').click( function() {
		$('#contact_panel_wrapper').slideUp('slow');
		$('#contact_close').css('display' , 'none');
		$('#contact_open').show();
	});
	
	//Scroll Effects
	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 $target = $(this.hash), 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;
					});
				});
			}
		}
	});
	
	// Portfolio Project Detail Text
	$('.project a').hover( function() {
		$(this).find('.project_hover p').stop().animate({marginTop: '20px'}, 500);
	}, function() {
		$(this).find('.project_hover p').stop().animate({marginTop: '175px'}, 500);
	});

	// Jribbble
	$.jribbble.getShotsByPlayerId('WillPhillips', function (playerShots) {
		var html = [];

		$.each(playerShots.shots, function (i, shot) {
			html.push('<div class="project drib_shot"><a href="' + shot.url + '" title="View this Shot on Dribbble."><div class="project_image">');
			html.push('<img src="' + shot.image_teaser_url + '" height="130" width="89" border="0" /><div class="project_hover"></div></div></a></div>');
		});

		$('#drib_shot_wrapper').html(html.join(''));
	}, {page: 1, per_page: 6});
	
	// 		<div class="project drib_shot">
	//		<a href="" title="View this Shot on Dribbble.">
	//			<div class="project_image">
	//				<img src="http://dribbble.com/system/users/3146/screenshots/424078/bwp_2.jpg" height="130" width="89" border="0" />
	//				<div class="project_hover"></div>
	//			</div>
	//		</a>
	//		</div>

});

