$(document).ready(function() {
	 Cufon.replace('h1, h2, h3, h4, #nav a, a.readmore, .toggle a', {
	 	fontFamily : 'normal',
	 	textShadow: '1px 1px rgba(0, 0, 0, 0.2)'
	 });
	 Cufon.replace('.blog h1, .blog h2, .blog h3, .blog h4, .blog #nav a, .blog a.readmore, .blog .dropcap', {
	 	fontFamily : 'Gentium',
	 	textShadow: '1px 1px rgba(0, 0, 0, 0.1)'
	 });
	  Cufon.replace('.about-author a, .about-author h3, .about-author p, .subscripe h2, .subscripe label, #ajaxContact label, form .color', {
	 	fontFamily : 'hand',
	 	textShadow: '1px 1px rgba(0, 0, 0, 0.1)'
	 });
	 $(".work .project a.thumbnail").hover(function(){
		 	$(this).fadeTo(300,0.8);
	 	},function(){
	 		$(this).fadeTo(300,1);
 	});
 	$(".toggle li a").hover(function(){
 		$(this).fadeTo(300, 0.8);
 	}, function() {
 		if($(this).hasClass('current')) {
			$(this).fadeTo(300, 1);
		} else {
			$(this).fadeTo(300, 0.3);
		}
 	});
 	$(".portfolio-item").hover(function(){
 		$("#area").stop(true, true).fadeOut("normal");
 	},function(){
 		$("#area").stop(true, true).fadeIn("normal");
 	});
 	$(".toggle li a").click(function(){
 		$(this).parent("li").siblings("li").children("a").fadeTo(300, 0.3);
 	});
	$('.filter ul a').click(function() {
		$('.filter ul .active').removeClass('active');
		$(this).parent().addClass('active');
		var filterVal = $(this).text().replace(' ','-').toLowerCase();

		if(filterVal == 'all') {
			$('.work .hidden').animate({height:"225px", opacity:"1"}, {duration:'500', easing:'easeInCubic'}).removeClass('hidden');
		} else {
			$('.work .project').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).addClass('hidden').animate({height: '0', opacity:"0"}, {duration:'500', easing:'easeOutCubic'});
				} else {
					$(this).animate({height: '225px', opacity:"1"}, {duration:'500', easing:'easeInCubic'}).removeClass('hidden');
				}
			});
		}

		return false;
	});
	$(".toggle ul").tabs(".about > .pane",{tabs: 'a',effect: 'slide'});
	$.localScroll();
	$(".blog .post:last").css("border", "0");
});
$(function() {
	// Define the height of your two background images.
           //The image to scroll
	   var backgroundheight = 1450;

	// Create a random offset for both images' starting positions
        offset = Math.round(Math.floor(Math.random()* 2001));
        offset2 = Math.round(Math.floor(Math.random()* 1001));
 
	function scrollbackground() {
                //Ensure all bases are covered when defining the offset.
   		offset = (offset < 1) ? offset + (backgroundheight - 1) : offset - 1;
		// Put the background onto the required div and animate vertically
   		$('#header').css("background-position", "50% " + offset + "px");
   		// Enable the function to loop when it reaches the end of the image
   		setTimeout(function() {
			scrollbackground();
			}, 100
		);
   	}
	// Initiate the scroll
	scrollbackground();
   	// done
   	if ($('#sidebar').length>0){
		var msie6 = $.browser == 'msie' && $.browser.version < 7;
		if (!msie6) {
		var top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('margin-top').replace(/auto/, 0));
		$(window).scroll(function (event) {
		  // what the y position of the scroll is
		  var y = $(this).scrollTop();
		  
		  // whether that's below the form
		  if (y >= top) {
			// if so, ad the fixed class
			$('#sidebar').addClass('fixed');
		  } else {
			// otherwise remove it
			$('#sidebar').removeClass('fixed');
		  }
		});
		}	
	}
});
