// Check to see if browser can handle what we are to throw at it
if (document.getElementById && document.getElementsByTagName && document.createElement) {
	 document.write('<link rel="stylesheet" type="text/css" href="/styles/show-hide.css" />');
	 window.onresize = bannerAlign;
}

function initTabpane(tabid) {
    var open_tab    = eval("_open_"+tabid);
    var tab_anchors = eval("_anchor_"+tabid);

    // Find all the tab links and append the onclick option to use toggle function
    var as = document.getElementById(tabid).getElementsByTagName('a');
    for (var k = 0; k < as.length; k++) {
        as[k].onclick = new Function("return toggleTab(this,'"+tabid+"');");
    }
}

function toggleTab(l,tabid) {
    // Get the right _tabset to deal with
    var _colours = eval("_colours_"+tabid);
    var tab_anchors = eval("_anchor_"+tabid);

    var idx = 0;

    if(l.parentNode.className == 'last' || l.parentNode.className == 'blast'){
        idx = 1;
        for(var k=0;k<l.parentNode.parentNode.getElementsByTagName('li').length;k++){
                this_color = _colours[idx];
if(k==0){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/latest-headline-off.gif)"; }
if(k==1){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/most-read-on.gif)"; }
l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundColor = this_color;
        }
    } else if(l.parentNode.className == 'first' || l.parentNode.className == 'bfirst') {
        idx = 0;
        for(var k=0;k<l.parentNode.parentNode.getElementsByTagName('li').length;k++){
              this_color = _colours[idx];
if(k==0){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/latest-headline-on.gif)"; }
if(k==1){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/most-read-off.gif)"; }
						l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundColor = this_color;
        }
    } else if(l.parentNode.className == 'tfirst') {
        idx =0;
        for(var k=0;k<l.parentNode.parentNode.getElementsByTagName('li').length;k++){
            this_color = _colours[idx];
if(k==0){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-left-on.gif)"; }
if(k==1){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-mid-off-left-on.gif)"; }
if(k==2){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-right-off-mid-off.gif)"; }
l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundColor = this_color;

        }
    } else if(l.parentNode.className == 'tmid') {
        idx = 1;
        for(var k=0;k<l.parentNode.parentNode.getElementsByTagName('li').length;k++){
            this_color = _colours[idx];
if(k==0){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-left-off-mid-on.gif)"; }
if(k==1){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-mid-on.gif)"; }
if(k==2){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-right-off-mid-on.gif)"; }
						l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundColor = this_color;
        }
    } else if(l.parentNode.className == 'tlast') {
        idx = 2;
        for(var k=0;k<l.parentNode.parentNode.getElementsByTagName('li').length;k++){
            this_color = _colours[idx];
if(k==0){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-left-off-mid-off.gif)"; }
if(k==1){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-mid-off-right-on.gif)"; }
if(k==2){l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundImage = "url(/images/triple-right-on.gif)"; }					l.parentNode.parentNode.getElementsByTagName('li')[k].style.backgroundColor = this_color;
        }
    }

    // Get the name if the div to display for the clicked tab 
    // div id needs to match the anchor name eg bit after #
    var cat_class = tab_anchors[idx].match(/#(\w.+)/)[1];

    // Then display the div	for the clicked tab 
    var clicked_tab = document.getElementById(cat_class);
    if(clicked_tab) {
        if(clicked_tab.style.display == "" || clicked_tab.style.display == "block") return true;

        clicked_tab.style.display = "block";
    }

    // Loop thru the divs for the tabset and make them all invisible
    var pool = document.getElementById("cp"+tabid).getElementsByTagName('div');
    for (var j = 0; j < pool.length; j++) {
        var curr_tab = document.getElementById(pool[j].id);

        if(curr_tab == clicked_tab) continue;

        curr_tab.style.display = 'none';
    }

    return false;
}

function bannerAlign() {
    // LITTLE JS TO MAKE THE BANNER ADD ALIGN CENTER OF SCREEN
    var w=0;

    if(document.body){
        w = document.body.clientWidth;
    } else if(window.innerWidth){
        w = window.innerWidth;
    }
    if(document.getElementById('top-banner')){
       n = document.getElementById('top-banner');
       align_this(n,w);
    }
    if(document.getElementById('base-banner')){
       n = document.getElementById('base-banner');
       align_this(n,w);
    }
}

function align_this(n,w){

//     var divs = n.getElementsByTagName('div');
//     if(divs.length>0) {
//         n = divs[0];
//     }

    if(w > 0){
        if(w > 988){
            n.style.paddingLeft = "0px";
            n.style.textAlign = "center";
        } else if(w <= 988 && w > 765) {
            n.style.textAlign = "left";
            p = (w-760)/2; // 760 = width of banner add 
            n.style.paddingLeft = p+"px";
        } else if(w <= 765) {
            n.style.paddingLeft = "0px";
            n.style.textAlign = "left";
        }
    }
} 