$(document).ready(function(){
	//$('a[href*=#]').each(function () { $(this).attr('href', $(this).attr('href').replace('#', '#_')); });
	//hashname = window.location.hash.replace('#_', '');
	$('#notification-bar .hide').click(function(event){
		event.preventDefault();
		$('#notification-bar').animate({marginTop: -45}, 200, function() {
			$('#show-notification').animate({marginTop: 37}, { queue: false, easing: 'swing', duration: 200 });
			$.cookie("notificationbar", "hidden", { path: '/' });
		});
	});
	$('#show-notification').click(function(event){
		event.preventDefault();
		$(this).animate({marginTop: -45}, 200, function () {
			$('#notification-bar').animate({marginTop: 0}, { queue: false, easing: 'swing', duration: 200 });
			$.cookie("notificationbar", "visible", { path: '/' });
		});
	});
	if ($.cookie("notificationbar") === 'hidden'){
		$('#notification-bar').css("marginTop", -45);
		$('#show-notification').css("marginTop", 37);
	} else {
		$('#notification-bar').css("marginTop", 0);
		$('#show-notification').css("marginTop", -45);
	}
	$('.thumb').hover(function(event){
		$(this).children('.thumbmenu').animate({ opacity: 1 }, { queue: false, easing: 'swing', duration: 200 }); 
	}, function(){
		$(this).children('.thumbmenu').animate({ opacity: 0 }, { queue: false, easing: 'swing', duration: 200 }); 
	});
	$('.launch_site').click(function(event){
		var link_id = $(this).children('span').attr('class').substring(8);
		$.post('/forms/count_click/'+link_id);
	});
	/*
	$('.likeable').click(function(event){
		event.preventDefault();
		var str = $(this).text();
		var link_id = $(this).attr('id').substring(8);
		var num_likes = $('.num_likes_'+link_id).text();
		$.ajax({
			type : 'POST',
			url : '/forms/set_favorite/',
			dataType : 'json',
			data: {
				link_id : link_id,
				str : str,
				num_likes : num_likes
			},
			success : function(data){
				if (str === 'Like'){
					$('.num_likes_'+data.link_id).text(data.new_num_likes);
					$('a#sb_link_'+data.link_id).html('Thanks!');
				}
				if (data.new_num_likes === 1){
					$('.people_'+data.link_id).text('person');
					$('.likes_title_'+data.link_id).text('like');
				} else {
					$('.people_'+data.link_id).text('people');
					$('.likes_title_'+data.link_id).text('likes');
				}
				$('a#sb_link_'+data.link_id).replaceWith('<span class="is_set">Thanks!</span>');
				setTimeout(function(){ $('#header span.is_set').fadeOut(750); }, 2000);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert(error);
			}
		});
	});*/
	$('#success_message').fadeOut(3000);
	$('#header #search_box input').focus(function(){
		$('#header #search_box').css('background-position', '0 -42px');
	});
	$('#header #search_box input').blur(function(){
		$('#header #search_box').css('background-position', '0 0');
	});
	$('#search_form').submit(function(){
		$('#header #search_box').css('background-position', '0 -84px');
	});
	$('#go').mousedown(function(){
		$('#header #search_box').css('background-position', '0 -84px !important');
	});
	$('#go').mouseup(function(){
		$('#header #search_box').css('background-position', '0 -42px !important');
	});
	$('#color_cloud a').hover(function(event){
		$(this).animate({left: "+=30px"}, {duration: 200});
	}, function(){
		$(this).animate({left: "0"}, {duration: 200});
	});
});

// smooth scroll to anchor when page is loaded
//$(window).load(function() {
//	var target_offset = $("#"+hashname).offset();
//	var target_top = target_offset.top;
//	$('html, body').delay(250).animate({scrollTop:target_top}, 1000, "swing");	
//});

// animate anchor navigation
$(".scroll").click(function(event){
	event.preventDefault();
	//get the full url - like example/page_alias#test
	var full_url = this.href;
	//split the url by # and get the anchor target name - home in example/page_alias#test
	var parts = full_url.split("#");
	var trgt = parts[1];
	//get the top offset of the target anchor
	var target_offset = $("#"+trgt).offset();
	var target_top = target_offset.top;
	//goto that anchor by setting the body scroll top to anchor top
	$('html, body').animate({scrollTop:target_top}, 1500, "swing");
});
