function selectcolor(color) {
        var colors = Array('orange', 'blue', 'green', 'pink', 'silver');
        if (color == null) color = colors[0];
        else if (!$.grep(colors, function(i) { return color == i; }))
                color = colors[0];
        $.each( colors, function(col) {
                $('.color').removeClass(colors[col]);
        });
        $('.color').addClass(color);
        $.cookie('color', color);
        $(".borders").corner("15px tl");
}

var dotsliving = 10;
function livingDots() {
        if (dotsliving < 1) return; dotsliving = dotsliving-1;
        var elements = $('#colorselector').children().children('img');
        var el = elements[(dotsliving % elements.length)  ];
        var w = 2 * $(el).attr('width');
        $(el).animate( {
                        width: w,
                        height: w
                },450);
        $(el).animate( {
                        width: w / 2,
                        height: w / 2
                },300);
}


$(document).ready(function() {
        $(".tabs").tabs(1);
        selectcolor($.cookie('color'));
        $(".borders").corner("15px tl");


        $('#colorselector img').hover(
                function() {
                        var imgsrc = $(this).attr('src');
                        $(this).attr('src', imgsrc.replace('.png', '-active.png'));
                },
                function() {
                        var imgsrc = $(this).attr('src');
                        $(this).attr('src', imgsrc.replace('-active.png', '.png'));
                }
        ); // colorselector

        var livingDots = window.setInterval("livingDots()", 500);
        $('#logo').mouseover(function(){ if (dotsliving==0) dotsliving=20; });
        $('#colorselector').mouseover(function(){ dotsliving=0; });

        $('.hiddeninputs label').click(function(){
                $(this).parent().children('label').children('img').each(function(){
                        var imgsrc = $(this).attr('src');
                        $(this).attr('src', imgsrc.replace('-active.png', '.png'));
                });
                var imgsrc = $(this).children('img').attr('src');
                $(this).children('img').attr('src', imgsrc.replace('.png', '-active.png'));
        });

        $('.gadget_models').hide(0);
        $('.gadget_model').click(function(){
                $('.gadget_models').hide(0);
                var id = '#gadget_' + $(this).attr('id');
                $(id).show(0);
        });

});
