
// ##### START COPYRIGHT NOTICE!

// Copyright 2004, 2005, 2006, 2007 Mythworks

// This Work is also relased under the terms of the GPL:

// This Work or file is part of the greater total Work, software or group of files named TInC.

// TInC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

// TInC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along with TInC; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

// Aternativly This Work is also relased under the terms of the CGPL:

// This Work or file is part of the greater total Work, software or group of files named TInC.

// TInC can be redistributed and/or modified under the terms of the CGPL, The Common Good Public License as published by and at CGPL.org (http://CGPL.org).  It is released under version 1.0 Beta of the License until the 1.0 version is released after which either version 1.0 of the License, or (at your option) any later version can be applied.

// THIS WORK, OR SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED (See the CGPL, The Common Good Public License for more information.)

// You should have received a copy of the CGPL, The Common Good Public License along with TInC; if not, email <copy@CGPL.org> or see http://CGPL.org to get a copy of the License.

// If you make changes please email your changes to the CGPL archive for easy copyright compliance and to add to the CGPL community at add@CGPL.org (i.e. easy source access - Duty to Share - 0.3 )

// ##### END COPYRIGHT NOTICE!


// TInC 0060-Alpha (Tiny Interface for Content), with resizing

// This is a VERY Alpha release.  A lot has changed.  

// More is on the way. (XML Schema and editor, objectification (we hope), history, page gen?)

// We will add a features, and fixes list here as soon as we have a feature stable release.  Also, new code comments and docs are on there way too.

//support lib

function GetWindowWidth(){
  var winw = 0;
  d = document;
   if ( typeof window.innerWidth != 'undefined' )
     winw = window.innerWidth;  // NN and Opera version
   else
   {
     if ( d.documentElement
       && typeof d.documentElement.clientWidth!='undefined'
       && d.documentElement.clientWidth != 0 )
       winw = d.documentElement.clientWidth;
     else
       if ( d.body
         && typeof d.body.clientWidth != 'undefined' )
         winw = d.body.clientWidth;
     else alert ("The program is not compatible with this Web Browser.")
   }
   return winw-32;
}

function GetWindowHeight(){
  var winh = 0;
  d = document;
   if ( typeof window.innerHeight != 'undefined' )
     winh = window.innerHeight;  // NN and Opera version
   else
   {
     if ( d.documentElement
       && typeof d.documentElement.clientHeight!='undefined'
       && d.documentElement.clientHeight != 0 )
       winh = d.documentElement.clientHeight;
     else
       if ( d.body
         && typeof d.body.clientHeight != 'undefined' )
         winh = d.body.clientHeight;
     else alert ("The program is not compatible with this Web Browser.")
   }
   return winh-50;
}

function browser_type(){
    //Globals Gecko, IE, Safari
    Gecko = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
    IE = (typeof window.ActiveXObject != 'undefined');
    Safari = 0; //need to add safari
}

function set_url(url, url_sub){
    window.location.href = url+"?"+url_sub;
}

function set_url_search(url_sub){
    window.location.search = url_sub;
}

function set_url_hash(url_sub){
    window.location.hash = url_sub;
}

function url_args(url_sub) {
	var args = new Object();
	//var query = location.search.substring(1);  // Get query string.
    if (!url_sub) url_sub = location.search.substring(1); 
	var def_pairs = url_sub.split(",");
	for(var i = 0; i < def_pairs.length; i++) {
		var pos = def_pairs[i].indexOf('=');       // Look for "name=value".
		if (pos == -1) continue;               // If not found, skip.
		var argname = def_pairs[i].substring(0,pos);  // Extract the name.
		var value = def_pairs[i].substring(pos+1); // Extract the value.
		args[argname] = unescape(value);
	}
	return args;                               // Return the prop array
}

function clear(){
	var bodyRef = document.getElementsByTagName("body")[0];     
	//alert(bodyRef.firstChild.nodeValue );
	bodyRef.innerHTML = "";
}



//TInC

// run setup functions and set GLOBALS

var gIframe = 0;
var gClear = 0;
var gRatio = 1;
var gHistory = new Array();
var gBack_history = new Array();
var gAdd_2_back = 1;
var screen_id;
var popup_screen_id;
var screen_names = new Array();

function get_ratio(type){
	var orgw = 950;
	var orgh = 600;
	switch (type){
		case "w":
			var winw = GetWindowWidth();
			gRatio = winw / orgw;
		break;
		case "h":
			var winh = GetWindowHeight();
			gRatio = winh / orgh;
		break;
		case "fit":
			var winw = GetWindowWidth();
			var winh = GetWindowHeight();
			var w_ratio = winw / orgw;
			var h_ratio = winh / orgh;
			if (w_ratio <= h_ratio) {
				gRatio = w_ratio;
			}
			else{
				gRatio = h_ratio;
			}
		break;
		case "org":
			gRatio =1;
		break;
	}
}

function Resize(clear_it, scale_type){
    //need to add a dont add to go back history here
	get_ratio(scale_type);
    //snap_win();
	gClear = clear_it;
	divEngine(screen_names);
}

function go_back(){
 if (gBack_history.length>1){
  screen_id = gBack_history[gBack_history.length-2];
  var end = gBack_history.length-2;
  gBack_history.splice(end,2);
  //alert(gBack_history);
  gClear = 1;
  make_screen_array()
 }
}

function load_XML(filename){
    //alert("loading XML");
	if (document.implementation && document.implementation.createDocument){
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = make_screen_array; // linkLoad() it messes up xmlDoc . . . WTFF???
	}
	else if (window.ActiveXObject){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
		    if (xmlDoc.readyState == 4) make_screen_array();
		}
 	}
	else{
		alert('Your browser can\'t handle this script');
		return;
	}

	xmlDoc.load(filename);
}

function TInC(filename, start_screen){
    browser_type();
    if (!window.location.search.substring(1)) {
        set_url_search("screen="+start_screen);
    }
    else{
        args = url_args(0);
        screen_id = args.screen;
        load_XML(filename); // how to get it in the toolbar with out loading the xml every time
    }
}

function linkLoad(screen_link){
    if (screen_link.substring(0, 1) == "@") {
        popup_screen_id = screen_link.substring(1);
        //need not only a no back history but a @ flag
        gAdd_2_back = 0;
    }
    else {
        screen_id = screen_link;
        clear();
    }
    make_screen_array();
}

function make_screen_array(){
	var xml_screen_id = "";
    if (gAdd_2_back) {
        screen_names = new Array();
	    var screen = xmlDoc.getElementsByTagName("screen");
	    for (var i=0; i<screen.length; i++){	
		    var xml_screen_id = screen[i].getElementsByTagName("id")[0].firstChild.nodeValue;
		    if (xml_screen_id == screen_id){
			    var parent_ids =screen[i].getElementsByTagName("parent_screen")[0].firstChild.nodeValue;
			    screen_names = parent_ids.split(",");
		    }
	    }
	    screen_names[screen_names.length] = screen_id;
        divEngine(screen_names, 0);
    }else{
        divEngine([popup_screen_id], 0);
    }
	//var screen_names2 = screen_names;
	//var test = screen_names.concat(screen_names2);
	//alert(screen_names);
}

function divEngine(screen_num_arr){
	var show_visted = 1;
	if (gClear) {
		clear();
        gClear = 0;
	}
    //document.body.style.position = "absolute";
    var master_div = document.body;
    //var master_div = document.createElement('div');
    master_div.setAttribute("style", "position:absolute; margin-left:"+ ((GetWindowWidth()-950*gRatio)/2)) +";";
    //document.body.appendChild(master_div);
    //document.body.style.position = "absolute";
    var col_width = xmlDoc.getElementsByTagName("w")[0].firstChild.nodeValue;
    document.body.style.width = col_width;
    var col_height = xmlDoc.getElementsByTagName("h")[0].firstChild.nodeValue;
    document.body.style.height = col_height;
    //var col_link_dec = xmlDoc.getElementsByTagName("link_decoration")[0].firstChild.nodeValue;
    //document.body.style.textDecoration = col_link_dec;
    var col_link_color = xmlDoc.getElementsByTagName("link_color")[0].firstChild.nodeValue;
    document.body.link = col_link_color;
    var col_visited_color = xmlDoc.getElementsByTagName("visited_color")[0].firstChild.nodeValue;
    document.body.vlink = col_visited_color;
    var col_active_color = xmlDoc.getElementsByTagName("active_color")[0].firstChild.nodeValue;
    document.body.alink = col_active_color;
    var screen = xmlDoc.getElementsByTagName("screen");
    gHistory[gHistory.length] = screen_num_arr[screen_num_arr.length-1];
    if (gAdd_2_back){
        gBack_history[gBack_history.length] = screen_num_arr[screen_num_arr.length-1];
    }
    gAdd_2_back = 1;
    for (var i1=0;  i1<screen_num_arr.length; i1++){
        for (var i2=0; i2<screen.length; i2++){
            if (screen_num_arr[i1] == screen[i2].getElementsByTagName("id")[0].firstChild.nodeValue){
                var all_elements = screen[i2].getElementsByTagName("element");
                //put attributes here from the screen and collection xml tags to the documnet.body
                                    //~ try {
                            //~ var link_color = all_elements[i3].getElementsByTagName("link-color")[0].firstChild.nodeValue;
                            //~ //a_style += "link: " + link_color +"; ";
                            //~ a_tag.setAttribute("link", link_color);
                        //~ }
                        //~ catch(e){}
			            //~ try {
                            //~ var alink_color = all_elements[i3].getElementsByTagName("alink-color")[0].firstChild.nodeValue;
                            //~ //a_style += "alink: " + alink_color +"; ";
                        //~ }
                        //~ catch(e){}
			            //~ try {
                            //~ var vlink_color = all_elements[i3].getElementsByTagName("vlink-color")[0].firstChild.nodeValue;
                            //~ //a_style += "vlink: " + vlink_color +"; ";
                        //~ }
                        //~ catch(e){}
                for (var i3=0; i3<all_elements.length; i3++){
                    // has to be checked this way or changed to try-catch methods - look at it later
                    var id_match = 0;
                    var el_id = 0;
                    if (all_elements[i3].getElementsByTagName("id")[0]) {   //check for tag exist
                        if (all_elements[i3].getElementsByTagName("id")[0].firstChild){ //check for value exist
                            el_id = all_elements[i3].getElementsByTagName("id")[0].firstChild.nodeValue;    //get val
                            if (document.getElementById(el_id)) {   //check for id match
                                id_match = 1;
                            }
                        }
                    }
                    // this is the branch for rendering new tags or mod tags
                    if (id_match) {
                        var doc_div = document.getElementById(el_id);
                        var doc_a = doc_div.getElementsByTagName("a")[0];
                        // this section is to allow for on the fly changing of the type by a child and 
                        if (all_elements[i3].getElementsByTagName("type")[0]){
                            if (all_elements[i3].getElementsByTagName("type")[0].firstChild){
                                var el_type = all_elements[i3].getElementsByTagName("type")[0].firstChild.nodeValue;
                                doc_div.setAttribute("type",  el_type);
                            }
                        }
                        // start rendering the new childern to body
                        for (var i4=0; i4<all_elements[i3].childNodes.length; i4++){
                            var el = all_elements[i3].childNodes[i4];
                            var el_name = el.nodeName;
                            var tag_type = doc_div.getAttribute("type");
                            try {
                                var vis = all_elements[i3].getElementsByTagName("visible")[0].firstChild.nodeValue;
                                doc_div.style.visibility = vis;
                            }
                            catch(e){}
                            // note that the first child in Gecko is a default text node in IE it is the first child tag
                            //the if is to deal with Gecko's text child
                            if (el_name !== "#text" && el.firstChild){
    			                var el_val = el.firstChild.nodeValue;
                                switch (el_name){
					case (el_name = "attribute"): 
						var attribute_list = el_val.split("=");
						doc_div.setAttribute(attribute_list[0], attribute_list[1]);
					break
                                    case (el_name = "x"):
                                        doc_div.style.left = (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "y"):
                                        doc_div.style.top = (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "w"):
                                        doc_div.style.width = (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "h"):
                                        doc_div.style.height = (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "z"):
                                        doc_div.style.zIndex = el_val;
                                    break
                                    case (el_name = "font"):
                                        doc_div.style.fontFamily = el_val;
                                    break
                                    case (el_name = "font_size"):
                                        doc_div.style.fontSize= (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "font_weight"):
                                        doc_div.style.fontWeight= el_val;
                                    break
                                    case (el_name = "color"):
                                        doc_div.style.color= el_val;
                                    break
                                    case (el_name = "background_color"):
                                        doc_div.style.backgroundColor= el_val;
                                    break
                                    case (el_name = "border"):
                                        doc_div.style.border= el_val;
                                    break
                                    case (el_name = "border_color"):
                                        doc_div.style.borderColor= el_val;
                                    break
                                    case (el_name = "font_style"):
                                        doc_div.style.fontStyle= el_val;
                                    break
                                    case (el_name = "letter_spacing"):
                                        doc_div.style.letterSpacing= (el_val  * gRatio) + "px";
                                    break
                                    case (el_name = "text_decoration"):
                                        doc_div.style.textDecoration= el_val;
                                    break
                                    case (el_name = "link"):
                                    //for mutiple functions in function tag, with linkload
													//if  (doc_a.href ) {
						//doc_a.href += "linkLoad('" + el_val + "'); ";
					//}
					//else {
						doc_a.href = "javascript:linkLoad('" + el_val + "'); ";
					//}
					if (show_visted){
						for (var ih=0; ih<gHistory.length; ih++){
							if (gHistory[ih] == el_val){
								doc_a.style.color = col_visited_color;
								break;
							}
						}
					//alert(gHistory);
					}
                break
				case (el_name = "function"):
                    func = el_val.replace(/;/gi, ";}catch(e){} try{");
                    func = "try{" + func;
                    func = func.substring(0,(func.length-5));
					doc_a.href = "javascript:" + func;
                break
                                    case (el_name = "link_color"):
                                        doc_a.style.color = el_val;
                                    break
                                    case (el_name = "link_decoration"):
                                        doc_a.style.textDecoration = el_val;
                                    break
                                    case (el_name = "content"):
                                        switch (tag_type){
                                            case (tag_type = "html"):
						doc_a.innerHTML = el_val;
                                            break
                                            case (tag_type = "url"):
                                            var iframe_name = gIframe + "_iframe";
                                            doc_a.innerHTML = "<iframe src=" + el_val + " id=" +  iframe_name + " name=" +  iframe_name + " frameborder=0 width=100% height=100% />";
                                            gIframe += 1;
                                            break
						case (tag_type = "jpg"):
							doc_a.innerHTML = "<img src= \"./Media/Graphics/" + el_val +".jpg\" alt=\"" + content + ".jpg\" width='100%' height='100%' border=\"0\"/>";
						break
						case (tag_type = "png"):
							doc_a.innerHTML = "<img src= \"./Media/Graphics/" + el_val +".png\" alt=\"" + content + ".png\" width='100%' height='100%' border=\"0\"/>";
						break
						case (tag_type = "gif"):
							doc_div.innerHTML = "<img src= \"./Media/Graphics/" + el_val +".gif\" alt=\"" + content + ".gif\" width='100%' height='100%' border=\"0\"/>";
						break
						case (tag_type = "mov"):
                                                var objTag ="<object type=\"video/quicktime\" ";
						//debug line
						//var movieDebug = "<div style=\"position:absolute; left:10px; top:640px; width:300px; height:15px;z-index:60;\">"+ el_val + ".mov </div>";                        
                                               objTag += "data=\"./Media/Video/" + el_val +".mov\" ";
                                                try {
                                                    var width = all_elements[i3].getElementsByTagName("w")[0].firstChild.nodeValue;
                                                    objTag += "width=\"" + (width * gRatio) + "px" +"\" ";
                                                }
                                                catch(e){
                                                    objTag += "width=\"" + (parseInt(doc_div.style.width)) + "px" +"\" ";
                                                };
                                                try {
                                                    var height = parseInt(all_elements[i3].getElementsByTagName("h")[0].firstChild.nodeValue) + 17;
                                                    objTag += "height=\"" + (height * gRatio) + "px" + "\" ";
                                                }
                                                catch(e){
                                                    objTag += "height=\"" + (parseInt(doc_div.style.height)) + "px" +"\" ";
                                                };
                                                objTag +="> <param name='scale' value='ToFit'>";
                                                objTag += "</object>" 
                                        //alert (objTag);
                                                doc_div.innerHTML = objTag;
						break
						case (tag_type = "swf"):
                                                var objTag ="<object type=\"application/x-shockwave-flash\" ";
						//debug line
						//var movieDebug = "<div style=\"position:absolute; left:10px; top:640px; width:300px; height:15px;z-index:60;\">"+ el_val + ".swf </div>";                        
                                                objTag += "data=\"./Media/Video/" + el_val +".swf\" ";
                                                try {
                                                    var width = all_elements[i3].getElementsByTagName("w")[0].firstChild.nodeValue;
                                                    objTag += "width=\"" + (width * gRatio) + "px" +"\" ";
                                                }
                                                catch(e){
                                                    objTag += "width=\"" + doc_div.style.width + "px" +"\" ";
                                                };
                                                try {
                                                    var height = parseInt(all_elements[i3].getElementsByTagName("h")[0].firstChild.nodeValue) + 17;
                                                    objTag += "height=\"" + (height * gRatio) + "px" + "\" ";
                                                }
                                                catch(e){
                                                    objTag += "height=\"" + doc_div.style.height + "px" +"\" ";
                                                };
                                                objTag +="> ";
                                                objTag += "</object>" 
                                        //alert (objTag);
                                                doc_div.innerHTML = objTag;
                                            break
				                            case (tag_type = "mov2"):
                                                if (!doc_div.getElementsByTagName("object")[0]){
                                                    obj = document.createElement("object");
                                                    obj.type = "video/quicktime";
                                                    obj.width = doc_div.style.width;
                                                    obj.height = doc_div.style.height;
                                                    obj.data = "./Media/Video/" + el_val +".mov";
                                                    doc_div.appendChild(obj);
                                                }
                                                //~ var doc_obj = doc_div.getElementsByTagName("object")[0];
                                                //~ try {
                                                    //~ doc_obj.width = all_elements[i3].getElementsByTagName("w")[0].firstChild.nodeValue;
                                                //~ }
			                                    //~ catch(e){}
                                                //~ try {
                                                    //~ doc_obj.height = parseInt(all_elements[i3].getElementsByTagName("h")[0].firstChild.nodeValue) + 17;
                                                //~ }
			                                    //~ catch(e){}
                                                //~ doc_obj.data = "./Media/Video/" + el_val +".mov";
                                            break
                                        }
                                    break
                                }
			                }
                        }
                    }
		            //section if did NOT find matching element; add new divs
                    else {
                        var new_div = document.createElement('div');
			            var a_tag = document.createElement('a');
                        if (el_id){
                            new_div.setAttribute("id", el_id);
                        }
                        var div_style = "position:absolute; ";
                        var a_style = "";
                        var link = 0;
			var func = 0;
                        //var alink = 0;
                        //var vlink = 0;
			try {
                            var attribute = all_elements[i3].getElementsByTagName("attribute")[0].firstChild.nodeValue;
			    var attribute_list = attribute.split("=");
			    //alert(attribute_list[1]);
                            new_div.setAttribute(attribute_list[0], attribute_list[1]);
                        }
			catch(e){}
                        try {
                            var left = all_elements[i3].getElementsByTagName("x")[0].firstChild.nodeValue;
                            div_style += "left:" + (left * gRatio) + "px; ";
                        }
                        catch(e){}
                        try {
                            var top = all_elements[i3].getElementsByTagName("y")[0].firstChild.nodeValue;
                            div_style += "top: " + (top * gRatio) + "px; ";
                        }
                        catch(e){}
                        try {
                            var width = all_elements[i3].getElementsByTagName("w")[0].firstChild.nodeValue;
				            div_style += "width: " + (width * gRatio) + "px; ";
			            }
			            catch(e){}
			            try {
				            var height = all_elements[i3].getElementsByTagName("h")[0].firstChild.nodeValue;
				            div_style += "height: " + (height * gRatio) + "px; ";
			            }
			            catch(e){}
			            try {
				            var z = all_elements[i3].getElementsByTagName("z")[0].firstChild.nodeValue;
				            div_style += "z-index: " + z + "; ";
			            }
			            catch(e){}
                        try {
                            var color = all_elements[i3].getElementsByTagName("color")[0].firstChild.nodeValue;
                            div_style += "color: " + color +"; ";
                        }
                     catch(e){}
                        try {
                            var backgroundColor = all_elements[i3].getElementsByTagName("background_color")[0].firstChild.nodeValue;
                            div_style += "background-color: " + backgroundColor +"; ";
                        }  
                        catch(e){}
                        try {
                            var borderWidth = all_elements[i3].getElementsByTagName("border_width")[0].firstChild.nodeValue;
                            
                            var borderColor = all_elements[i3].getElementsByTagName("border_color")[0].firstChild.nodeValue;
                            div_style += "border: " + borderWidth + "px solid " + borderColor +";";
                        }    
                        catch(e){}
                        try {
                            var font = all_elements[i3].getElementsByTagName("font")[0].firstChild.nodeValue;
                            div_style += "font-family: " + font + "; ";
                        }
                        catch(e){}
                        try {
                            var fontSize = all_elements[i3].getElementsByTagName("font_size")[0].firstChild.nodeValue;
                            div_style += "font-size: " + (fontSize * gRatio) + "; ";
                        }
                        catch(e){}
                        try {
                            var fontWeight = all_elements[i3].getElementsByTagName("font_weight")[0].firstChild.nodeValue;
                            div_style += "font-weight: " + fontWeight + "; ";
                        }
                        catch(e){}
                         try {
                                var fontStyle = all_elements[i3].getElementsByTagName("font_style")[0].firstChild.nodeValue;
                                div_style += "font-style: " + fontStyle +"; ";
                        }
                        catch(e){}
			//div_style += "letter-spacing: " +"-1px; ";
                        try {
                            var letterSpace = all_elements[i3].getElementsByTagName("letter_spacing")[0].firstChild.nodeValue;
                            div_style += "letter-spacing: " + (letterSpace * gRatio) +"px; ";
                        }
                        catch(e){}
                        try {
                            var textDecor = all_elements[i3].getElementsByTagName("text_decoration")[0].firstChild.nodeValue;
                            div_style += "text-decoration: " + textDecor +"; ";
                        }
                        catch(e){}
                        try {
                            var visible = all_elements[i3].getElementsByTagName("visible")[0].firstChild.nodeValue;
                            div_style += "visibility: " + visible +"; ";
                        }
                        catch(e){}
                        try {
				link = all_elements[i3].getElementsByTagName("link")[0].firstChild.nodeValue;
			}
                        catch(e){}
			try {
				var func_temp = all_elements[i3].getElementsByTagName("function")[0].firstChild.nodeValue;
                func = func_temp.replace(/;/gi, "}catch(e){} try{");
                func = "try{" + func;
                func = func.substring(0,(func.length-5));
                }
			catch(e){}
			if (link || func) {
						if (link && func){
							var href = "javascript:linkLoad('" + link + "'); "+func;
                                                }
						else if (link){
							var href = "javascript:linkLoad('" + link + "');";
						}
						else if (func){
							var href = "javascript:"+ func;
						}
                            a_tag.setAttribute("href", href);
                            var link_dec = 0;
                            //var link_color = 0;
                            try {
                                link_color = all_elements[i3].getElementsByTagName("link_color")[0].firstChild.nodeValue;
                                a_tag.style.color = link_color;
                            }
                            catch(e){}
                            // need to add rendering based on collection/screen to body - and elments to divs
                            // some props will have to be set directly here becuase there is no way to inline a:link color
                            try {
                                link_dec = all_elements[i3].getElementsByTagName("link_decoration")[0].firstChild.nodeValue;
                            }
                            catch(e){
                            try {
                                link_dec = screen[i2].getElementsByTagName("link_decoration")[0].firstChild.nodeValue;
                            }
                            catch(e){
                            try {
                                link_dec = xmlDoc.getElementsByTagName("link_decoration")[0].firstChild.nodeValue;
                            }
                            catch(e){}}}
                            if (link_dec) a_tag.style.textDecoration = link_dec;
                            //if (link_color) 
			}
                        //this is to set what there is even if there is no type 
                        if (Gecko) new_div.setAttribute("style", div_style);
                        if (IE) new_div.style.setAttribute("cssText", div_style, 0);
                        //now add tags in the the innerHTML based on there type . . . 
                        //if (all_elements[i3].getElementsByTagName("type")[0] && all_elements[i3].getElementsByTagName("content")[0]){
                            //if (all_elements[i3].getElementsByTagName("type")[0].firstChild && all_elements[i3].getElementsByTagName("content")[0].firstChild){
                        if (all_elements[i3].getElementsByTagName("type")[0]){
                            if (all_elements[i3].getElementsByTagName("type")[0].firstChild){
                                var el_type = all_elements[i3].getElementsByTagName("type")[0].firstChild.nodeValue;
                                new_div.setAttribute("type", el_type);
                                switch (el_type){
                                    case (el_type = "html"):
				    	                try {
					                        a_tag.innerHTML = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
					                    }
					                    catch(e){}
							if (show_visted){
								for (var ih=0; ih<gHistory.length; ih++){
									if (gHistory[ih] == link){
										a_tag.style.color = col_visited_color;
										break;
									}
								}
								//alert(gHistory);
							}
                                    break
                                    case (el_type = "jpg"):
				                        try {
					                        var imgSrc = "<img src= \"./Media/Graphics/";
                                            var content = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
					                        a_tag.innerHTML = imgSrc + content +".jpg\" alt=\"" + content + ".jpg\" width='100%' height='100%' border=\"0\"/>";
				                        }
				                        catch(e){};
				                        break
                                    case (el_type = "png"):
				                        try {
					                        var imgSrc = "<img src= \"./Media/Graphics/";
					                        var content = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
					                        a_tag.innerHTML = imgSrc + content +".png\" alt=\"" + content + ".png\" width='100%' height='100%' border=\"0\"/>";
				                        }
				                        catch(e){};
                                    break
                                    case (el_type = "gif"):
				                        try {
					                        var imgSrc = "<img src= \"./Media/Graphics/";
					                        var content = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
					                        a_tag.innerHTML = imgSrc + content +".gif\" alt=\"" + content + ".gif\" width='100%' height='100%' border=\"0\"/>";
				                        }
				                        catch(e){};
                                    break
                                    case (el_type = "mov"):
                                        var objTag ="<object type=\"video/quicktime\" ";
				                       try { 
					                        var content = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
                                            objTag += "data=\"./Media/Video/" + content +".mov\" ";
                                        }
                                        catch(e){};
					case (el_type = "swf"):
                                        var objTag ="<object type=\"application/x-shockwave-flash\" ";
				                       try { 
					                        var content = all_elements[i3].getElementsByTagName("content")[0].firstChild.nodeValue;
                                            objTag += "data=\"./Media/Video/" + content +".swf\" ";
                                        }
                                        catch(e){};
                                        try {
                                            var width = all_elements[i3].getElementsByTagName("w")[0].firstChild.nodeValue;
                                            objTag += "width=\"" + width +"\" + px;";
                                            //objTag += "width=\"" + (width  * gRatio) +"\" +px;";
                                        }
                                        catch(e){};
                                        
                                        try {
                                            var height = parseInt(all_elements[i3].getElementsByTagName("h")[0].firstChild.nodeValue) + 17;
                                            objTag += "height=\"" + height + "\" + px;";
                                            //objTag += "height=\"" + (height  * gRatio) + "\" +px;";
                                        }
                                        catch(e){};
                                        objTag +="> ";
                                        //!!!!play with the embed tag now that i have it working - other wise the params will not pass
                                        //question is there a way to put the params in the object tag as an attribute?
                                        //var autoplay = all_elements[i3].getElementsByTagName("autostart")[0].firstChild.nodeValue;
                                        //var controller = all_elements[i3].getElementsByTagName("controller")[0].firstChild.nodeValue;
                                        //objTag += "<param name=\"autoplay\" value=\"" + autoplay + "\"/> <param name=\"controller\" value=\"" +controller + "\"/>";
                                        objTag += "</object>"; 
                                        //alert (objTag);
                                        new_div.innerHTML = objTag;
                                    break
                                    //alert (debugInfo + movieDebug);
                                         //var debugInfo = "<div style=\"position:absolute; left:40px; top:470px; width:120px; z-index:60;\">Screen ID: "+ screen_num_arr[screen_num_arr.length-1] + "</div>";
														
														//a_tag.innerHTML = debugInfo + movieDebug;
                                }
                            }
                        }
                        new_div.appendChild(a_tag);
                        document.body.appendChild(new_div);
                    }
                }
            }
        }
    }
    //var debugInfo = "<div style=\"position:absolute; left:10px; top:620px; width:200px;\">Screen ID: "+ screen_num_arr[screen_num_arr.length-1] + "</div>";
    //alert (debugInfo);
   //var bodyRef = document.getElementsByTagName("body")[0];     
	//bodyRef.innerHTML += debugInfo + movieDebug;

	try { 
	var after_load = xmlDoc.getElementsByTagName("after_load")[0].firstChild.nodeValue;
	eval(after_load);
	}
	catch(e){};
}
