/*
	Name: Main JavaScript
	Description: Main JavaScript for joshgerdes.com
	Author: Josh Gerdes
	Author URI: http://joshgerdes.com
*/
$(document).ready(function() {
	// Check for IE7 and just switch to rollover (due to IE7 bug with transparent PNG fade with JS)
	if($.browser.msie && $.browser.version.substr(0,1) == 7) {
		// Setup image rollovers
		$('.crossfade img[data-hover]').hover(function() {
			$(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp');
		}).each(function() {
			$('<img />').attr('src', $(this).attr('data-hover'));
		});
	}
	else {
		// Setup cross-fade image rollovers
		$('.crossfade').css('position', 'relative');
		$('.crossfade img[data-hover]').each(function(i,e){
			$(e)
			.css({
				"position" : "absolute",
				"opacity" : 1,
				"display" : "block"
			})
			.after(
				$('<img />')
				.attr('src', $(e).attr('data-hover'))
				.css({
					"position" : "absolute",
					"opacity" : 0,
					"display" : "block"
				})
			);
		});
		
		$('.crossfade').hover(function(){
			$(this).children('img[data-hover]').fadeTo(400,0);
			$(this).children('img:not([data-hover])').fadeTo(400,1);
		}, function(){
			$(this).children('img[data-hover]').fadeTo(400,1);
			$(this).children('img:not([data-hover])').fadeTo(400,0);
		});
	}
	
	// Add rollover color to work section
	$('#work').hover(function(){
		$(this).stop().animate({backgroundColor: '#C9DE55'}, 400);
	}, function(){
		$(this).stop().animate({backgroundColor: '#2D2D2D'}, 400);
	});
});
