/*
 * Change Skin
 */

get_current_color = function() {
    color_class = $('body').attr('class');
    colors = color_class.split('site_');
    color = "";
    if (colors.length > 1) color = colors[1];
    return color;
}

change_src = function(obj, str_split, color) {
    src = obj.attr('src');
    split = (str_split + get_current_color() + '/').replace('//', '/');
    if (src.indexOf(split) == 0) {
	ssrc = src.split(split);
	if (ssrc.length > 1) {
	    obj.attr('src', str_split + color + '/' + ssrc[1]);
	}
    }
}

change_skin = function(next_color) {
    $('img, input.btn').each(function() {
	change_src($(this), 'btn/', next_color);
	change_src($(this), 'img/', next_color);
	change_src($(this), '../btn/', next_color);
	change_src($(this), '../img/', next_color);
    });
    
    $('body').removeClass('site_' + get_current_color());
    $('body').attr('class', 'site_' + next_color);
}

var random_skin = function() {
    n = Math.floor(Math.random() * str_colors.length);
    
    next_color = str_colors[n];
    change_skin(next_color);
}

var auto_switch_skin = function() {
    n = Math.floor(Math.random() * str_colors.length);
//    n = (n + 1) % str_colors.length;
    next_color = str_colors[n];
    change_skin(next_color);
}

var str_colors = ['black', 'blue', 'green', 'orange', 'pink', 'red'];
var n = 0;


