/*
	Scope 2010 Javascript Library
	amhay 54075
*/

var cmh = new Object();

// Sliding Panels
cmh.slidingPanels = function(panelContainer, panelGroup, panelIDPrefix, args) {
	this.currentSlide = 0;
	this.panelGroup = panelGroup;
	this.panelIDPrefix = panelIDPrefix;

	if (!args) this.slideSpeed = 0.5;
	else {
		if (args.indexOf('speed:') > -1) {
			this.slideSpeed = args.split('speed:')[1];
				this.slideSpeed = parseInt(this.slideSpeed.split(',')[0]);
		}
		else this.slideSpeed = 0.5;

		if (args.indexOf('fade:') > -1) {
			this.fade = args.split('fade:')[1];
				this.fade = toBoolean(this.fade.split(',')[0]);
			if (this.fade == true)
				this.slideSpeed = 0.0;
		}
		else this.fade = false;

		if (args.indexOf('showCurrent:') > -1) {
			this.showCurrent = args.split('showCurrent:')[1];
				this.showCurrentCSS = this.showCurrent.split(',')[0];
			this.showCurrent = true;
		}
		else this.showCurrent = false;

		if (args.indexOf('panelCSS:') > -1) {
			this.panelCSS = args.split('panelCSS:')[1];
				this.panelCSS = this.panelCSS.split(',')[0];
		}
		else this.panelCSS = false;

		if (args.indexOf('width:') > -1) {
			this.panelWidth = args.split('width:')[1];
				this.panelWidth = parseInt(this.panelWidth.split(',')[0]);
		}
		else this.panelWidth = $(panelIDPrefix+'0').offsetWidth;
	}

	if (this.showCurrent == true)
		changeCurrentCSS(null, this.currentSlide, this.panelIDPrefix, this.showCurrentCSS);
	
	if (this.panelCSS != false)
		this.totalPanels = $$('#'+this.panelGroup+' > div').length - 1;
	else
		this.totalPanels = $(panelGroup).getElementsByTagName('div').length - 1;
}
cmh.slidingPanels.prototype.slideTo = function(elemID) {
	var nextSlide_n = elemID.split(this.panelIDPrefix)[1];
	var slideX = 0 - (this.panelWidth * nextSlide_n);
	
	if (nextSlide_n != this.currentSlide) {
        $(this.panelIDPrefix + this.currentSlide).style.height = '1px';
        $(this.panelIDPrefix + nextSlide_n).style.height = 'auto';
        
		if (this.fade == true) new Effect.Fade($(this.panelGroup), { duration: 0.5, from: 0, to: 1 });
		new Effect.Move($(this.panelGroup), { x: slideX, y: 0, duration: this.slideSpeed, mode: 'absolute' });

		if (this.showCurrent == true)
			changeCurrentCSS(this.currentSlide, nextSlide_n, this.panelIDPrefix, this.showCurrentCSS);

		this.currentSlide = nextSlide_n;
	}
}

function changeCurrentCSS(currentSlide, nextSlide_n, panelIDPrefix, showCurrentCSS) {
	var sender = document.getElementsByTagName('a');
	var css_N = false;

	if (showCurrentCSS.charAt(showCurrentCSS.length-1) == '_')
		css_N = true;

	for (i = 0; i < sender.length; i++) {
		if (sender[i].onclick && (sender[i].onclick.toString()).indexOf(panelIDPrefix) > -1) {
			if (sender[i].onclick) {
				var onClick = sender[i].onclick.toString();

				if (onClick.indexOf(panelIDPrefix + currentSlide) > -1) {
					if (css_N == true)
						$(sender[i].id).removeClassName(showCurrentCSS + currentSlide);
					else
						$(sender[i].id).removeClassName(showCurrentCSS);
				}
				
				if (onClick.indexOf(panelIDPrefix + nextSlide_n) > -1) {
					if (css_N == true)
						$(sender[i].id).addClassName(showCurrentCSS + nextSlide_n);
					else
						$(sender[i].id).addClassName(showCurrentCSS);
				}
			}
		}
	}
}


// Special Methods
// toBoolean(string);
function toBoolean(value) {
	var booleanValue;

	switch (value.toLowerCase()) {
		case "true": booleanValue = true; break;
		case "1": booleanValue = true; break;

		case "false": booleanValue = false; break;
		case "0": booleanValue = false; break;

		default: booleanValue = false; break;
	}

	return booleanValue;
}

// trim(string)
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

