System.useCodePage = true;
XML.prototype.ignoreWhite = true;

// CLASSES DEFINITIONS
// ==== "menu" class definition  =====
// includs attributes and methids to make the menu up in general
menu.prototype = new MovieClip();
function menu() {};

// attributes
	menu.xmlMenu = null;
	menu.titles = null; // the major object for storing menu info
	// intervals
	menu.prototype.intervalBetweenTitleAndFirstItem = -2;
	menu.prototype.intervalBetweenLastItemAndNextTitle = 0;
	menu.prototype.intervalBetweenItems = -4;
	menu.prototype.itemLeftIndent = 10;
	// movies base names
	menu.prototype.titlesBaseName = "title_";
	menu.prototype.itemBaseName = "item_";
	// storing the first free depth level for new attached movie
	menu.prototype.freeDepthLevel = 100;

	
	
// methods
// ----------- loadData()
// load xml menu data from xml-file
menu.prototype.loadData = function() {
	this.xmlMenu = new XML;
	this.xmlMenu.load("menu.xml");
	var pointToThis = this;
	this.xmlMenu.onLoad = function(success) {
		if(success) {
			pointToThis.make();
		}
	}
}

// ----------- parseXml()
// load data from xml-object to array of objects 
menu.prototype.parseXml = function(menuXml) {
	objCollection = menuXml.firstChild.firstChild;
	this.titles = new Array();
	while (objCollection.hasChildNodes()) {
		var titleId = objCollection.attributes["id"];
		var titleLable = objCollection.attributes["label"];
		var gapBefore = objCollection.attributes["gapBefore"];
		// load menu-title data
		this.titles[titleId] = new Object();
		this.titles[titleId].items = new Array();
		this.titles[titleId].label = titleLable;
		this.titles[titleId].gapBefore = gapBefore;

					
		for(i=0; i 0) {
		var previousItem = this[this.itemBaseName + (titleId-1) + (this.titles[titleId-1].items.length-1)];
		var titleY = previousItem._y + previousItem._height + this.intervalBetweenLastItemAndNextTitle + this.strToNum(this.titles[titleId].gapBefore);
	}
	else {
		var titleY = this.strToNum(this.titles[titleId].gapBefore);
	}
	
	// place title
	this.attachMovie("title", titleName, this.freeDepthLevel++, {_x: titleX, _y: titleY});
	// write title label
	this[titleName].label.autoSize = true;
	this[titleName].label.text = "  " + this.titles[titleId].label;
	// set title bar width accroding to label text width 
	this[titleName].bar._width = Math.floor(this[titleName].label.textWidth + this[titleName].label.textWidth*this[titleName].bar._xscale/350);
	var barW = Math.floor(this[titleName].bar.barMask._width * this[titleName].bar._xscale/100);
	// add the title right oval bit
	this[titleName].bit.attachMovie("titleBit", titleBitName, 1);
	this[titleName].bit._x = this[titleName].bar._x + barW;
}


// ----------- makeItem()
// generate a menu item
	// input vars:
	// titleId - a title id (0,1,2..) a title id (see xml-file)
	// itemId (0,1,2..) an item id inside the group defined by the titleId
menu.prototype.makeItem = function(itemId, titleId) {
		// input vars:
	// title id (0,1,2..)
	var title = this[this.titlesBaseName + titleId];
	var itemName = this.itemBaseName + titleId + itemId;
	// getting x,y coordinats for new item
	var itemX = this.itemLeftIndent;
	if(itemId > 0) {
		var previousItem = this[this.itemBaseName + titleId + "" + (itemId-1)];
		var itemY = previousItem._y + previousItem._height + this.intervalBetweenItems + this.strToNum(this.titles[titleId].items[itemId].gapBefore);
	}
	else {
		var itemY = title._y + title._height + this.intervalBetweenTitleAndFirstItem + this.strToNum(this.titles[titleId].items[itemId].gapBefore);
	}
	
	// place item
	this.attachMovie("item", itemName, this.freeDepthLevel++, {_x: itemX, _y: itemY});

	// write item label
	this[itemName].labelMovie.label.autoSize = true;
	this[itemName].labelMovie.label.text = this.titles[titleId].items[itemId].label;
	
	// url assign
	this[itemName].href = this.titles[titleId].items[itemId].href;
	
	// make blinking width
	this[itemName].blink.blinkMovieToResize._width = this[itemName].labelMovie.label.length * ((this[itemName].labelMovie.label.textWidth + Math.round(Math.sqrt(this[itemName].labelMovie.label.length))*10)/ this[itemName].labelMovie.label.length);
	this[itemName].blink.blinkMovieToResize._x -= this[itemName].labelMovie.label.length;
}

//--- strToNum()
// convert a string of digits to number 
menu.prototype.strToNum = function(str) {
	var num = 0;
	var arr = str.split("");
	for(var i=0; i