
//URL = new String(Request.ServerVariables('URL'));

URL = new String(location.href);
URL = URL.substring(URL.indexOf('/',7), URL.lastIndexOf('/') + 1);

var RootSection = '';
var root = null;

// template functions ==========================================================

function title(full_mode) {
	var struct = Structure.element(URL);
	var title = struct.title;
	while (struct) {
		struct = struct.parent;
		if (struct && (struct.parent || full_mode))
			title = struct.short_title + ((title) ? ' / ' + title : '');
	}
	return title;
}

// navigation classes ==========================================================

function SectionItem(code, title, pic_name, pic_width, pic_height, childs) {
	this.code = code;
	this.title = title.replace(/[\[\]]/g, '');
	this.short_title = title.replace(/\[(.*)\]/, '');
	this.sub_title = '';
	if (this.short_title != this.title)
		this.sub_title = title.replace(/.*\[(\s\/\s)?(.*)\]/, '$2');
	this.childs = childs;
	this.pic_name = pic_name;
	this.pic_width = pic_width;
	this.pic_height = pic_height;
	this.onclick = null;
	this.init = SectionItemInit;
}

function SectionItemInit(parent, root) {
	this.parent = parent;
	this.url = this.code.match(/^http:/) ? this.code : (parent.url + this.code + '/');
	root.index[this.url] = this;
	if (this.childs) {
		for (var i = 0; i < this.childs.length; i++) {
			this.childs[i].init(this, root);
		}
	}
}

function SiteStructure(args) {
	this.title = '';
	this.short_title = '';
	this.parent = null;
	this.url = '/';
	this.sections = new Array();
	this.index = new Array();
	for (var i = 0; i < arguments.length; i++) {
		this.sections[i] = arguments[i];
		this.sections[i].init(this, this);
	}
	this.path = SiteStructurePath;
	this.element = SiteStructureElement;
}

function SiteStructurePath(url) {
	var point = this.element(url).parent;
	var path_str = '';
	while (point && point != this) {
		path_str = ' / ' + PathElement(point.short_title, point.url) + path_str;
		point = point.parent;
	}
	return '<a href="/">Home</a>' + path_str;
}

function SiteStructureElement(url) {
	var element = this.index[url];
	return (element) ? element : this;
}

function PathElement(title, url) {
	return (url == URL) ? '<nobr>' + title + '</nobr>' : '<a href="' + url + '"><nobr>' + title + '</nobr></a>';
}

// main menu classes ===========================================================

function BuildMainMenu()
{
	for (var i = 0; i < Structure.sections.length - 1; i++)
	{
		if(URL.indexOf(Structure.sections[i].url)==0)
			document.write('			<a href="' + Structure.sections[i].url + '" class="menu' + (i+2) + ' cur"><img src="/images/menu_' + (i+2) + '_cur.gif" alt="' + Structure.sections[i].title + '" /></a>\n');
		else		
			document.write('			<a href="' + Structure.sections[i].url + '" class="menu' + (i+2) + '"><img src="/images/menu_' + (i+2) + '.gif" alt="' + Structure.sections[i].title + '" onmouseover="javascript:this.src=\'/images/menu_' + (i+2) + '_over.gif\'" onmouseout="javascript:this.src=\'/images/menu_' + (i+2) + '.gif\'" /></a>\n');
	}
}

function BuildPageFlash()
{
	var section = Structure.element(URL);
	var flashString;
	//document.write('		<div class="flash"><img src="/images/noflash_' + section.pic_name + '.jpg" alt="" /></div>\n');

flashString = '	<div class="flash">\n';
flashString += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="828" height="150" id="company" align="middle">\n';
flashString += '<param name="allowScriptAccess" value="sameDomain" />\n';
flashString += '<param name="movie" value="/images/' + section.pic_name + '.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#666865" /><embed src="company.swf" quality="high" bgcolor="#ffffff" width="828" height="150" name="company" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n';
flashString += '</object></div>\n'

document.write(flashString+ '\n');
}

function SelectLeftMenu(id) {
    var element = document.getElementById(id);

    element.className = "lev1 lev1Off";
}

function BuildTopTags(thelist) {
    var usednums = [-1];
    var addtoflag = "true";
    var random;
    var print = "<ul>"
    for (i = 0; i < 10;) {
        random = Math.floor(Math.random() * thelist.length);
        for (c = 0; c < usednums.length; c++) {
            if (usednums[c] == random) {
                addtoflag = "false";
            }
        }
        if (addtoflag == "true") {
            print = print + '<li class="lev1"><a href="' + thelist[random][0] + '">' + thelist[random][1] + '</a></li>';
            usednums[usednums.length] = random;
            i++;
        }
        addtoflag = "true";
    }
    print = print + "</ul>";
    document.write(print);
}

function BuildPageTitleAndSubManu()
{
	var section = Structure.element(URL);
	while(section.parent != Structure)
		section = section.parent;
	document.write('				<div class="title"><img src="/images/title_' + section.code + '.gif" alt="' + section.title + '" /></div>\n');
	if(section.childs || section.sub_title)
	{
		document.write('				<div class="submenu">\n');
		if(section.sub_title)
		{
			if(URL ==  section.url)
					document.write('<a href="' + section.url + '" class="cur">' + section.sub_title + '</a>');
			else
					document.write('<a href="' + section.url + '">' + section.sub_title + '</a>');
		}
		if(section.childs)
		{
			for (var i = 0; i < section.childs.length; i++)
			{
				if(URL.indexOf(section.childs[i].url)==0)
					document.write('<a href="' + section.childs[i].url + '" class="cur">' + section.childs[i].title + '</a>');
				else
					document.write('<a href="' + section.childs[i].url + '">' + section.childs[i].title + '</a>');
			}
		}		
		document.write('				</div>\n');
	}
}
