var p = null;
var cssPath = "./css/";
var XMLFile = "./content/content.xml";
var imagePath = "./images/";
var cssFiles = [];
var allDivs = new Array();
var allPanels = new Array();
var shadowClasses = new Array();
var site_content = new Array();
var current_page = "";
var home_page = "index.php";
var contentDiv = "content";
var usingSlimBox = false;
var useJSLinks = true;
var fadeDuration = 500;

allDivs[0] = ['content', 'content', null, true, true];
allDivs[1] = ['popup', 'popup', 'popup_wrapper' , false, false];
allDivs[2] = ['links', 'links', null , false, false];
allDivs[3] = ['copyright', 'copyright', null , false, false];
allDivs[4] = ['popup_content', 'popup_content', null , true, true];
allDivs[5] = ['tip', null, null , false, false];

var currentItem = 0;

window.addEvent('domready', function() {
	if ($('loading-page') && (imageFiles && imageFiles.length > 0)) {
		$('loading-logo-light').setStyles({'opacity': '0', 'visibility': 'visible'});
		var resizeOverlay = function(){
			$('loading-page').setStyles({top: Window.getScrollTop() + 'px', height: window.getSize().y + 'px'});
		}
		resizeOverlay();
		window.addEvent('resize', function(){
			resizeOverlay();
		});
		var inc = 100 / (imageFiles.length - 1);
		var counter = 0;
		var lastPercent = 0;
		new Asset.images(imageFiles, {
			onProgress: function(count, img) {
				var percent = count * inc;
				if (percent < lastPercent) percent = lastPercent;
				if (percent > 100) percent = 100;
				lastPercent = percent
				$('loading-logo-light').setStyle('opacity', (percent < 99) ? '0.' + Math.ceil(percent) : '1');
				$('loading_text').set('text', 'Loading... (' + Math.ceil(percent) + '%)');
			},
			onComplete: function() {
				window.removeEvent('resize');
				$('loading-page').set('tween', {duration: 1000, onComplete: function(){$('loading-page').addClass('invisible')}});
				$('loading_text').set('text', 'DONE!');
				var fadeOut = function(){
					$('loading-container').fade('out');
				};
				var pageReveal = function(){
					$('loading-content').set('html', '');
					$('loading-page').fade('out');
				};
				fadeOut.delay(1000);
				pageReveal.delay(2000);
			}
		});
	}
	firstLoad();
	newPage('');
	
});

function firstLoad() {
	readXML();
	storePage();
	if ($('popup_noscript')) $('popup_noscript').setStyle('visibility', 'hidden');
	if ($('popup_wrapper')) $('popup_wrapper').setStyles({visibility: 'hidden', position: 'absolute', top: '0px', left: '0px', margin: '0', width: 'auto'});
	var tickerReverse = (Browser.Engine.trident && Browser.Engine.version < 5) ? false : true;
	if ($('TickerHorizontalA')) {
		var lineA = new Ticker('TickerHorizontalA', {speed:18000,delay:1000,layout:'horizontal',reverse: tickerReverse});
		var glowItemsA = new Glower('#TickerHorizontalA li', {speedin: 0,speedout: 2000, delay: 0, style: 'opacity', valueto: '1', valuefrom: '.1', overlap: true});
	}
	if ($('TickerHorizontalB')) {
		var lineB = new Ticker('TickerHorizontalB', {speed:6000,delay:1000,layout:'horizontal'});
		var glowItemsB = new Glower('#TickerHorizontalB li', {speedin: 0,speedout: 2000, delay: 0, style: 'opacity', valueto: '1', valuefrom: '.1', overlap: true});
	}
	if ($('TickerHorizontalC')) {
		var lineC = new Ticker('TickerHorizontalC', {speed:12000,delay:1000,layout:'horizontal',reverse: tickerReverse});
		var glowItemsC = new Glower('#TickerHorizontalC li', {speedin: 0,speedout: 2000, delay: 0, style: 'opacity', valueto: '1', valuefrom: '.1', overlap: true});
	}
}

function newPage(p) {
	fixImg();
	changeContent(p);
	getActivePage();
	fixLinks();
	swapHoverImage();
	slidePanels();	
	var toolTips = new newTips($$('.map-tip'), {
       	className: 'buttontips',
		offsets: {x: -30, y: 30},
		tlClass: 'tip-top-left',
		trClass: 'tip-top-right',
		blClass: 'tip-bottom-left',
		brClass: 'tip-bottom-right',
		fadeDuration: 500,
		closeClick: true
    });
    
    var toolTips2 = new newTips($$('.button-tip'), {
       	className: 'buttontips',
		offsets: {x: -30, y: 30},
		tlClass: 'tip-top-left',
		trClass: 'tip-top-right',
		blClass: 'tip-bottom-left',
		brClass: 'tip-bottom-right',
		fadeDuration: 500,
		showDelay: 2000,
		closeClick: true
    });
    
    if ($('elite_badge') && !$('elite_badge').retrieve('processed')) {
		$('elite_badge').store('processed', true).set('tween', {duration: 3000, onComplete: function(){
			if ($('elite_badge').getStyle('opacity') < 1) {
				$('elite_badge').fade(1);
			} else {
				$('elite_badge').fade(0.5);
			}
		}}).fade(0.5);
	}
    
}

function changeContent(p) {

}


var Glower = new Class({
	Implements: [Options],
				
	options: {
		speedin: 1000,
		speedout: 1000,
		delay: 0,
		hold: 0,
		valueto: '#ffffff',
		valuefrom: '#000000',
		style: 'color',
		overlap: false,
		transition: Fx.Transitions.Expo.easeInOut,
		onComplete: Class.empty,
		onStart: Class.empty
	},
	
	initialize: function(el, options){
		this.setOptions(options);
		this.items = $$(el);
		var thisStyle = this.options.style;
		var thisValue = this.options.valuefrom;
		this.items.each(function(el){
			el.setStyle(thisStyle, thisValue);
		});

		this.current = Math.floor(Math.random() * this.items.length);
		this.next();
	},
	
	next: function() {
		var lastValue = this.options.valuefrom;
		var fadeTimer = this.options.speedout;
		var glowStyle = this.options.style;
		var fadeTransition = this.options.transition;
		var fadeDelay = this.options.hold;
		if (this.options.speedin > 0 && this.options.speedout > 0) {
			this.fx = new Fx.Tween(this.items[this.current], {
				transition: this.options.transition,
				duration: this.options.speedin,
				onComplete: function(el) {
					this.fxb = new Fx.Tween(el, { duration: fadeTimer, transition: fadeTransition }).start(glowStyle, lastValue);
				}
			});
		} else if (this.options.speedout > 0) {
			this.items[this.current].setStyle(this.options.style, this.options.valueto);
			this.fx = new Fx.Tween(this.items[this.current], {
				transition: this.options.transition,
				duration: this.options.speedout
			}).start(glowStyle, lastValue);
		} else if (this.options.speedin > 0) {
			this.fx = new Fx.Tween(this.items[this.current], {
				transition: this.options.transition,
				duration: this.options.speedin,
				onComplete: function(el) {
					el.setStyle(glowStyle, lastValue);
				}
			});
		} else {
		
		}
		
		if (this.options.speedin > 0) this.fx.start(this.options.style, this.options.valueto);
		this.last = this.current;
		this.current = Math.floor(Math.random() * this.items.length);
		if (this.options.overlap) {
			var nextTimer = (this.options.delay + this.options.hold + this.options.speedin + this.options.speedout) /2;
		} else {
			var nextTimer = this.options.delay + this.options.hold + this.options.speedin + this.options.speedout;
		}
		this.next.bind(this).delay(nextTimer);
			
	}

});


var Ticker = new Class({
				Implements: [Options, Events],
				
				options: {
						speed: 1000,
						delay: 5000,
						layout: 'horizontal',
						reverse: false,
						onComplete: Class.empty,
						onStart: Class.empty
				},
				
				initialize: function(el, options){
					this.setOptions(options);
					this.el = $(el);
					if (!this.el.retrieve('tickerdone')) {
					this.el.store('tickerdone', '1');
	
					this.items = this.el.getElements('li');
					var w = 0;
					var h = 0;
					if(this.options.layout == 'horizontal') {
						h = this.el.getSize().y; 
						this.items.each(function(li,index) {
							w += li.getSize().x; 
						});
					} else {
						w = this.el.getSize().x;
						this.items.each(function(li,index) {
							h += li.getSize().y;
						});
					}
					

					
					if (!this.options.reverse) {
					
						this.el.setStyles({ 
							position: 'absolute',
							top: 0,
							left: 0,
							width: w,
							height: h,
							overflow: 'hidden'
						});
					
					} else {
					
						this.el.setStyles({ 
							position: 'absolute',
							bottom: 0,
							right: 0,
							width: w,
							height: h,
							overflow: 'hidden'
						});
					
					}

					
					
					this.fx = new Fx.Tween(this.el, {duration:this.options.speed,onComplete:function() { 
						var i = this.current;
						
						if (!this.options.reverse) {
							this.items[i].inject(this.el, 'bottom');
							this.el.setStyles({
								left:0,
								top:0
							});
						
						} else {
							this.items[i].inject(this.el, 'top');
							this.el.setStyles({
								right:0,
								bottom:0
							});
						
						}
						
						if (this.options.reverse) {
							this.current--;
							if (this.current < 0) this.current = this.items.length - 1;
						} else {
							this.current++;
							if (this.current >= this.items.length) this.current = 0;
						}
						
						var pos = this.items[this.current];
						if (this.options.layout == 'horizontal') {
							if (!this.options.reverse) {
								this.fx.start('left', '-' + pos.getSize().x);
							} else {
								this.fx.start('right', '-' + pos.getSize().x);
							}
						} else {
							this.fx.start('top', '-' + pos.offsetTop);
						}
						
					}.bind(this)});
					
					this.current = (this.options.reverse) ? this.items.length-1 : 0;
					var pos = this.items[this.current];
					if (this.options.layout == 'horizontal') {
						if (!this.options.reverse) {
							this.fx.start('left', '-' + pos.getSize().x);
						} else {
							this.fx.start('right', '-' + pos.getSize().x);
						}
					} else {
						this.fx.start('top', '-' + pos.offsetTop);
					}
					
					}
				},
				
				next: function() {
					var pos = this.items[this.current];
					if (this.options.layout == 'horizontal') {
						if (!this.options.reverse) {
							this.fx.start('left', '-' + pos.getSize());
						} else {
							this.fx.start('right', '-' + pos.getSize().x);
						}
					} else {
						this.fx.start('top', '-' + pos.offsetTop);
					}

				}

			});


