$(document).ready(function() {
//	$('#content').css('visibility','visible').css( {opacity: ".4"} );
//	$('#content.interior').css('visibility','visible');
	$("#good_news p a").addClass("external").attr( { target: "_blank" } );
	$("#trad_container").hide();
	$("#trad_information").css( {opacity: "1"} );
	$("#good_news p").hide();
	$("ul#notes_overlay li").css( { opacity :'0.75' } );
	$("good_news").delay(500, function() {
		$(this).animate( { 'min-width': '150px' }, 200 );
	});
	$("p#credits").hide().css( { opacity: "0" } );
	
	$("p#more_info").hoverIntent (
		function() {
			$("p#credits").animate( { opacity: "1" }, 200).show();
		},
		function() {
			$("p#credits").stop();
		}
	);
	
	$("a.more_info-close").click (
		function() {
			$("p#credits").animate( { opacity: "0" }, 200).hide();
		}
	);
	
	$("li.planterade_trad").click (
		function() {
			$("#trad_container").animate( { opacity: '0.97'}, 300 ).fadeIn(300);
		}
	);
	
	$("#trad_container a#close").click (
		function() {
			$('#trad_container').animate( { opacity: '0'}, 300 ).hide(300);
		});
			
	//	N A V  H O V E R  S T A T E S

	$("a.primary_navigation.projects").hoverIntent (
		function() {
			$(this).animate( { backgroundColor: '#F8DA00' }, 50 );

		},
		function() {
			$(this).animate( { backgroundColor: '#BDF0FF' }, 200 );
		}
	);
	
	$("a.primary_navigation.about").hoverIntent (
		function() {
			$(this).animate( { backgroundColor: '#F8DA00' }, 50 );
                                                           
		},                                                 
		function() {                                       
			$(this).animate( { backgroundColor: '#D7F5FF' }, 200 );
		}
	);
	
	$("a.primary_navigation.case_study").hoverIntent (
		function() {
			$(this).animate( { backgroundColor: '#F8DA00' }, 50 );
                                                           
		},                                                 
		function() {                                       
			$(this).animate( { backgroundColor: '#E0F4FF' }, 200 );
		}
	);
	
	$("a.primary_navigation.blog").hoverIntent (
		function() {
			$(this).animate( { backgroundColor: '#F8DA00' }, 50 );
                                                           
		},                                                 
		function() {                                       
			$(this).animate( { backgroundColor: '#EEFCFF' }, 200 );
		}
	);
	
	// Hides menu which otherwise shows when using back button after using tertiary nav
	
	$("ul#navigation a").click (
		function() {
			$("ul.tertiary li.inactive").hide();
		}
	);
	
	$("li.has_tertiary").hoverIntent (
		function() {
			$(this).find("li.inactive").fadeIn(200);

		},
		function() {
			$(this).find("li.inactive").slideUp(300);
		}
	);	
	
	$("li.has_tertiary").click (
		function() {
			$(this).find("li.inactive").show();
		}
	);
	
	$("#bottom_hugger #navigation_wrapper ul#navigation li.primary ul.secondary ul.tertiary li.inactive a").hoverIntent (
		function() {
			$(this).animate( { backgroundColor: '#F8DA00' }, 50 );

		},                                               
		function() {                                     
			$(this).css( { backgroundColor: '#E0F4FF' } );
		}
	);
	
	//	G O O D  N E W S

	$("#good_news").click (

		function(){
			if (
				$(this).hasClass("open")
				)
				$(this).removeClass("open").addClass("closed").animate( { 'min-width': '10px' }, 200 ).stop().find("p").hide();

			else
				$(this).removeClass("closed").addClass("open").stop().find("p").fadeIn(300).show(200);

		}
	);
		
	$("#good_news").hoverIntent (
		function() {
			$(this).animate( { 'min-width': '15px' }, 200 );
		},                                               
		function() {                                     

			$(this).animate( { 'min-width': '10px' }, 200 );
		}
	);
	
	// Notes overlay
	
	$("ul#notes_overlay li.inactive").hoverIntent (
		function() {
			$(this).animate( { opacity :'0.9' }, 200 );

			$(this).removeClass("inactive").addClass("active").find("p").fadeIn(200).show(200);
		},                                               
		function() {                                     

			$(this).animate( { opacity: '0.75' }, 200 );
			$("ul#project_notes li.inactive_note").animate( { color: '#999999' }, 200 );
			$(this).removeClass("active").addClass("inactive").find("p").fadeOut(200).hide(200);

		}
	);
		

	$("ul#notes_overlay li").hover (
		function(){
		    var classes = $(this).attr('class').split(' '); // create an array of class names

		    $.each(classes, function() { // iterate over array 
		        $('ul#project_notes li.' + this).animate( { color: '#BDF0FF' }, 200 );
	    		}
			);
		}
	);
	
	$("ul#project_notes li").hoverIntent (

		function(){
			$(this).animate( { color: '#BDF0FF' }, 200 );
		    var classes = $(this).attr('class').split(' '); // create an array of class names
		    $.each(classes,
				function() { // iterate over array 

		        	$('ul#notes_overlay li.' + this).animate( { opacity :'0.9' }, 200 ).removeClass("inactive").addClass("active").find("p").fadeIn(200).show(200);
	    		}
			);

		},
		function(){
			$(this).animate( { color: '#999999' }, 200 );
		    var classes = $(this).attr('class').split(' '); // create an array of class names
		    $.each(classes,
				function() { // iterate over array 

		        	$('ul#notes_overlay li.' + this).animate( { opacity: '0.75' }, 200 ).removeClass("active").addClass("inactive").find("p").fadeOut(200).hide(200);
	    		}
			);

		}
	);
	
		// project slideshow

		$('.piececontainer div, .slidetitle li').hide()
		$('.piececontainer div:eq(0), .slidetitle li:eq(0)').show()


		cur = 1;

		$('a.nasta').click(function () {

			req = cur + 1;


			if ( $('#slide'+req).length > 0 ) {
				$('#slide'+cur+', .caption'+cur).fadeOut();
				$('#slide'+req+', .caption'+req).delay(500).fadeIn();
				cur = req;

			} else {
				$('#slide'+cur+', .caption'+cur).fadeOut();
				$('#slide1'+', .caption1').delay(500).fadeIn();
				cur = 1;
			}
		});


		$('a.tidigare').click(function () {

			req = cur - 1;


			if ( req < 1 ) {
				$('#slide'+cur+', .caption'+cur).fadeOut();
				$('.piececontainer div:last, .slidetitle li:last').delay(500).fadeIn();

				cur = $('.piececontainer div:last').attr('id').replace('slide','');


			} else {
				$('#slide'+cur+', .caption'+cur).fadeOut();
				$('#slide'+req+', .caption'+req).delay(500).fadeIn();

				cur = req;

			}
		});
		
});
