/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx2 by mad4milk (http://moofx2.mad4milk.net).

var Class2 = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method2 = this;
	return function() {
		return __method2.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method2 = this;
	return function(event) {
		__method2.call(object, event || window.event);
	}
}

function $$$$() {
	if (arguments.length == 1) return get$$$$(arguments[0]);
	var elements2 = [];
	$c(arguments).each(function(el){
		elements2.push(get$$$$(el));
	});
	return elements2;

	function get$$$$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element2) var Element2 = new Object();

Object.extend(Element2, {
	remove: function(element) {
		element = $$$$(element);
		element.parentNode.removeChild(element);
	},

	hasClass2Name: function(element, className) {
		element = $$$$(element);
		if (!element) return;
		var hasClass2 = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass2 = true;
		});
		return hasClass2;
	},

	addClassName: function(element, className) {
		element = $$$$(element);
		Element2.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $$$$(element);
		if (!element) return;
		var newClassName2 = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName2 += ' ';
				newClassName2 += cn;
			}
		});
		element.className = newClassName2;
	},

	cleanWhitespace: function(element) {
		element = $$$$(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element2.remove(node);
		});
	},

	find: function(element, what) {
		element = $$$$(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position2 = {
	cumulativeOffset: function(element) {
		var valueT2 = 0, valueL2 = 0;
		do {
			valueT2 += element.offsetTop  || 0;
			valueL2 += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL2, valueT2];
	}
};

document.getElement2sByClassName = function(className) {
	var children2 = document.getElementsByTagName('*') || document.all;
	var elements2 = [];
	$c(children2).each(function(child){
		if (Element2.hasClass2Name(child, className)) elements2.push(child);
	});  
	return elements2;
}

//useful array functions
Array.prototype.iterate = function(func){
	for(var i=0;i<this.length;i++) func(this[i], i);
}
if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;

function $c(array){
	var nArray2 = [];
	for (var i=0;i<array.length;i++) nArray2.push(array[i]);
	return nArray2;
}


/*
moo.fx2, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx2.mad4milk.net).
Sunday, March 05, 2006
v 1.2.3
*/

var fx2 = new Object();
//base
fx2.Base = function(){};
fx2.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 500,
		onComplete: '',
		transition: fx2.sinoidal
	}
	Object.extend(this.options, options || {});
	},

	step: function() {
		var time2  = (new Date).getTime();
		if (time2 >= this.options.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.time2r);
			this.time2r = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			var Tpos2 = (time2 - this.startTime) / (this.options.duration);
			this.now = this.options.transition(Tpos2) * (this.to-this.from) + this.from;
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.time2r != null) return;
		this.from = from;
		this.to = to;
		this.startTime = (new Date).getTime();
		this.time2r = setInterval (this.step.bind(this), 13);
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.time2r);
		this.time2r = null;
	}
}

//transitions
fx2.sinoidal = function(pos){
	return ((-Math.cos(pos*Math.PI)/2) + 0.5);
	//this transition is from script.aculo.us
}



//ACRO MEDIA ADDITION of left:XXpx; sliding effect. Built around video object declared below.

fx2.Slide = Class2.create();
fx2.Slide.prototype = Object.extend(new fx2.Base(), {
	initialize: function(el, options) {
		this.el = $$$$(el);
		this.setOptions(options);
		this.now = 0;
	},
	increase: function() {		
		this.el.style.marginLeft = this.now + "px";	
		
	},
	slide: function(howMuch2){
		this.clearTimer();
		this.custom(this.now, howMuch2 * this.options.distance * -1);
	}
});

var video2 = {
	vids : null, currentNum : 0, slider : null,
	init : function(){
		this.vids = $$$$('popSlideA').getElementsByTagName('div').length;
		this.vids = eval(this.vids / 6);
		this.slider = new fx2.Slide($$$$('popSlideA'), {distance: 516, duration: 600});	 
	},toggle : function(direction2){	   
		if(!this.slider) this.init();
    var new_num2 = this.currentNum + direction2;

    if (this.vids <= 3){
        document.getElementById('video_left2').style.display = 'none';
        document.getElementById('video_right2').style.display = 'none';
    } else {
    		if(new_num2 <= 0) {    
            new_num2 = 0;
            //document.getElementById('video_left2').style.display = 'none';
            document.getElementById('video_left2').innerHTML = '&nbsp;';
        } else {
            //document.getElementById('video_left2').style.display = '';  
            document.getElementById('video_left2').innerHTML = '<li><a href="javascript:;" onclick="video2.toggle(-1); return false;" class="pg_prev" title="previous page"></a></li><li class="txtlink"><a href="javascript:;" onclick="video2.toggle(-1); return false;">Previous</a></li>';                  
        }
        
        if(Math.ceil(eval(eval(eval(new_num2 + 1) * 3) - this.vids)) >= 0) {            
            document.getElementById('video_right2').style.display = 'none';          
        }  else {
            document.getElementById('video_right2').style.display = '';                  
        }  
    }
    this.currentNum = new_num2;
		this.slider.slide(this.currentNum);
	}
}
fx2.sinoidal = function(pos){return ((-Math.cos(pos*Math.PI)/2) + 0.5);}

