(function($){
  var GREENHAUS = GREENHAUS|| {};
	GREENHAUS = {
		init: function(){
  			$('.more_info, #description, .sub_page #page_nav ul li a span').hide();
			GREENHAUS.bindEvents();
    	},
		bindEvents: function(){
			$('#main_nav li').hover(function(){
				$(this).addClass('active');
			 	if($(this).children('.more_info:animated').length === 0)
					$(this).children('.more_info').fadeIn('slow');
				else{
					$(this).children('.more_info').fadeIn();
				}
			},
			function(){
				$(this).removeClass('active')
				$(this).children('.more_info').fadeOut(1000, function(){
					if($(this).parent().hasClass('active'))
						$(this).show();
				});
			});
			
			$('#home_page li.logo img').click(function(events){
				events.preventDefault();
				$('#description').show();
			});
			
			/*Sub Page JS */
			$('.sub_page #page_nav ul li a').hover(function(){
				if($(this).children('span:animated').length === 0)
					$(this).children('span').fadeIn();
			}, function(){
				$(this).children('span').fadeOut(500);
			});
			
			/*Sub nav animations on sub pages*/
			$('#more_less .more-less-link').slideUp(500);
			$('#snapshot_about .snapshot-link').slideUp(500);
			$('#greenhaus_effect .greenhaus-effect-link').slideUp(500);
			$('#folio_tour .folio-tour-link').slideUp(500);
			$('#blender .blender-link').slideUp(500);
			
			/*Capabilities page fade ins*/
			$('.capabilities-page .capabilities h2').hide();
			var h2 = $('.capabilities-page .capabilities h2').first();
			var count = $('.capabilities-page .capabilities h2').length;
			GREENHAUS.fadeInNextH2(h2, count);
			
			$('#portfolio_wrap a').hover(function(){
					var $this = $(this),
							$img = $this.children('img'),
							titleVal = $img.attr('title'),
							$clientNamesH3 = $('#client_names h3');
							$clientNamesH3.text(titleVal);
				},
				function(){
				}
			);
			
			$('#project_wrap .client_info .thumbs img').not('.video_thumb img').click( function(e){
					var $this = $(this),
							relVal = $this.attr('rel');
					$('.thumbs img').removeClass('active');
					$this.addClass('active');
					$('#full_size_img img').fadeOut( function(){
						var $this = $(this);
						$this.attr('src', relVal);
						$this.delay(1000).fadeIn();
					});
			});

			$('#project_wrap .thumbs a').click( function(e){
				e.preventDefault();
			});

			$('#project_wrap .client_info .thumbs img').hover( function(e){
					var $this = $(this),
  						altVal = $this.attr('alt');
					$('#thumb_type').text(altVal);
			}, function(){
					$('#thumb_type').text('');
			});
			
			$('#project_wrap .client_info #project_videos img').hover( function(e){
					var $this = $(this),
  						altVal = $this.attr('alt');
					$('#video_type').text(altVal);
			}, function(){
					$('#video_type').text('');
			});
			
			$('#project_wrap a.video_thumb').click( function(e){
				e.preventDefault();
				e.stopPropagation();
				var $this = $(this),
						$img = $this.find('img'),
  					relVal = $img.attr('rel'),
						thumbVal = $img.attr('src'),
						$param = $('.vjs-flash-fallback param[name="flashvars"]'),
						$modalContain = $('#modal_contain'),
						movieConfig = "config={'playlist':['" + thumbVal + "', {'url': '" + relVal + "','autoPlay':true, 'autoBuffering':true}]}",
						params = "{allowfullscreen: true}",
						attributes = {};
						swfobject.embedSWF("/includes/flowplayer-3.2.7.swf", "video", "640", "480", "9.0.0", null, {config: "{'clip': '" + relVal + "', 'autoPlay': false}"}, params, attributes);
						
						//$('#poster_image').attr('src', thumbVal);
						$modalContain.width($(window).width());
						$modalContain.height($(window).height());
						$modalContain.fadeIn();
						$('#close_wdw, #modal_contain').click(function(e){
							e.preventDefault();
							$modalContain.find('object').remove();
							$modalContain.find('#video_contain').append('<div id="video"></div>');
							$modalContain.fadeOut();
						});
						$('#video_contain').click(function(e){
							e.stopPropagation();
						});
			});
		},
		fadeInNextH2: function(h2, count){
			count = count-1;
			$(h2).fadeIn('slow');
			if(count > 0){
				setTimeout(function(){
					GREENHAUS.fadeInNextH2($(h2).next(), count);
				}, 1000);
			}
		}
  };

  window.GREENHAUS= GREENHAUS;
  $(document).ready(GREENHAUS.init);	
})(jQuery);
