// class Collection()
// collection of objects class.
function Collection() {
    this.type = "";
    this.items = new Array();
    this.count = 0;
    this.add = addCollectionItem;
    this.get = getCollectionItem;

    // Adds an item (object) to the collection.
    // item: The object to add
    // remark: Only objects of class specified in this.type are allowed.
    function addCollectionItem(item) {
        var className = /(\w+)\(/.exec(item.constructor.toString())[1];
        if(className == this.type && item.id) {
            this.items[this.count] = item;
            this.count++;
        }
        else {
            if(item.id)alert('Collection.add Error\nOnly >' + this.type + '< allowed!');
            else alert('Collection.add Error\nItem has no >Id< Property!');
        }
    }

    // Get an object from the collection by object.id;
    function getCollectionItem(id) {
        var item = null;
        for(i=0;i<this.count;i++) {
            if(this.items[i].id == id) {
                item = this.items[i];
            }
        }
        return item;
    }
}

// class FlashIFrame()
// single Frame used by the FlashIFrameNavi class.
function FlashIFrame(id, url, imageLink, height) {
    this.id=id;
    this.url= url;
    this.imageLink = imageLink.replace(/&amp;/g,String.fromCharCode(38));
    this.height = height;
}

// class FlashIFrames()
// Collection of FlashIFrame elements. Derived from Collection, used by the FlashIFrameNavi class.
function FlashIFrames() {
    this.items = new Array();
    this.type = "FlashIFrame";
}
FlashIFrames.prototype = new Collection;


var g_flashIFrameNaviReq = null; // HTTPRequest for FlashIFrameNavi frame changes
// class FlashIFrameNavi()
// Used to dynamically change contents of a page, controlled by flash or the HTML fallback.
// frameId: 
function FlashIFrameNavi(frameId, flashIFrames) {
    this.frameId = frameId;
    this.useIFrame = true;
    this.flashIFrames = flashIFrames;
    this.checkNavigation = checkNavigation;
    this.changeContent = changeContent;
    this.getInnerContent = getInnerContent;

    var XMLHttpFactories = [
        function () {return new XMLHttpRequest()},
        function () {return new ActiveXObject("Msxml2.XMLHTTP")},
        function () {return new ActiveXObject("Msxml3.XMLHTTP")},
        function () {return new ActiveXObject("Microsoft.XMLHTTP")}
    ];

    function createXMLHTTPObject() {
        var xmlhttp = false;
        for (var i=0;i<XMLHttpFactories.length;i++) {
            try {
                xmlhttp = XMLHttpFactories[i]();
            }
            catch (e) {
                continue;
            }
            break;
        }
        return xmlhttp;
    }
    
    //change the content of the layer/iframe with id=frameId
    function changeContent(frameId) {
        var height = 2100;
        var frame = document.getElementById(this.frameId);
        var introImage = document.getElementById('introImage_Image');
        var url;
        var imageLink;
        var height;
        var currentFrame = this.flashIFrames.get(frameId)
        if(currentFrame && currentFrame.url != '')
        {
            if(!this.useIFrame) {
                thisFrameId = this.frameId;
            	g_flashIFrameNaviReq = createXMLHTTPObject();
            	if(g_flashIFrameNaviReq.overrideMimeType)g_flashIFrameNaviReq.overrideMimeType('text/xml');
                g_flashIFrameNaviReq.onreadystatechange = function() {eval('getInnerContent(thisFrameId)')};
                g_flashIFrameNaviReq.open("GET", currentFrame.url, true);
                g_flashIFrameNaviReq.send(null);
            }
            else {
                frame.src = currentFrame.url;
                frame.style.height = currentFrame.height + 'px';
            }
            if(introImage) {
                introImage.src = currentFrame.imageLink;
            }
        }
        else {
            alert(frameId + 'not found!');
        }
    }
    
    function getInnerContent(frameId) {
        if (g_flashIFrameNaviReq.readyState != 4) {return;}
        if (g_flashIFrameNaviReq.status != 200 && req.status != 304) {return;}

        var footer = document.getElementById("footer");
        var frame = document.getElementById(frameId);
        var page = g_flashIFrameNaviReq.responseText;
        var pageDoc = null; 
        // Parsing the responseText into an 
        if(!window.DOMParser) {
            //Internet Explorer
            try {
                page = page.replace(/\<!DOCTYPE .*>/, '');
                pageDoc=new ActiveXObject("Microsoft.XMLDOM");
                pageDoc.async = false;
                pageDoc.loadXML(page);
                if(pageDoc.parseError != 0)alert(pageDoc.parseError.line + ' - ' + pageDoc.parseError.srcText + '\n' + pageDoc.parseError.reason);
            }
            catch(e)
            {
                alert(e.message);
            }
        }
        else {
            //Firefox, Mozilla, Opera, etc.
            try {
                parser=new DOMParser();
                pageDoc=parser.parseFromString(page,"text/xml");
            }
            catch(e) {
                alert(e.message);
            }
        }
        if(pageDoc) {
            if(pageDoc.documentElement)var elements = pageDoc.documentElement.getElementsByTagName("div");
            else var elements = pageDoc.getElementsByTagName("div");
            if (elements) {
                for (i = 0; i < elements.length; i++) {
                    classAttribute = null;
                    classAttribute = elements[i].attributes.getNamedItem('class');
					if (classAttribute != null && classAttribute.nodeValue == 'innerContent') {
                        pageDiv = elements[i];
                        pageDiv.attributes.getNamedItem('class').nodeValue = ''
                        break;
                    }
				//###############################################################					
					/*if (classAttribute != null && classAttribute.nodeValue == 'tabContent') {
			                        var tabContent = elements[i];
			                        var p_element = tabContent.getElementsByTagName("p");
									if(p_element){
										for(j=0;j<p_element.length;j++)
											p_element[j].setAttribute("class", "footnote");
									}
					}*/							
				//###############################################################						
					
					
                }
				
            }
            if(pageDiv) {
                if(pageDiv.xml) {
                    frame.innerHTML = pageDiv.xml;
                }
                else {
                    try {
						
                        frame.innerHTML = '';
                        frame.appendChild(document.importNode(pageDiv, true));
                        if(!g_is_opera) {
                            frame.innerHTML = frame.innerHTML;
                        }
                    }
                    catch(e) {
                        alert(e.message);
                    }
                }
                if(footer) {
                    positionFooter();
                    document.getElementById("footer").style.display = "none";
                    document.getElementById("footer").style.display = "block";
                }
            }
        }
    }

    function checkNavigation() {
        intro = document.getElementById('introImage');
        if (intro) {
            inner = intro.innerHTML;
            if (!document.getElementById('introFlash_flash')) {
                htmlNavi = document.getElementById('flashiframenavi');
                if (htmlNavi) {
                    htmlNavi.style.display = 'block';
                    img = document.createElement('img');

                    img.setAttribute('id', 'introImage_Image');
                    intro.innerHTML = ''
                    intro.appendChild(img);
                }
            }
        }
    }
} // End of FlashIFrameNavi Class
