jQuery(window).load(function() {

	/* Init Functions */
	initFeaturedWorkHover();
	initFeaturedWorkAnim();
	initEvents();			
			
	/* Featured Work */
	function initFeaturedWorkHover() {
		var projects = jQuery('#featured-work li a.tall');
		projects.hover(
			function () { 
				jQuery(this).children('.hover').removeClass('offscreen'); 
			}, 
			function () { 
				jQuery(this).children('.hover').addClass('offscreen');
			}
		);

	};

	function initFeaturedWorkAnim() {
		var project = jQuery('#featured-work li a.tall');
		var projectTxt = project.children('.hover');

		project.children('.hover').css({left: '0px'})
		project.children().children('.hover-bg').fadeTo(1, 0.0)
		project.children().children('.hover-content').css({left: '-300px'})

		project.hover(
			function () {
				jQuery(this).children().children('.hover-content').css({left: '-260px'});
				jQuery(this).children().children('.hover-bg').stop().fadeTo(600, 1);
				jQuery(this).children().children('.hover-content').stop().animate({left: '0px'} , { queue: false, duration: 450, easing: 'easeOutQuint' });
			}, 
			function () {
				jQuery(this).children().children('.hover-bg').stop().fadeTo(800 , 0.0);
				jQuery(this).children().children('.hover-content').stop().animate({left: '300px'} , { queue: false, duration: 300, easing: 'easeOutQuint' });
			}
		);
	};
	
	function initSlideBox() {

		jQuery(window).scroll(function(){
			
			var distanceTop = jQuery('#slideboxplacer').offset().top - jQuery(window).height();

			if  (jQuery(window).scrollTop() > distanceTop)
				jQuery('#slidebox').animate({'right':'0px'},300);
			else
				jQuery('#slidebox').stop(true).animate({'right':'-430px'},100);	
		});

		/* remove the slidebox when clicking the cross */
		jQuery('#slidebox .close').bind('click',function(){
			jQuery(this).parent().remove();
		});
	};
	
	function initEvents() {

		/* Dropdown Navigation */
		jQuery('div.menu ul.children').hide();
		jQuery('div.menu ul li').hover(function(){
			jQuery(this).find('ul.children').fadeIn('fast');
		},
		function(){
			jQuery(this).find('ul.children').fadeOut('fast');
		})
				
		/* Preloader */
		jQuery("div#featured-work").preloader2();
		jQuery("div.showcase").preloader2();
		jQuery("ul.row").preloader2();
		
		/* Pretty Photo */
		jQuery("a.modal").attr('rel','gallery[modal]');
		jQuery("a.modal").prettyPhoto({animationSpeed:'normal',theme:'pp_default', show_title : false});

		/* Image Over */
		jQuery('div.showcase img').css({ opacity: 1 });
		jQuery('div.showcase img').hover(function(){
		    jQuery(this).stop().animate({ opacity: .7 }, 250);
		}, function(){
		    jQuery(this).stop().animate({ opacity: 1 }, 350);
		});
		
		/* IE FIX */
		jQuery("div#featured-work ul li.project:nth-child(3n)").css("margin-right", "0px");
		jQuery("div.post ul.row li:nth-child(3n)").css("margin-right", "0px");
		
	};
})
