/*
*                  _         _                   _ _         _ 
*      /\  /\_   _| |_ ____ / \   /\/\   ___  __| (_) __ _  / \
*     / /_/ / | | | __|_  //  /  /    \ / _ \/ _` | |/ _` |/  /
*    / __  /| |_| | |_ / //\_/  / /\/\ \  __/ (_| | | (_| /\_/ 
*    \/ /_/  \__,_|\__/___\/    \/    \/\___|\__,_|_|\__,_\/   
*
*	CSS Stylesheet
*
*	Developed By Hutz! Media! <hutzmedia.com>
*	under contract for WebStager <webstager.com>
*
*	June 29, 2010
*
*/

/* Class: SlideShowClass
		Creates a fade-in and out slide show.
*/
function SlideShowClass(objList) {
	this.objList = objList;
	this.current = 0;
	this.fps = 30;
	this.pause = 3000;
	this.fade = 2000;
	this.zIndex = 15;
}
SlideShowClass.prototype = {
	start: function() {
		// go to next after pause
		var self = this;
		setTimeout(function(){self.next(self);}, self.pause);
	},
	next: function(self) {
		// start fade out and in
		
		var a = self.current;
		var b = a + 1;
		if (b >= self.objList.length) {
			b = 0;
		}
		self.current = b;
		
		var objA = self.getID(self.objList[a]);
		var objB = self.getID(self.objList[b]);
		
		// make sure A is in front of B
		objA.style.zIndex = self.zIndex + 0;
		objB.style.zIndex = self.zIndex + 1;
		
		// set starting opacity
		self.setOpacity(objA, 99);
		self.setOpacity(objB, 1);
		
		// make both visible
		self.setVisible(objA, true);
		self.setVisible(objB, true);
		
		// start fade
		self.fadeStep(self, objA, objB, 0);
	
	},
	fadeStep: function(self, objA, objB, alpha) {
		// step through fade until complete
		
		var delay = 1000 / self.fps;
		var step = 100 / self.fade * delay;
		
		alpha = Math.min(alpha + step, 100);
		
		// set alpha
		self.setOpacity(objA, (100 - Math.floor(alpha)));
		self.setOpacity(objB, Math.floor(alpha));
		
		if (alpha >= 100) {
			// done
			self.setVisible(objA, false);
			setTimeout(function(){self.next(self);}, self.pause);
		} else {
			// continue step
			setTimeout(function(){self.fadeStep(self, objA, objB, alpha);}, delay);
		}
	},
	getID: function(objname) {
		return document.getElementById(objname);
	},
	setVisible: function(obj, v) {
		if (v) {
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	},
	setOpacity: function(obj, alpha) {
		try { obj.style.opacity = (alpha / 100); } catch (e) { }
		try { obj.style.MozOpacity = (alpha / 100); } catch (e) { }
		try { obj.style.KhtmlOpacity = (alpha / 100); } catch (e) { }
		try { obj.style.filter = "alpha(opacity=" + alpha + ")"; } catch (e) { }
	}
};


function cropMenu(x1, x2) {
	var obj = this.document.getElementById("menuClip");
	obj.style.visibility = 'visible';
	obj.style.clip = "rect(0px," + x2 + "px,30px," + x1 + "px)";
}
function cropMenuOut() {
	var obj = this.document.getElementById("menuClip");
	obj.style.clip = "rect(0px, 0px, 0px, 0px)";
}

function initSlideshow(ids) {
	
	var SS = new SlideShowClass(ids);
	SS.pause = 3000; // 3s
	SS.fade = 1000; // 1s
	SS.start();
	
}

var scrollP = 0;
function scrollTestimonial() {
	scrollP = 0;
	nextScroll();
}
function nextScroll() {
	try {
	
		var obj = document.getElementById("testimonial_content");
		var objS = document.getElementById("testimonial_signature");
		
		// set text
		obj.style.overflow = "hidden";
		obj.innerHTML = testimonials[scrollP][0];
		objS.innerHTML = testimonials[scrollP][1];
		
		
		// iterate
		scrollP++;
		if (scrollP >= testimonials.length) { scrollP = 0; }
		
		// get text height
		var objW = (790 - objS.clientWidth) + 12;
		obj.style.width = objW + "px";
		var scrollW = obj.scrollWidth;
		obj.scrollLeft = 0;
		
		if (scrollW > objW) {
			//setTimeout(function(){scrollAction(obj, 0, scrollW - 790, 2, 50);},4000); // start in 2s
			setTimeout(function(){scrollAction(obj, 0, scrollW, objW, 4, 50);},4000); // start in 2s
		} else {
			// no scrolling required
			setTimeout(function(){nextScroll();}, 10000); // 10s
		}
		
	} catch (e) { 
		// error scrolling
	}

}
function scrollAction(obj, current, target, objW, step, delay) {
	current = Math.min(current + step, target);
	
	if (target - current < objW) {
		obj.style.width = Math.max(((target - current) + 12), 600) + "px";
		obj.scrollLeft = obj.scrollWidth;
	} else {
		obj.scrollLeft = current;
	}
	
	if (current == target) {
		// reached target - sleep
		setTimeout(function(){nextScroll();}, 0);
	} else {
		// keep going
		setTimeout(function(){scrollAction(obj, current, target, objW, step, delay);}, delay);
	}
}
