function expand(theli)
{
	var item = document.getElementById(theli);
	var childCount = item.getElementsByTagName('ul').length;
		
	if(childCount > 0)
	{
		item.style.width=item.offsetWidth;
		item.style.overflow='hidden';
		item.lastChild.style.position='relative';
		item.lastChild.style.top='0px';
		item.lastChild.style.visibility='visible';
	}

}
		
function removechild(theli)
{	
	var item = document.getElementById(theli);
	var childCount = item.getElementsByTagName('ul').length;
	
	if(childCount > 0)
	{
		item.lastChild.style.visibility='hidden';
	}
}

function expandsub(theli)
{
	var item = document.getElementById(theli);
	var childCount = item.getElementsByTagName('ul').length;
	
	if(childCount > 0)
	{
		item.style.overflow='hidden';
		item.lastChild.style.position='relative';
		item.lastChild.style.top='-42px';
		item.lastChild.style.left=(item.offsetWidth-5);
		item.lastChild.style.visibility='visible';
	}

}
		
function removechildsub(theli)
{	
	var item = document.getElementById(theli);
	var childCount = item.getElementsByTagName('ul').length;

	if(childCount > 0)
	{
		item.lastChild.style.visibility='hidden';
	}
}


/* MOOTOOLS STUFF*/
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
ie6 = (version >= 5.5 && version < 7);

function ieHack()
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()

		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			
			img.outerHTML = strNewHTML;
			i--;
		}
	}
}

 
var Stage = new Class({

	initialize: function(options) {
		options = options || {};

		this.stage = options.stage;
		this.slides = options.slides;
		this.container = options.container;

		this.content = [];
		this.items = this.slides.getElements('li');
		this.tabs = {};
		this.max = this.items.length - 1;
		this.current = 0;

		this.timer = null;
		this.timeout = 10000;
		this.paused = false;
		if (ie6){
		  ieHack()
	  }
	},

	load: function() {

		this.items.each(function(item) {

			var header = item.getElement('h3');
			
			
			this.content[this.content.length] = {
				'header' : header.get('text'),
				'html': item.get('html') + ''
			};

		}, this);

		this.container.empty();

		// create new container
		this.slides = new Element('div', {
			'id': 'c0',
			'class': 'slides',
			'html': this.content[this.current].html
		});

		// add to stage
		this.container.grab(this.slides);

		// show tabs
		this.showtabs(this.current);

		// start timer
		this.start();

	},

	start: function() {
		// set timer
		this.timer = this.play.delay(this.timeout, this);
	},

	play: function() {
		// next key
		var key = (this.current == this.max) ? 0 : this.current + 1 ;

		// show slide
		this.show(key);

		// set timer
		this.timer = this.play.delay(this.timeout, this);

		// set stauts
		this.paused = false;
	},

	pause: function() {
		// clear timer
		this.timer = $clear(this.timer);

		// set status
		this.paused = true;
	},

	show: function(key) {

		// same key return
		if(this.current == key) {
			return;
		}

		// set new key
		this.current = key;
		
		// create new container
		var slide = new Element('div', {
			'id': 'c' + this.current,
			'class': 'slides',
			'html': this.content[this.current].html,
			'styles': {
				'left': 940 // start elemnt off screen
			}
		});

		// add to stage
		this.container.grab(slide);

		// move slides
		var options = {
			'link': 'ignore',
			'transition': Fx.Transitions.Linear
		};
		var fx1 = new Fx.Tween(slide, options);
		fx1.start('left', 0);

		var fx2 = new Fx.Tween(this.slides, options);
		fx2.start('left', -940);

		// replace holder
		fx2.addEvent('complete', function(){

			this.slides.destroy();
			this.slides = slide;

		}.bind(this));

		// show tabs
		this.showtabs();
		
	},

	showtabs: function() {

		if($chk($('tabs'))) {
			$('tabs').destroy();
		}
		
		// tabs
		this.tabs = new Element('ul', {
			'id': 'tabs'
		});

		this.items.each(function(item, index) {

			var li = new Element('li');

			// class name
			var classes = [];

			if(index == 0) {
				classes.push('first');
			}
			if(index == this.current) {
				classes.push('selected');
			}
			if(index == (this.items.length - 1)) {
				classes.push('last');
			}

			var a = new Element('a', {
				'href': '#',
				'text': this.content[index].header,
				'class': classes.join(' '),
				'events': {

					'click': function(e) {

						this.show(index);
						this.pause();
						e.stop();

					}.bind(this)/*,

					'mouseenter': function(e) {

						var c = e.target.className;
						// make sure its selected
						if(c.indexOf('selected') != -1) {
							if(!this.paused) this.pause();
						}

					}.bind(this),

					'mouseleave': function(e) {

						var c = e.target.className;
						// make sure its selected
						if(c.indexOf('selected') != -1) {
							if(this.paused) {
								this.start();
							}
						}
						
					}.bind(this)*/

				}
			});

			li.grab(a);
			this.tabs.grab(li);

		}, this);

		this.stage.grab(this.tabs);

	}

});

var Font = new Class({
	initialize: function(src, options) {
		options = options || {};

		this.swf = new Swiff(src, {
			width: (options.width) ? options.width : 100 ,
			height: (options.height) ? options.height : 20,
			vars: options
		});
	},
	replace: function(id) {
		var element = $(id);
		this.swf.replaces(element);
	}
});




function myAddEvent( obj, type, fn ) {  

   if (obj.addEventListener) {   
        obj.addEventListener( type, fn, false );   
    }   
    else if (obj.attachEvent) {   
        obj["e"+type+fn] = fn;   
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }   
        obj.attachEvent( "on"+type, obj[type+fn] );   
    }   
    else {   
        obj["on"+type] = obj["e"+type+fn];   
    }   
}
		
