jQuery(document).ready(function($) {
	
	// blog images
	$('#blog a').hover(function(){
		$(this).find('img').animate({'opacity':'0.4'}, 110);
		$(this).find('.thumb-magnifier').animate({'opacity': '1'}, 130);
	}, function(){
		$(this).find('img').animate({'opacity':'1'}, 110);
		$(this).find('.thumb-magnifier').animate({'opacity': '0'}, 130);
	});
	

	
	function slideout_frontslider(){
		$('.frontslider-container').animate({'bottom': '0'});
	}
	
	function slidein_frontslider(){
		$('.frontslider-container').animate({'bottom': '-100px'});
	}
	
	// slide the frontslider
	$('.frontslider-container').css({'bottom': '-100px'});
	$('.frontslider-abscontainer').hoverIntent({
		over: slideout_frontslider, // function = onMouseOver callback (REQUIRED)    
		timeout: 800, // number = milliseconds delay before onMouseOut    
		out: slidein_frontslider // function = onMouseOut callback (REQUIRED)
	});
	

	

	// do the whitelayer
	$('#whitelayer').animate({'opacity': '0.2'});
	
	
	// navigation
	var nav_open = true;

	$('#nav-toggle').click(function(){
		if(nav_open == true) {
			
			// for ie fixing
			if ($.browser.msie && $.browser.version.substr(0,1)<9) {
				$('nav').css({'top': '-143px'});
			} else {
				$('nav').animate({'top': '-143px'}, 250);
			}
			$(this).fadeOut(250);
			var thisthis = this;
			setTimeout(function(){
				$(thisthis).find('.show-nav').show();
				$(thisthis).find('.hide-nav').hide();
			}, 250);
			$(this).fadeIn(250);
			
			//$('nav').slideUp();
			nav_open = false;
		} else if(nav_open == false) {
			
			// again for annoying ie
			if ($.browser.msie && $.browser.version.substr(0,1)<9) {
				$('nav').css({'top': '0'});
			} else {
				$('nav').animate({'top': '0'}, 250);
			}
			
			$(this).fadeOut(250);
			var thisthis = this;
			setTimeout(function(){
				$(thisthis).find('.show-nav').hide();
				$(thisthis).find('.hide-nav').show();
			}, 250);
			$(this).fadeIn(250);
			//$('nav').slideDown();
			nav_open = true;
		}
	});
	
	
	// fancybox of photos
	$("#photos .photo a, .attachment a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'			:	600, 
		'speedOut'		:	300,
		'overlayColor': '#000',
		'overlayOpacity': '0.9',
		'padding': '0'
	});
	
	// photos slider
	$(function() {
	    //vars
	    var conveyor = $(".photos-conveyor", $("#photos-content")),
	    item = $(".photo", $("#photos-content"));
			
			var width = 0;
	    //set length of conveyor
	    
			$(item).each(function(index) {
				width = width + $(this).width();
			});
			
			conveyor.css("width", width);

	    //config
	    var sliderOpts = {
	      max: width - parseInt($(".photos-viewer", $("#photos-content")).css("width")),
	      slide: function(e, ui) {
	        conveyor.css("left", "-" + ui.value + "px");
	      }
	    };

	    //create slider
	    $("#photos-slider").slider(sliderOpts);
	});
	
	
	// slider toggle things 
	var slider_over = false;
	var slider_toggle = false;
	
	
	$('#photos-slider a').mousedown(function(){
		slider_toggle = true;
	});
	$(document).mouseup(function(){
		if(slider_over == false) {
			slider_toggle = false;
			$('#photos-slider a').animate({'top':'18px', 'height':'2px'}, 150);
		}
	});
	
	$('#photos-slider').hover(function(){
		$(this).find('a').animate({'top':'16px', 'height':'7px'}, 150);
		slider_over = true;
	}, function(){
		if(slider_toggle == false) {
			$(this).find('a').animate({'top':'18px', 'height':'2px'}, 150);
		}
		slider_over = false;
	});

	
	// slider portfolio categories
	var pc_width_start = $('#photos-categories .selector').width();
	var pc_width_end = $('#photos-categories').width();
	var pc_open = false;
	
	$('#photos-categories').width(pc_width_start);
	
	$('#photos-categories .selector').click(function(){
		if(pc_open == false) {
			$('#photos-categories').animate({'width': pc_width_end + 'px'});
			$('#photos-slider').animate({'margin-left': (pc_width_end + 30) + 'px'});
			pc_open = true;
		} else if(pc_open == true) {
			$('#photos-categories').animate({'width': pc_width_start + 'px'});
			$('#photos-slider').animate({'margin-left': '90px'});
			pc_open = false;
		}
		
	});
	
	
	
	var footer_open = false;
	var footer_height = $('#footer-content-container').outerHeight();
	$('#footer-content-hidewrap').css({'height': '0px', 'overflow': 'hidden'});
	$('#footer-content-container').css({'top': '100%'});
	
	$('#bar a').click(function(){
		if(footer_open == false) {
			$('#footer-content-hidewrap').css({'height': footer_height + 'px'});
			
			$('#footer-content-container').animate({'top': '0'}, 200);
			$('#bar').animate({ 'top': '-' + footer_height + 'px' }, 200);
			footer_open = true;
			
			
			
			
			
			
			
		} else if(footer_open == true) {
			setTimeout(function(){
				$('#footer-content-hidewrap').css({'height': '0px'});
			}, 250);
			
			$('#footer-content-container').animate({'top': '100%'}, 200);
			$('#bar').animate({ 'top': '0' }, 200);
			footer_open = false;
		}
		return false;
	});
	
	
	
	// deactivate title hovers
	$(document).ready(function() {
	  $('[title]').each(function() {
	    $this = $(this);
	    $.data(this, 'title', $this.attr('title'));
	    $this.removeAttr('title');
	  });
	});
	
	
	
	
	// create the keyboard arrow notice
	
	if($.cookie('try-arrows') == null) {
		$('#try-arrows').fadeIn(400);
		$.cookie('try-arrows', 'showed', { expires: 1 }); // set cookie
	}
	
	if($.cookie('try-arrows')) {
		$('#supersized-loader').css({'margin-top': '-30px !important'});
	} // get cookie 
	
	$(document).keydown(function(e){ $('#try-arrows').fadeOut(800); });
	setTimeout(function(){ $('#try-arrows').fadeOut(800); }, 4000);
	
	
	// make blog content min-height like sidebar
	var asideheight = $('aside').height();
	$('#blog').css({'min-height': asideheight + 'px'});
	
});

