/* -----------------------------------------------------------------
// Tabbed Items Classes
//
// Class for TNT Post tabbed items
// Dependency: 
// Used by: page object
// Version: 1.2 (20071112)
//
// Copyright 2007, TNT Post
//
// CVL 2007-11-07: Vertical tabs added
// AFR 2007-07-25: Function TabbedSection has been altered
----------------------------------------------------------------- */

/* -----------------------------------------------------------------
// TabbedItems Class
----------------------------------------------------------------- */
TabbedItems = function() {
    /* Horizontal tabs */
    this.sections = new Array;
    var sections = getElementsByClassName("tabbed-section", document);
    if (sections.length > 0) {
        for (var i = 0; i < sections.length; i++) {
            this.sections[this.sections.length] = new TabbedSection(sections[i], "ts" + i);
        };
    };
    /* Vertical tabs */
    this.vSections = new Array;
    var vSections = getElementsByClassName("v-tab-nav", document);
    if (vSections.length > 0) {
        for (var i = 0; i < vSections.length; i++) {
            this.vSections[this.vSections.length] = new TabbedSectionVertical(vSections[i], "tvs" + i);
        };
    };
    tickle();
};
TabbedItems.prototype.destroy = function() {
    /* Horizontal tabs cleanup */
    for (var i = 0; i < this.sections.length; i++) {
        for (var j = 0; j < this.sections[i].tabs.childNodes; j++) {
            var u = this.sections[i].tabs.childNodes[j];
            u.number = u.onclick = null;
        };
    };
    /* Vertical tabs cleanup */
    for (var i = 0; i < this.vSections.length; i++) {
        for (var j = 0; j < this.vSections[i].lis; j++) {
            this.vSections[i].lis[j].onmouseover = this.vSections[i].lis[j].onmouseout = null;
        };
    };
};
function SetMovie(swf) {
    if (document.getElementById("flashCont")) {
        var fc = document.getElementById("flashCont")
        fc.parentNode.removeChild(fc)
    }
    var img = document.getElementById("changebleimage");
    var flash = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"315\" height=\"195\">";
    flash += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
    flash += "<param name=\"movie\" value=\"" + swf + "\" />";
    flash += "<param name=\"quality\" value=\"high\" />";
    flash += "<param name=\"wmode\" value=\"transparent\">";
    flash += "<embed src=\"" + swf + "\" quality=\"high\" wmode=\"transparent\" width=\"315\" height=\"195\"  type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
    flash += "</object>";
    var flashCont = document.createElement("div");
    flashCont.innerHTML = flash;
    flashCont.setAttribute("style", "width:315px;height:195px;");
    flashCont.setAttribute("id", "flashCont");
    flashCont.setAttribute("name", "flashCont");
    img.parentNode.insertBefore(flashCont, img);
    img.style.display = "none";
}
/* -----------------------------------------------------------------
// TabbedSection Class
----------------------------------------------------------------- */
TabbedSection = function(obj, id) {
    // gather children and construct the menu
    this.items = getElementsByClassName("tabbed-item", obj);
    this.headers = getElementsByClassName("tabbed-header", obj);
    this.changeImages = getElementsByClassName("changeableImage", obj);
    // create tabbed menu
    this.tabs = document.createElement("ul");
    this.tabs.className = "tabs";

    for (var i = 0; i < this.headers.length; i++) {
        var tab = document.createElement("li");
        var self = this;
        tab.number = i;
        if (this.headers[i].title) var label = this.headers[i].title;
        else var label = this.headers[i].innerHTML;
        var strimage = '';
        for (j = 0; j < this.changeImages.length; j++) {

            if (this.changeImages[j].getAttribute('tabindex') == i) {
                strimage = this.changeImages[j].value;
            }
        }
        if (strimage.indexOf(".swf") > 0) {
            tab.innerHTML = "<a href=\"#\" onclick=\"SetMovie('" + strimage + "');\">" + label + "</a>";
        }
        else {
            tab.innerHTML = "<a href=\"#\" onclick=\"ChangeImage('" + strimage + "');\">" + label + "</a>";
        }
        tab.onclick = function() {
            self.resetAll(this.number);
            return false;
        }
        this.tabs.appendChild(tab);
    }
    this.tabs.childNodes[0].className = "first";
    obj.insertBefore(this.tabs, this.items[0]);
    // set defaults
    this.resetAll(0);
}
TabbedSection.prototype.resetAll = function(exception) {
	for (var i = 0; i < this.items.length; i++) {
		if (i != exception) {
			removeClass(this.items[i], "current");
			removeClass(this.tabs.childNodes[i], "current");
		} else {
			addClass(this.items[i], "current");
			addClass(this.tabs.childNodes[i], "current");
			if (document.getElementById("changeimage")) {
			     document.getElementById("changeimage").style.display = "";
			     if (this.items[i].className.indexOf("tab-wide") > 0) {
			          document.getElementById("changeimage").style.display = "none";
			    }else{
            if(exception!=0){
              for(var x = 0; x < this.items[i].childNodes.length; x++){
                if(this.items[i].childNodes[x].className=="changeableImage"){

        if (this.items[i].childNodes[x].value.indexOf(".swf") > 0) {
            SetMovie(this.items[i].childNodes[x].value);
        }
        else {
            document.getElementById("changebleimage").src=this.items[i].childNodes[x].value;
        }                  

                                  }
              }
            }
			    }
			}
		}
	}
	tickle();
}

/* -----------------------------------------------------------------
// TabbedSectionVertical Class
----------------------------------------------------------------- */
TabbedSectionVertical = function(obj, id) {
    this.locationUri = location.href; // URI to highlight
    // gather children
    this.lis = obj.getElementsByTagName("li");
    if (this.lis.length > 0) {
        for (var i = 0; i < this.lis.length; i++) {
            // hook up behaviors
            this.lis[i].onmouseover = function() {
                addClass(this, "hover");
            };
            this.lis[i].onmouseout = function() {
                removeClass(this, "hover");
            };
            // highlight current item corresponding to URI
            if (this.locationUri.match(this.lis[i].getElementsByTagName("a")[0].href)) {
                addClass(this.lis[i], "current");
            };
        };
    };
};

