$(function(){
    //remember the color ...
    if($.cookie('color')){
	set_color($.cookie('color'), false);
    }
    else{
	set_color('orange', false);
    }

    //the color picker
    $('button').click(function(){
	color = this.id;
	$.cookie('color',color, {expires: 9999,path:'/'});
	set_color(color, true);
    });
    $('a#toggle_in').click(function(e){
	e.preventDefault();
	$(this).fadeOut(300);
	$('#color_picker').animate({top:"0"}, 400, "swing", function(){
	    $('#color_picker').css({'background-color': '#222'});
	});
    });
    $('a#toggle_out').click(function(e){
	e.preventDefault();
	$('#color_picker').animate({top:"-33px"}, 400);
	$('a#toggle_in').fadeIn("slow");
	$('#color_picker').css({'background': 'none'});
    });

    //the home carousel
});

function set_color(color, animate){
    header = $('#header_bg');
    im = 'url(http://media.metarz.net/img/header-'+color+'.png) repeat-x';
    if(animate){
	header.fadeOut(1000, function(){
	    header.css({'background':im});
	});
	header.fadeIn(1000);
    }
    else{
	header.css({'background':im});
    }
    var orig_color = '';
    var color_map = {'orange': '#f69a13',
		     'blue'  : '#3caaff',
		     'red'   : '#df3918',
		     'green' : '#97d45c',
		     'purple': '#c41be3'};
    $('a').each(function(i){
	orig_color = this.style.color;
	$(this).hover(
	    function(){
		$(this).css('color',color_map[color]);
	    },
	    function(){
		$(this).css('color',orig_color);
	    }
	);
    });
}
