

function change_bubble_page(bubble_id, bubble_page_id, new_menu_link)
{
    var donor_div = document.getElementById('pagecontent_'+bubble_page_id);
    var surrogate_div = document.getElementById('bubble_text');
    var old_menu_link = document.getElementById('b_menu_active_'+bubble_id);
    
    var donor_head = document.getElementById('pageheading_'+bubble_page_id);
    var surrogate_head = document.getElementById('bubble_heading');
    
    
    var donor_greatForText = document.getElementById('greatForText');
    
    var donor_great = document.getElementById('greatfor_'+bubble_page_id);
    var surrogate_great = document.getElementById('bubble_extras');
    
    var donor_social = document.getElementById('social_'+bubble_page_id);
    var surrogate_social = document.getElementById('bubble_social');
    
    
    if(donor_div)
    {
        surrogate_head.innerHTML = donor_head.innerHTML;
        surrogate_div.innerHTML = donor_div.innerHTML;
        surrogate_great.innerHTML = donor_great.innerHTML;
        surrogate_social.innerHTML = donor_social.innerHTML;
        
        if(typeof old_menu_link != "undefined" && old_menu_link)
        {
            old_menu_link.className = "";
            old_menu_link.id = "";
        }
        new_menu_link.className = "b_menu_active";
        new_menu_link.id = "b_menu_active_"+bubble_id;
        
        if(donor_great.innerHTML != "")donor_greatForText.className = "great";
        else donor_greatForText.className = "nodisplay";
        
        if(donor_social.innerHTML != "")surrogate_social.className = "";
        else surrogate_social.className = "nodisplay";
        
    }
    
}

function change_bubble(bubble_sel)
{
    var bubble_id = bubble_sel.value;
    var donor_ul = document.getElementById('bubble_menu_'+bubble_id);
    
    var donor_strapline = document.getElementById('b_straplines_'+bubble_id);
    var strapline = document.getElementById('bubble_strapline');
    
    var donor_img = document.getElementById('b_images_'+bubble_id);
    var b_image = document.getElementById('bubble_image');
    
    var surrogate_ul = document.getElementById('bubble_menu');
    var menu_wrapper = document.getElementById('bubble_menu_wrapper');
    
    
    if(typeof donor_ul != "undefined" && donor_ul)
    {
        //surrogate_ul.innerHTML = donor_ul.innerHTML;
        //surrogate_ul.innerHTML = "";
        var new_ul = donor_ul.cloneNode(true);
        new_ul.className = "bubble_menu";
        new_ul.id = "bubble_menu";
        
        if(typeof donor_img != "undefined" && donor_img)b_image.src = donor_img.src;
        strapline.innerHTML = donor_strapline.innerHTML;
        
        menu_wrapper.replaceChild(new_ul, surrogate_ul);
        
        var starter_li = new_ul.firstChild;
        var starter_link = starter_li.firstChild;
        
        var bubble_page_id = get_id_from_el_id(new_ul.firstChild.id);
        
        
        change_bubble_page(bubble_id, bubble_page_id, starter_link)
    }
    
}


function get_id_from_el_id(id)
{
    var regexp = /(.).(.er)/i;

    var arr = id.split('_');
    
    return arr[2];
}


/* Very Basic Scroller            */

var ie4=document.all;

function scroller_class(delay, id)
{
	this.delay = delay;
	this.id = id;
	this.totalcontent = 0;
	this.curindex = 0;
}

scroller_class.prototype.get_total = function()
{
    if (ie4)
    {
        while (eval("document.all."+this.id+this.totalcontent))
        this.totalcontent++
    }
    else
    {
        while (document.getElementById(''+this.id+this.totalcontent))
        {
            this.totalcontent++;
        }
    }
}

scroller_class.prototype.contract_all = function()
{
    var y=0;
    for (y=0; y<this.totalcontent; y++)
    {
        if (ie4)
            eval("document.all."+this.id+y).className="nodisplay";
        else
            document.getElementById(''+this.id+y).className="nodisplay";
    }
}


scroller_class.prototype.expand_one = function()
{
    this.contract_all();
    if (ie4)
        eval("document.all."+this.id+this.curindex).className="";
    else
    {
        var the_one = document.getElementById(''+this.id+this.curindex);
        the_one.className = "";
    }
}








