$(document).ready(function(){
	function windowwidth() {
		if($(window).width() < 1080) {
			$('header').css({'width':960});
			$('#image').addClass('min');
			$('#thumbs').css({'right':-10});;
			$('#portfolio').css({'width':960});
			$('#portfolio li a').css({'width':159, 'height':159});
		} else {
			$('header').css({'width':1060});
			$('#image').removeClass('min');
			$('#thumbs').css({'right':-60});
			$('#portfolio').css({'width':1062});
			$('#portfolio li a').css({'width':176, 'height':176});
		}
		
		if($(window).width() < 1300) {		
			$('#footer-logo').addClass('small');
		} else {
			$('#footer-logo').removeClass('small');
		}
	}
	function windowheight() {
		if($(window).height() < 699 && (($(window).height() + $(window).scrollTop()) < 699)) {
			$('footer').addClass('stuck');
		} else {
			$('footer').removeClass('stuck');
		}
	}
	windowheight();
	windowwidth();
	$(window).scroll(function () {
		windowheight();
	});
	$(window).resize(function() {
		windowheight();
		windowwidth();
	});
	//Fix for Active States
	if ($('#image').hasClass('project')) {
		$('.menu-item-22').addClass('current-menu-item');
	}
	if ($('#image').hasClass('testimonial')) {
		$('.menu-item-21').addClass('current-menu-item');
	}
	
	
	$('#portfolio').hoverIntent(function(){
	},function(){
		$('#portfolio li img').animate({'opacity':1}, 400);
	});
	
	$('#portfolio li').hoverIntent(function(){
		$(this).find('span').fadeIn(400);
		$(this).find('img').animate({'opacity':1}, 400);
		$('#portfolio li').not(this).find('img').animate({'opacity':.5}, 400);
	}, function(){
		$(this).removeClass().find('span').fadeOut(400);
	});

	$('#main-content').columnize({ columns: 2 });

	//Cycle for Hero Images
		$('#image').cycle({ 
				fx: 'fade',
				speed: 2000,
				timeout: 4000,
				height: '418px',
				width: '1060px',
				fit: 1
		});
	//Cycle for Project Images
	if($('#image.project').children().length > 1) {
		$('#image.project').after('<span class="prev"></span><span class="next"></span><div id="thumbnails"></div>');
		$('#image.project').cycle({ 
				fx: 'fade',
				speed: 2000,
				timeout: 4000,
				prev: $(this).find('.prev'),
				next: $(this).find('.next'),
			    pager: '#thumbnails',
			    pagerAnchorBuilder: function(idx, slide) { 
			        return '<a href="#"><img src="' + slide.src + '" height="54" /></a>'; 
			    }
		});
	}	
	$('#project-holder').hoverIntent(function(){
		$('.prev, .next').fadeIn();
	}, function() {
		$('.prev, .next').fadeOut();
	});
	
	$('.prev, .next').hoverIntent(function(){
		$(this).animate({'opacity':.75},{duration: 600, easing: 'easeOutExpo'});
	}, function() {
		$(this).animate({'opacity':1},{duration: 600, easing: 'easeOutExpo'});
	});

	//Sticky Sidebar 
	$(window).scroll(function() {  
		if(!$('#news-media').length < '1') {
			if ($(window).scrollTop() > $('#side-panel').offset().top) {
				$('#categories').addClass('fixed');
			} else {
				$('#categories').removeClass('fixed');		
			}
		}
	});
	//Form Other option
	$('select#hear').change(function() {
		if ($("select option:selected").attr('value') == 'Other') {
			$('.other').fadeIn().find('input').focus();
		} else {
			$('.other').fadeOut();
	
		}
	});
	$('input#all').change(function() {
		if(!$(this).hasClass('selected')) {
			$(this).addClass('selected');
			$('.check input').not('#all, :checked').click();
		} else {
			$(this).removeClass('selected');
			$('.check input:checked').not('#all').click();
		}
	});
	$(".contactForm").validate();
	
	//Intro Animation
	if($('#intro').length > "0") {
		$('body').css({'overflow':'hidden'});
		
		$('#logoint').css({'left':$(window).width()/2-300, 'top':$(window).height()/2-200});
		$('#subtext').css({'opacity':1,'display':'block','left':$(window).width(),'top':$(window).height()/2+44})
		$('#subtext').delay(2500).animate({'left':$(window).width()/2-12},1000,'easeInOutBack');
		$('#subtext').delay(200).fadeOut(100,function(){
			$('#intro').delay(800).fadeOut(1000, function(){
				$('#logoint').remove();
				$('body').css({'overflow':'auto'});
				$('footer').append('<div id="slogan"></div>');
				swfobject.embedSWF("/wp-content/themes/impressions/js/boutiqueslogan.swf", "slogan", "500", "100", "9.0.0", "/wp-content/themes/impressions/js/expressInstall.swf", flashvars, params, attributes);
			});
		});
	}	
	
	//Animating nav hover
	$('nav').append('<div class="navactive" />');
	$('.current-menu-item,.current-menu-ancestor').addClass('currentpage');
	$('.navactive').css({'left':$('.currentpage').offset().left - $('header').offset().left + (($('.currentpage').width() - $('.navactive').width())/2)});
	$('nav li').hoverIntent(function(){
		$('.navactive').animate({'left':$(this).offset().left - $('header').offset().left + (($(this).width() - $('.navactive').width())/2)})
	},function(){
	});

	$('#subnav li:last').addClass('last');
	
	if($('#subnav li.current_page_item').length > 0) {
		$('#subnav').append('<li id="line"></li>');
		$('#line').css({'left':$('#subnav li.current_page_item').offset().left - $('#subnav').offset().left + (($('#subnav li.current_page_item').width() - $('#line').width())/2)});
		$('#subnav li').hoverIntent(function(){
			$('#line').animate({'left':$(this).offset().left - $('#subnav').offset().left + (($(this).width() - $('#line').width())/2)})
		},function(){
		});
	}
	
	$('#portfolio img, #image img').attr('title','');
});
