/* This is all to make LastFM Player shutup */ function LastFmBogus() { function FlashBogus() { function PlayerBogus() {
                                                    this.onLoad = function() { return false; }
                                                    this.onMouseDownViewport = function() { }
                                                } this.Player = new PlayerBogus(); } this.Flash = new FlashBogus(); } LFM = new LastFmBogus();

function get_get_parameter(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function get_style(element_id, style) {
    if(document.defaultView) {
        value = document.defaultView.getComputedStyle(document.getElementById(element_id), "").getPropertyValue(style);
    } else if(document.getElementById(element_id).currentStyle) {
        value = document.getElementById(element_id).currentStyle[style];
    }

    return value;
}

function hexcode_to_rgb(hexcode) {
    if (hexcode.substr(0,3) == 'rgb') {
        var rgb = hexcode.slice(4, -1).split(',');
        rgb[0] = Number(rgb[0]);
        rgb[1] = Number(rgb[1]);
        rgb[2] = Number(rgb[2]);
        return rgb;
    }
    if (hexcode.substr(0, 1) == '#') {
        hexcode = hexcode.substr(1); //toss out leading pound sign
    }
    hexcode = hexcode.toUpperCase();
    var rgb = new Array(parseInt(hexcode.substr(0, 2), 16), parseInt(hexcode.substr(2, 2), 16), parseInt(hexcode.substr(4, 2), 16));

    rgb[0] = Number(rgb[0]);
    rgb[1] = Number(rgb[1]);
    rgb[2] = Number(rgb[2]);

    return rgb;
}

text_color_change_events = new Array();
function text_color_change(element_id, start_color, end_color, duration, smoothing, delay, text) {
    if (!document.getElementById(element_id)) {
        return false; // could not find element
    }

    if (text_color_change_events[element_id]) {
        for (x = 0; x < text_color_change_events[element_id].length; x++) {
            window.clearTimeout(text_color_change_events[element_id][x]);
        }
    }
    text_color_change_events[element_id] = new Array();

    if (!start_color) {
        start_color = get_style(element_id, 'color'); //get current color from element
    }
    if (!end_color) {
        end_color = get_style(element_id, 'color');
    }
    start_color = hexcode_to_rgb(start_color);
    end_color = hexcode_to_rgb(end_color);

    if (!duration) {
        duration = 1000;
    }
    if (url_fade_duration = Number(get_get_parameter('fade_duration'))) {
        duration = url_fade_duration;
    }
    if (!smoothing) {
        smoothing = 100;
    }
    if (url_fade_smoothing = Number(get_get_parameter('fade_smoothing'))) {
        smoothing = url_fade_smoothing;
    }
    if (!delay) {
        delay = 0;
        //bugfix
        document.getElementById(element_id).style.color='rgb('+start_color[0]+','+start_color[1]+','+start_color[2]+')';
        if (text) {
            document.getElementById(element_id).innerHTML = text;
        }
    }
    var step = new Array((end_color[0]-start_color[0])/(smoothing+'.0'), (end_color[1]-start_color[1])/(smoothing+'.0'), (end_color[2]-start_color[2])/(smoothing+'.0'));

    if (text) {
        text_color_change_events[element_id][text_color_change_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").style.color = "rgb('+start_color[0]+','+start_color[1]+','+start_color[2]+')"', delay);
        text_color_change_events[element_id][text_color_change_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").innerHTML = unescape("'+escape(text)+'");', delay);
    }

    for (x = 0; x <= smoothing; x++) {
        text_color_change_events[element_id][text_color_change_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").style.color="rgb('+Math.round(start_color[0]+step[0]*x)+','+Math.round(start_color[1]+step[1]*x)+','+Math.round(start_color[2]+step[2]*x)+')"', Math.round((duration/smoothing+'.0')*x)+delay);
    }
}

resize_element_height_events = new Array();
function resize_element_height(element_id, start_height, end_height, duration, smoothing, delay) {
    if (!document.getElementById(element_id)) {
        return false; // could not find element
    }

    if (resize_element_height_events[element_id]) {
        for (x = 0; x < resize_element_height_events[element_id].length; x++) {
            window.clearTimeout(resize_element_height_events[element_id][x]);
        }
    }
    resize_element_height_events[element_id] = new Array();

    if (!start_height) {
        if (document.defaultView) {
            var start_height = document.defaultView.getComputedStyle(document.getElementById(element_id),"").height;
            start_height = start_height.substr(0, start_height.length-2);
        } else {
            var start_height = document.getElementById(element_id).scrollHeight;
        }
    }
    if (!end_height) {
        if (document.defaultView) {
            var end_height = document.defaultView.getComputedStyle(document.getElementById(element_id),"").height;
            end_height = end_height.substr(0, end_height.length-2);
        } else {
            var end_height = document.getElementById(element_id).scrollHeight;
        }
    }

    start_height = Number(start_height);
    end_height = Number(end_height);

    if (!duration) {
        duration = 1000;
    }
    if (url_resize_duration = Number(get_get_parameter('resize_duration'))) {
        duration = url_resize_duration;
    }
    if (!smoothing) {
        smoothing = 100;
    }
    if (url_resize_smoothing = Number(get_get_parameter('resize_smoothing'))) {
        smoothing = url_resize_smoothing;
    }
    if (!delay) {
        delay = 0;
    }
    var step = (end_height-start_height)/(smoothing+'.0');

    for (x = 0; x <= smoothing; x++) {
        resize_element_height_events[element_id][resize_element_height_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").style.height="'+Math.round(start_height+step*x)+'px"', Math.round((duration/smoothing+'.0')*x)+delay);
    }
}

function block_slide(element_id, duration, smoothing, delay) {
    if (delay) {
        return window.setTimeout('block_slide("'+element_id+'", '+duration+', '+smoothing+')', delay);
    }

    var element = document.getElementById(element_id);

    if (document.defaultView) {
        var current_display = document.defaultView.getComputedStyle(document.getElementById(element_id),"").display;
    } else {
        var current_display = document.getElementById(element_id).currentStyle.display;
    }

    if (current_display == 'none') { // slide down
        element.style.display = 'block';
        if (document.defaultView) {
            var end_height = document.defaultView.getComputedStyle(document.getElementById(element_id),"").height;
            end_height = end_height.substr(0, end_height.length-2);
        } else {
            var end_height = document.getElementById(element_id).scrollHeight;
        }
        element.style.height = '1px';
        resize_element_height(element_id, 1, end_height, duration, smoothing);
    } else { // slide up
        if (document.defaultView) {
            var start_height = document.defaultView.getComputedStyle(document.getElementById(element_id),"").height;
            start_height = start_height.substr(0, start_height.length-2);
        } else {
            var start_height = document.getElementById(element_id).scrollHeight;
        }
        resize_element_height(element_id, 0, 1, duration, smoothing);
        window.setTimeout('document.getElementById("'+element_id+'").style.display = "none";', duration);
        window.setTimeout('document.getElementById("'+element_id+'").style.height = "'+start_height+'px";', duration);
    }
}

function tab_switch(element_id, start_height, end_height, duration, smoothing, delay) {
    var element = document.getElementById(element_id);
    var parent = element.parentNode;
    //var parent_id = parent.attributes.getNamedItem('id').nodeValue;
    var parent_id = parent.getAttribute('id');

    if (!start_height) {
        if (document.defaultView) {
            var start_height = document.defaultView.getComputedStyle(parent,"").height;
            start_height = start_height.substr(0, start_height.length-2);
        } else {
            var start_height = parent.offsetHeight;
            //needs to include border width?
        }
    }
    start_height = Number(start_height);

    var node = parent.firstChild;
    do {
        if (node.style) {
            node.style.display = 'none';
        }
    } while (node = node.nextSibling);

    var overflow = parent.style.overflow;
    parent.style.overflow = 'hidden';
    parent.style.height = start_height;
    element.style.display = "block";

    if (!end_height) {
        if (document.defaultView) {
            var end_height = document.defaultView.getComputedStyle(element,"").height;
            end_height = end_height.substr(0, end_height.length-2);
        } else {
            var end_height = element.offsetHeight;
            var margin_top = element.currentStyle.marginTop;
            margin_top = Number(margin_top.substr(0, margin_top.length-2));
            end_height+= margin_top;
            var margin_bottom = element.currentStyle.marginBottom;
            margin_bottom = Number(margin_bottom.substr(0, margin_bottom.length-2));
            end_height+= margin_bottom;
            var border_top = element.currentStyle.borderTopWidth;
            border_top = Number(border_top.substr(0, border_top.length-2));
            end_height+= border_top;
            var border_bottom = element.currentStyle.borderBottomWidth;
            border_bottom = Number(border_bottom.substr(0, border_bottom.length-2));
            end_height+= border_bottom;
            var parent_padding_top = parent.currentStyle.paddingTop;
            parent_padding_top = Number(parent_padding_top.substr(0, parent_padding_top.length-2));
            end_height+= parent_padding_top;
            var parent_padding_bottom = parent.currentStyle.paddingBottom;
            parent_padding_bottom = Number(parent_padding_bottom.substr(0, parent_padding_bottom.length-2));
            end_height+= parent_padding_bottom;
        }
    }
    end_height = Number(end_height);

    if (duration) {
        resize_element_height(parent_id, start_height, end_height, duration, smoothing, delay);
    }
    if (overflow) {
        window.setTimeout('document.getElementById("'+parent_id+'").style.overflow = "'+overflow+'"', duration);
    }
}

text_typer_events = new Array();
function text_typer(element_id, direction, text, duration, delay) {
    if (!document.getElementById(element_id)) {
        return false;
    }

    if (text_typer_events[element_id]) {
        for (x = 0; x < text_typer_events[element_id].length; x++) {
            window.clearTimeout(text_typer_events[element_id][x]);
        }
    }
    text_typer_events[element_id] = new Array();

    if (!duration) {
        duration = 2000;
    }
    if (!delay) {
        delay = 0;
    }
    var disappear = false;
    if (!text) {
        disappear = true;
        text = document.getElementById(element_id).innerHTML;
    }
    var step = (duration+'.0')/text.length;

    var spaces = 0;
    if (direction != 'reverse') {
        if (!disappear) {
            for (x = 0; x < text.length; x++) {
                if (text.charAt(x) == ' ') {
                    spaces++;
                    x++;
                }
                text_typer_events[element_id][text_typer_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").innerHTML = unescape("'+escape(text.substr(0, x+1))+'")', Math.round(step*(x-spaces))+delay);
            }
        } else {
            for (x = 0; x < text.length; x++) {
                if (text.charAt(x) == ' ') {
                    spaces++;
                    x++;
                }
                text_typer_events[element_id][text_typer_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").innerHTML = unescape("'+escape(text.substr(0, text.length-x-1))+'")', Math.round(step*(x-spaces))+delay);
            }
        }
    } else {
        if (!disappear) {
            for (x = 0; x < text.length; x++) {
                if (text.charAt(x) == ' ') {
                    spaces++;
                    x++;
                }
                text_typer_events[element_id][text_typer_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").innerHTML = unescape("'+escape(text.substr(text.length-x-1))+'")', Math.round(step*(x-spaces))+delay);
            }
        } else {
            for (x = 0; x < text.length; x++) {
                if (text.charAt(x) == ' ') {
                    spaces++;
                    x++;
                }
                text_typer_events[element_id][text_typer_events[element_id].length] = window.setTimeout('document.getElementById("'+element_id+'").innerHTML = unescape("'+escape(text.substr(x+1))+'")', Math.round(step*(x-spaces))+delay);
            }
        }
    }
}

function requestObject(){
  if (window.XMLHttpRequest) {
     return new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
     return new ActiveXObject("Microsoft.XMLHTTP");
  }
}

