var Mnet = new Class();			
	
// Use this method for any duration to allow transitions to be turned off
Mnet.showTransitions = true;
Mnet.getDuration = function(duration) {
	return Mnet.showTransitions && $defined(duration) ? duration : 0;
};
	
/* Flash class */
Mnet.Flash = new Class();
Mnet.Flash.installed = (Browser.Plugins.Flash.version >= 6);
Mnet.Flash.object = function(container, src, width, height, params, vars, events) {
	if(!Mnet.Flash.installed)
		return null;

	if(!$defined(Mnet.rootUrl))
		Mnet.rootUrl = '';

	if(!$defined(params)) params = {};
	if(!$defined(vars)) vars = {};

	var options = {
	    width: width,
	    height: height,
		container: container,
	   	params: params, 
	    vars: vars,
		events: events
	};

	if(!src.match(/^\w+:\/\/|^\//))
		src = Mnet.rootUrl + 'flash/' + src + '.swf';
	
	if(params.makeVisible && $(container).getStyle('visibility') == 'hidden')
		$(container).setStyle('visibility', 'visible');

	var o = new Swiff(src, options);
	return o;
}



/* Debug class */
Mnet.Debug = new Class();

Mnet.Debug.init = function() {
	if(!$defined(Mnet.Debug.el)) {
		Mnet.Debug.el = new Element('div', { id:'debug', style:'position:fixed; top:0px; left:0px; background-color:#FFFFFF; color:#000; ' +
			' width:200px; height:12px; z-index:10; text-align:left; line-height:12px; font-size:10px;' }); 
			
		var elClose = new Element('a', { href:'javascript:Mnet.Debug.clear();', html:'[X]', style:'position:absolute; right:0px; color:#000;' });
		Mnet.Debug.el.appendChild(elClose);

		Mnet.Debug.elText = new Element('div', {  });
		Mnet.Debug.el.appendChild(Mnet.Debug.elText);
			
		document.body.appendChild(Mnet.Debug.el);
	}
	else
		Mnet.Debug.el.setStyle('visibility', 'visible');
}
	
Mnet.Debug.append = function(txt) {
	Mnet.Debug.init();	
	var ctxt = Mnet.Debug.elText.get('html');
	if(ctxt != '')
		txt = ctxt + '<br/>' + txt;
		
	Mnet.Debug.el.setStyle('height', Mnet.Debug.elText.getStyle('height').toInt() + 12);
	
	Mnet.Debug.set(txt);
};
var _d = Mnet.Debug.append;

Mnet.Debug.set = function(txt) {
	Mnet.Debug.init();
	Mnet.Debug.elText.set('html', txt);
};

Mnet.Debug.clear = function() {
	Mnet.Debug.init();
	Mnet.Debug.set('');
	Mnet.Debug.el.setStyle('height', 12);
	Mnet.Debug.el.setStyle('visibility', 'hidden');
};

Mnet.SerialImageLoader = new Class({
	imageIndex: 0,
	
	initialize: function(options) {
		if(!$defined(options))
			options = {}

		this.onProgress = $defined(options.onProgress) ? options.onProgress : $empty;
		this.onComplete = $defined(options.onComplete) ? options.onComplete : $empty;
	},
	
	addImages: function(images) {
		if(!$defined(this.imageArray))
			this.imageArray = [];
		
		this.imageArray.extend(images);
	},
	
	load: function() {
		this.imageCount = this.imageArray.length;
		this.imageIndex = -1;
		
		// Call onload method - first time will init and load first image
		this.onLoad();
	},
	
	onLoad: function() {
		// First load call? init images array and skip event calling
		if(!$defined(this.images))
			this.images = [];
		else {
			this.onProgress(this.images[this.imageIndex], this.imageIndex, this.imageCount);
		}
		
		// More images to load?
		if(++this.imageIndex < this.imageCount) {
			var image = this.imageArray[this.imageIndex];
			var src;
			if($type(image) == 'string')
				src = image;
			else if(image.tagName == 'img')
				src = image.src;
			else
				src = image.getElement('img').src;

			this.images.push(new Asset.image(src, {onload:this.onLoad.bind(this)}));
		}
		else
			this.onComplete(this.imageCount);
	}
});

Element.implement({
	getFullHeight: function() {
		var value = this.retrieve('Element:fullHeight');
		if(!$defined(value)) {
			value = this.offsetHeight.toInt() + 
				this.getStyle('marginTop').toInt() +
				this.getStyle('marginBottom').toInt() +
				this.getStyle('paddingTop').toInt() +
				this.getStyle('paddingBottom').toInt();
			this.store('Element:fullHeight', value);
		}
		return value;
	},
	
	getFullWidth: function() {
		var value = this.retrieve('Element:fullWidth');
		if(!$defined(value)) {
			//_d(this.getStyle('borderRightWidth'));
			value = this.offsetWidth.toInt() + 
			this.getStyle('marginLeft').toInt() +
			this.getStyle('marginRight').toInt() +
			this.getStyle('paddingLeft').toInt() +
			this.getStyle('paddingRight').toInt()/* +
			this.getStyle('borderLeftWidth').toInt() +
			this.getStyle('borderRightWidth').toInt()*/;
			this.store('Element:fullWidth', value);
		}
		return value;					
	}
});
	
Mnet.Gallery = new Class({
	Implements: Options,
	
	options: {
		holderClass:'image-holder',
		thumbnailsClass:'thumbnails',
		fadeDuration:700,
		display:0,
		thumbFaded:0.5,
		thumbFadeDuration:200,
		addHolderLink:true,
		imageElements:'img',
		align:'left'
	},
	
	initialize: function(holder, thumbnails, thumbnailHolder, options) {
		this.setOptions(options);
		
		this.holder = holder;
		this.images = holder.getElements(this.options.imageElements);
		
		if($defined(thumbnails))				
			this.thumbnails = thumbnails.getElements(thumbnailHolder);				
		
		this.currentIndex = -1;
		this.maxIndex = this.images.length - 1;
		
		if(this.maxIndex < 0)
			return;
		
		var align = (this.options.align == 'right') ? 'right' : 'left';
		
		this.images.each(function(item, index) {
			item = item.setStyles({
				position:'absolute',
				//left:'0px',	
				top:'0px',
				opacity:0
			});
			item.setStyle(align, '0px');
			item.set('tween', {'link':'cancel','duration': Mnet.getDuration(this.options.fadeDuration)});
			
			if(item.get('tag') == 'a' || item.getParent().get('tag') == 'a')
				this.options.addHolderLink = false;
		}, this);
		
		// If images don't already have links on them, add next() link to holder
		if(this.options.addHolderLink) {
			this.holder.setStyles({
				cursor:'pointer'
			}).addEvent('click', this.next.bind(this));
		}
				
		if($defined(this.thumbnails)) {
			this.thumbnails.each(function(item, index) {
				item
				.setStyles({cursor:'pointer','opacity':this.options.thumbFaded})
				.set('tween', {'link':'cancel','duration': Mnet.getDuration(this.options.thumbFadeDuration)})
				.addEvent('click', function() {
					this.display(index);	
				}.bind(this))
				.addEvent('mouseover', function() {
					item.tween('opacity', 1);
				}.bind(this))
				.addEvent('mouseout', function() {
					if(index != this.currentIndex)
						item.tween('opacity', this.options.thumbFaded);
				}.bind(this));
			}, this);
		}
		
		// Make sure image is loaded before displaying
		var img = this.images[this.options.display];
		if(img.get('tag') != 'img')
			img = img.getElement('img');
		if(img.complete) this.display(this.options.display);
		else img.onload = this.display.pass(this.options.display, this);
	},
	
	display: function(index) {
		if(this.currentIndex == index)
			return;
		
		// Update holder height		
		this.holder.setStyle('height', this.images[index].getFullHeight());
				
		if(this.currentIndex >= 0) {
			this.images[this.currentIndex].tween('opacity', 0);
			if($defined(this.thumbnails))
				this.thumbnails[this.currentIndex].tween('opacity', this.options.thumbFaded);
		}
		
		this.images[index].tween('opacity', 1);
		if($defined(this.thumbnails))
			this.thumbnails[index].set('opacity', 1);
		
		this.currentIndex = index;
	},
	
	prev: function() {
		var index = this.currentIndex - 1;
		this.display(index < 0 ? this.maxIndex : index);
	},
	
	next: function() {
		var index = this.currentIndex + 1;
		this.display(index > this.maxIndex ? 0 : index);
	},
	
	link: function() {
		var item = this.images[this.currentIndex];
		var parent = item.getParent();
		
		if(parent.get('tag') == 'a') {
			if(parent.hasEvent('click'))
				parent.fireEvent('click');
			else {
				var href = parent.href;
				if($type(href) == 'function')
					(href)();
				else if($type(href) == 'string' && href != '')
					document.location.href = href;
			}
		}
	}
});

Mnet.Gallery2 = new Class({
	Implements: Options,
	
	options: {
		thumbnailsClass:'thumbnails',
		fadeDuration:700,
		display:0,
		thumbFaded:0.5,
		thumbFadeDuration:200,
		imageElements:'img',
		align:'left',
		currentIndex:-1
	},
	
	initialize: function(holder, thumbnails, thumbnailHolder, options) {
		this.setOptions(options);
		
		this.holder = holder;
		this.thumbnails = thumbnails.getElements(thumbnailHolder != null ? thumbnailHolder : 'a');				
		
		this.currentIndex = this.options.currentIndex;
		this.maxIndex = this.thumbnails.length - 1;
		if(this.maxIndex < 0)
			return;

		this.thumbnails.each(function(item, index) {
			item
			.setStyles({cursor:'pointer','opacity':this.options.thumbFaded})
			.set('tween', {link:'cancel', duration:Mnet.getDuration(this.options.thumbFadeDuration)})
			.addEvent('click', function(e) {
				e.stop();
				this.display(index, item);	
			}.bind(this))
			.addEvent('mouseover', function() {
				item.tween('opacity', 1);
			}.bind(this))
			.addEvent('mouseout', function() {
				if(index != this.currentIndex)
					item.tween('opacity', this.options.thumbFaded);
			}.bind(this));
		}, this);

		if(this.currentIndex >= 0)
			this.thumbnails[this.currentIndex].set('opacity', 1);
		
		// Init current image if any
		var currentImg = this.holder.getElement(this.options.imageElements);
		if(currentImg != null)
			this.initImage(currentImg, true);
	},
	
	initImage: function(img, first) {
		img.setStyles({
			position:'absolute',
			//left:'0px',	
			top:'0px',
			opacity:first ? 1 : 0
		});
		img.setStyle(this.options.align, '0px');
		img.set('tween', {link:'cancel', duration:Mnet.getDuration(this.options.fadeDuration)});
	},
	
	display: function(index, item, currentIndex) {
		// If current item already selected or current index has change while image was loading
		if(this.currentIndex == index || (currentIndex != null && this.currentIndex != currentIndex))
			return;

		// Create new image element
		var img = new Element('img', {src:item.getProperty('href')});
		
		// Make sure image is loaded before displaying
		if(!img.complete) {
			currentIndex = this.currentIndex;
			img.onload = function() { this.display(index, item, currentIndex); }.bind(this);
		}
		else {
			var prevImg = this.holder.getElement(this.options.imageElements);
			
			this.initImage(img);
			this.holder.appendChild(img);

			if(this.currentIndex >= 0)
				this.thumbnails[this.currentIndex].tween('opacity', this.options.thumbFaded);
		
			if(prevImg != null) {
				var prevTween = new Fx.Tween(prevImg, {
					duration: Mnet.getDuration(this.options.fadeDuration), 
					link:'cancel'
				});
				prevTween.start('tween', 0, 1).chain(
					function() { try { this.holder.removeChild(prevImg); } catch(e) {}; }.bind(this)
				);
			}
	
			img.tween('opacity', 1);
			
			this.thumbnails[index].set('opacity', 1);
			this.currentIndex = index;
		}
	},
	
	prev: function() {
		var index = this.currentIndex - 1;
		this.display(index < 0 ? this.maxIndex : index);
	},
	
	next: function() {
		var index = this.currentIndex + 1;
		this.display(index > this.maxIndex ? 0 : index);
	}
});

Mnet.Form = new Class();
Mnet.Form.itemValue = function(item) {
	if(!item)
		return null;
	else if(item.options)
		return (item.selectedIndex >= 0) ? item.options[item.selectedIndex].value : "";
	else if(item.length) {
		i = 0;
		while(i < item.length && !item[i].checked)
			i++;
		return (i < item.length) ? item[i].value : "";
	}
	else if(item.type == 'checkbox' || item.type == 'radio')
		return item.checked ? item.value : '';
	else
		return item.value;
};

Mnet.Slider = new Class({
	Implements: Options,
	
	options: {
		duration: 1000,
		transition: Fx.Transitions.Pow.easeOut,
		delay:-1,
		link: 'cancel',
		reflect: {
			opacity:0.6,
			height:0.33
		}
	},
	
	initialize: function(slider, items, options) {
		this.setOptions(options);
		
		this.elSlider = $(slider);
		this.elFrame = this.elSlider.getElement('.slider');
		this.elBody = this.elSlider.getElement('.slider-body');
		this.elTracker = this.elSlider.getElement('.slider-tracker');
		this.elKnob = this.elSlider.getElement('.slider-knob');
		this.elLeft = this.elSlider.getElement('.slider-left');
		this.elRight = this.elSlider.getElement('.slider-right');
		
		// Calc width
		if($type(items) == 'string')
			items = this.elBody.getElements(items);
		
		this.items = items;
		this.widths = {};
		this.positions = {};
		this.loaded = 0;
		
		//this.bodyWidth = 0;
		
		this.scroller = new Fx.Morph(this.elBody, { 
			link: this.options.link,
			duration: Mnet.getDuration(this.options.duration), 
			transition: this.options.transition
		});

		// Go through each item and get width + add onload event to image
		this.items.each(function(item, index) {
			// Find image
			var img = item.getElement('.image img');
			if(!img.complete) 
				new Asset.image(img.src, { onload: this.onImageLoad.pass([img, index], this) });
			else {
				//this.widths[index] = img.width;
				this.onImageLoad(img, index);
			}
		}, this);
	},
	
	onImageLoad: function(img, index) {
		this.loaded++;

		//_d(index);
		//this.items[index].setStyle('width', this.widths[index]);
		this.widths[index] = this.items[index].getFullWidth('width');
		
		//this.bodyWidth += this.widths[index];
		//this.elBody.setStyle('width', this.bodyWidth);
		
		if(this.options.reflect)
			img.reflect(this.options.reflect);
		
		if(this.loaded == this.items.length)
			this.onLoaded();
	},
	
	// All loaded, set up slider
	onLoaded: function(reload) {
		// Get index max
		var widthCont = this.elSlider.getStyle('width').toInt();
		var width = 0;

		var i = this.items.length - 1;
		if(i > 0) {
			// Remove any right margin on last item
			//this.items[i]
			
			do { 
				width += this.widths[i];
				
				if(width <= widthCont)
					i--;
					
				//_d(i + ":" + this.widths[i] + " + " + width + " :" + widthCont);
			} while(width <= widthCont && i > 0);
		}
		
		// Calc positions
		if(!reload) {
			var pos = 0;
			for(var j = 0; j < this.items.length; j++) {
				var w = this.widths[j];
				this.positions[j] = pos;
				pos += w;
			}
		}
				
		// Set knob width
		var count = this.items.length;
		var max = i + 1;
		width = (count - max) / count;

		//_d(count + ":" + max);
		
		this.elKnob.setStyle('width', Math.round(width * 100) + '%');
		
		var step = (reload) ? this.slider.step : 0;
		this.slider = new Slider(this.elTracker, this.elKnob, {
			range: [0, max],
			wheel: true,
			snap: true,
			//onStart: this.onStart.bind(this),
			//onTick: this.onTick.bind(this),
			//onComplete: this.onComplete.bind(this),
			onChange: this.onChange.bind(this)
		});
		this.slider.set(Math.min(step, this.slider.options.range[1]));
		
		// Add links to left / right buttons
		if(!reload) {
			if(this.elLeft)
				this.elLeft.addEvent('click', this.onStep.pass(-1, this));
			if(this.elRight)
				this.elRight.addEvent('click', this.onStep.pass(1, this));
		}
		
		this.ready = true;
		//if(this.options.delay > 0)	
		//	this.play();
	},
	
	reload: function() {
		var play = this.playing();
		if(play)
			this.pause();
		this.onLoaded(true);
		if(play)
			this.play();
	},
	
	/*
	onStart: function() {
		//this.borderFx = this.borderFx || this.element.tween('border').start('#ccc');
		//Mnet.Debug.append('s');
	},
	onTick: function(pos) {
		_d(pos);
		//Mnet.Debug.append(this.slider.step);
		this.elKnob.setStyle('left', pos);
	},
	onComplete: function() {
		//alert(this.step + ":");
		//this.element.morph('left').start(10);
		//Mnet.Debug.append('d');
	},
	*/
	onChange: function(pos) {
		var item = this.items[this.slider.step];
		pos = this.positions[this.slider.step];
		
		this.scroller.start({left:-pos});
	},
	onStep: function(step, wrap) {
		var newStep = this.slider.step + step;
		if(wrap) {
			var min = this.slider.options.range[0];
			var max = this.slider.options.range[1];
			
			if(newStep > max)
				newStep = min;
			else if(newStep < min)
				newStep = max;
		}
		this.slider.set(newStep);
	},

	playPause: function() {
		if(this.playing())
			this.pause();
		else
			this.play();
	},
	
	playing: function() { return (this.timerId != null); },
	
	play: function() { 
		if(!this.ready) return;
		
		// Only scroll if needed
		if(!this.playing())
			this.timerId = this.onStep.periodical(this.options.delay, this, [1, true]);
	},

	pause: function() { 
		if(!this.ready) return;
			
		if(this.playing()) {
			$clear(this.timerId);
			this.timerId = null;
		}
	},
	
	next: function() { 
		if(!this.ready) return;
		
		this.onStep(1, true);
	},

	prev: function() { 
		if(!this.ready) return;
		
		this.onStep(-1, true);
	}	
});

Mnet.VariableSizeObjectLoopScroller = new Class({
	Implements: Options,
	
	options:{
		duration:500,
		delay:2000,
		transition:Fx.Transitions.Sine.easeInOut,
		link:'chain',
		show:0,
		onReady:$empty,
		maxHeight:-1,
		objects:'img',
		direction:1,
		wrap:true,
		fullWidth:false,
		leftOffset:0,
		loadImages:true,
		vertical:false
	},
	
	initialize: function(id, options) {
		this.setOptions(options);

		this.contentWrapper = $(id);
		
		this.contentDiv = $(id + '-body');
		
		this.mover = new Fx.Morph(this.contentDiv, {
			duration: Mnet.getDuration(this.options.duration), 
			transition: this.options.transition,
			link: this.options.link
		});
 		
		this.contentWrapperWidth = this.options.vertical ? 
			this.contentWrapper.offsetHeight : this.contentWrapper.offsetWidth; //getStyle('width').toInt();
		this.contentWidth = 0;
		this.contentHeight = 0;
		
		this.items = this.contentDiv.getElements(this.options.objects);
		this.itemWidths = [];
				
		this.itemCount = 0;
		this.itemIndex = 0;

		if(this.options.leftOffset)
			this.contentDiv.setStyle(this.options.vertical ? 'top' : 'left', this.options.leftOffset);

		if(this.options.loadImages) {
			this.imageLoader = new Mnet.SerialImageLoader({ onProgress:this.onProgress.bind(this) });
			this.imageLoader.addImages(this.items);
			this.imageLoader.load();
		}
		else {
			this.items.each(function(item, index) {
				this.onProgress(item, index, this.items.length);
			}.bind(this));
		}
	},
	
	onProgress: function(item, index, count, reload) {
		this.itemCount++;
		
		item = this.items[index];
		
		var width = this.options.vertical ? $(item).getFullHeight() : $(item).getFullWidth();
		//_d(index + ":" + width);
		//alert(width+":"+$(item).getStyle('width'))
		//var height = $(item).getFullHeight();
		//width = $(item).getStyle('width').toInt() + 28;
		//width -= 20;
		
		if(this.options.wrap)
			this.itemWidths[index] = width;
		else
			this.itemWidths[index] = this.contentWidth;
		this.contentWidth += width;
		
		//if(height > this.contentHeight)
		//	this.contentHeight = height;
		
		// Ready? set width and start scroll
		if(index == count - 1) {
			this.contentDiv.setStyle(this.options.vertical ? 'height' : 'width', this.contentWidth + 1000);

			if(!reload) {
				this.contentHeight = this.options.vertical ? 
					this.contentWrapper.getFullWidth() : this.contentWrapper.getFullHeight();
				
				if(this.options.maxHeight > 0 && this.contentHeight > this.options.maxHeight)
					this.contentHeight = this.options.maxHeight;
					
				// Set wrapper height and make content movable
				this.contentWrapper.setStyle(this.options.vertical ? 'width' : 'height', this.contentHeight);
				this.contentDiv.setStyle('position', 'absolute');
				
				//_d(this.contentWrapper.getStyle('height'))
				//this.contentWrapper.setStyle('height', this.contentHeight);

				this.ready = true;
				this.scrollable = (this.contentWidth > this.contentWrapperWidth);
				
				// If scrollable and full width set expanded wrapper
				if(this.options.fullWidth && this.scrollable) {
					// Get new offset, width and scrollable flag
					this.options.leftOffset += this.contentWrapper.offsetLeft;
					this.contentWrapper.setStyle('position', 'absolute');

					this.contentWrapperWidth = this.contentWrapper.getStyle(this.options.vertical ? 'height' : 'width').toInt();
					this.scrollable = (this.contentWidth > this.contentWrapperWidth);
					
					if(this.options.leftOffset)
						this.contentDiv.setStyle(this.options.vertical ? 'top' : 'left', this.options.leftOffset);
				}
				if(this.options.delay > 0)
					this.play();
				
				this.options.onReady.bind(this)();
			}
		}
	},
	
	reload: function() {
		this.contentWidth = 0;
		this.itemCount = 0;
		
		var count = this.items.length;
		for(var i = 0; i < count; i++) {
			this.onProgress(null, i, count, true);
		}
	},
	
	playPause: function() {
		if(this.playing())
			this.pause();
		else
			this.play();
	},
	
	playing: function() { return (this.timerId != null); },
	
	play: function() { 
		if(!this.ready) return;
		
		// Only scroll if needed
		if(!this.playing() && this.scrollable)
			this.timerId = this.next.periodical(this.options.delay, this);
	},

	pause: function() { 
		if(!this.ready) return;
			
		if(this.playing()) {
			$clear(this.timerId);
			this.timerId = null;
		}
	},
	
	prev: function() { this.move(-1); },
	next: function() { this.move(1); },
	
	move2: function() {
		//_d(this.prevIndex);
		var item = this.items[this.prevIndex];
		
		// Get node right under content div
		while(item.parentNode != this.contentDiv)
			item = item.parentNode;
				
		this.contentDiv.appendChild(this.contentDiv.removeChild(item));
		
		// Reset div position		
		this.contentDiv.setStyle(this.options.vertical ? 'top' : 'left', this.options.leftOffset);
				
		this.moving = false;
	},

	move: function(direction) {
		if(!this.ready || this.moving || !this.scrollable) return false;
		
		direction *= this.options.direction;
		
		var thisIndex = this.itemIndex;
		var nextIndex = (thisIndex + direction);
		
		if(this.options.wrap)
			nextIndex = (nextIndex + this.itemCount) % this.itemCount;
		else if(nextIndex < 0 || nextIndex >= this.itemCount)
			return false;

		this.moving = true;

		this.prevIndex = thisIndex;
		this.itemIndex = nextIndex;
		
		var xy = this.options.vertical ? 'top' : 'left';
		
		var moveTo = {};
		
		
		if(this.options.wrap) {
			if(direction > 0) {
				moveTo[xy] = -this.itemWidths[thisIndex] + this.options.leftOffset;
				this.mover.start(moveTo).chain(
					function() { this.move2(); }.bind(this)
				);
			}
			else {
				//_d(this.prevIndex);
				var item = this.items[nextIndex];
				
				// Get node right under content div
				while(item.parentNode != this.contentDiv)
					item = item.parentNode;
				
				//_d(nextIndex);
				
				var i = this.contentDiv.removeChild(item);		
				i.inject(this.contentDiv, 'top');
				
				// Reset div position		
				this.contentDiv.setStyle(xy, -this.itemWidths[nextIndex]);

				// Scroll
				moveTo[xy] = this.options.leftOffset;
				this.mover.start(moveTo).chain(
					function() { this.moving = false; }.bind(this)
				);
			}
		}
		else {
			moveTo[xy] = -this.itemWidths[nextIndex] + this.options.leftOffset;
			this.mover.start(moveTo).chain(
				function() { this.moving = false; }.bind(this)
			);
		}
		
		return true;
	}
});

// Font sizes (%)
Mnet.fontSizes = [100, 103, 106];
Mnet.cookieExpireDays = 30;
Mnet.setFontSize = function(size) {
	try {
		var fontSize;
		
		// Get next size in array
		if(size == "next") {
			size = 0;
			
			fontSize = document.body.style.fontSize;
			if(fontSize != '') {
				var i = 0;
				while(i < Mnet.fontSizes.length && Mnet.fontSizes[i] + '%' != fontSize)
					i++;
				if(i < Mnet.fontSizes.length)
					size = (i + 1) % 3;
			}
			else
				size = 1;
		}

		// Get font size from sizes array
		fontSize = Mnet.fontSizes[size];
	
		// 0 is default so remove cookie
		if(size == 0)
			Mnet.Cookie.remove("fontSize");
		else
			Mnet.Cookie.set("fontSize", size, Mnet.cookieExpireDays);
		
		document.body.style.fontSize = fontSize + '%';
	}
	catch(e) { 
		alert("Unable to change the font size. Please make sure you have cookies enabled. You can also use your browser to change the font size e.g. 'Menu Bar > View > Text Size' for Internet Explorer or Firefox");
	};
};
// Get font size from cookie
Mnet.getFontSize = function() {
	try {
		var fontSize = Mnet.Cookie.get("fontSize");
		if(fontSize != null && fontSize != '' && !isNaN(fontSize) && fontSize >= 0 && fontSize < Mnet.fontSizes.length)
			Mnet.setFontSize(fontSize);
	}
	catch(e) { 
		;
	};
};

Mnet.Cookie = new Class();
// Set cookie
Mnet.Cookie.set = function(name, value, days) {
	var expires = "";
	
	if(days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	
	document.cookie = name + "=" + value + expires + "; path=/";
};
// Get cookie
Mnet.Cookie.get = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		
		var j = 0;
		while(j < c.length && c.charAt(j) == " ")
			j++;
		c = c.substring(j);

		if(c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	
	return null;
};
// Remove cookie
Mnet.Cookie.remove = function(name) {
	Mnet.Cookie.set(name, "", -1);
};

Mnet.init = function() {
	// Hide flash titles
	
	//h1#flash-title
	if(Browser.Plugins.Flash.version >= 6) {
		/*
		document.write(
			'<' + 'style type="text/css" media="screen">' +
			'	h1#flash-title { visibility:hidden; }' +
			'<' + '/' + 'style>'
		);
		*/
	}
		
	// Hide images while loading
	document.write(
		'<' + 'style type="text/css" media="screen">' +
		'	#images-holder { height:0px; overflow:hidden; } ' +
		'<' + '/' + 'style>'
	);
						
	window.addEvent('domready', function() {
		// Skip transitions on ipod 
		if(Browser.Platform.ipod)
			Mnet.showTransitions = false;
			
		Slimbox.scanPage();
		
		Mnet.getFontSize();
	});
	
	/*
	window.addEvent('load', function() {
		
	});
	*/
};
