function quoteSlider(quoteID, slideEl)
{
	this.quoteCont = $(quoteID);
	this.quotes = $(quoteID + " " + slideEl);
	this.moveWidth = this.quotes[0].offsetWidth;
	var contWidth = this.quotes[0].offsetWidth  * this.quotes.length;
	this.quoteCont.css({width:contWidth});
	this.prevBtn;
	this.nextBtn;
}
/*--------------------------------*/

quoteSlider.prototype.slideQuote = function(dir)
{
	var left = this.quoteCont[0].offsetLeft - (this.moveWidth * dir);
	$(this.quoteCont).animate({left:left});
	if(left == 0)
	{
		if(this.prevBtn)
			this.prevBtn.css({display:"none"});
		else
			$("#prevQuote").css({display:"none"});
		return true;
	}
	else
	{
		if(this.prevBtn)
			this.prevBtn.css({display:"block"});
		else
			$("#prevQuote").css({display:"block"});
	}
	if(left == ((this.quoteCont[0].offsetWidth-this.moveWidth)*(-1)))
	{
		if(this.nextBtn)
			this.nextBtn.css({display:"none"});
		else
			$("#nextQuote").css({display:"none"});
		return true;
	}
	else
	{
		if(this.nextBtn)
			this.nextBtn.css({display:"block"});
		else
			$("#nextQuote").css({display:"block"});
	}
}
/*--------------------------------*/

// take all the HR tags and wrap a div around it so we can control the styling better
// screen readers still get the nice HR tag along with browsers with javascript turned off
function replaceHR()
{
	var hr = document.getElementsByTagName("hr");
	for(var i=0,z=hr.length;i<z;i++)
	{
		var newHR = hr[i];
		var div = document.createElement("div");
		div.className = "hrBorder";
		hr[i].parentNode.replaceChild(div,hr[i]);
		div.appendChild(newHR);
	}
}
/*--------------------------------*/

// function that allows getting elements by their class name. Returns the found elements in an array
// arguments: className - class name to search for, element - a starting point to start the search
// if no element is specified, all the nodes on the page are searched
document.getElementsByClassName = function(className,element)
{
	if(element)
	{
		//if(typeof element == "string" && var el = document.getElementById(element))
		var el = document.getElementById(element);
		var children = el.getElementsByTagName('*');
	}
	else
	{
		var children = document.getElementsByTagName('*') || document.all;
	}
	
	var elements = [];
	var regexp = new RegExp("\\b"+className+"\\b","g");
	for(i = 0; i < children.length; i++)
	{
		if(children[i].className.match(regexp))
			elements.push(children[i]);
	}
	if(elements.length > 0)
		return elements;
	else
		return false;
}
/*----------------------*/

function getViewport()
{
	var viewport = [];
	// standars compliant browsers
	if(window.innerHeight)
	{
		viewport["width"] = window.innerWidth;
		viewport["height"] = window.innerHeight;
	}
	// IE6 in standards mode. IE6 in quirks mode won't work
	else if(document.documentElement.clientHeight)
	{
		viewport["width"] = document.documentElement.clientWidth;
		viewport["height"] = document.documentElement.clientHeight;
	}
	return viewport;
}
/*-----------------------------*/

function getScrollLength()
{
	//var x = 0; var y = 0;
	offset = [];
	if (self.pageXOffset || self.pageYOffset)
	{
		offset["x"] = self.pageXOffset;
		offset["y"] = self.pageYOffset;
	}
	 else if ((document.documentElement && document.documentElement.scrollLeft)||(document.documentElement && document.documentElement.scrollTop))
	{
		offset["x"] = document.documentElement.scrollLeft;
		offset["y"] = document.documentElement.scrollTop;
	}
	 else if (document.body) 
	{
		offset["x"] = document.body.scrollLeft;
		offset["y"] = document.body.scrollTop;
	}
	return offset;
}
/*-----------------------------*/

// grays out the page to create modal dialog boxes
function grayOut(callback)
{
	// hide select tags in IE6
	if(!window.XMLHttpRequest)
	{
		var selectShow = $(".modalDialog select");
		$("select").each(function(i)
		{
			for(var j=0,z=selectShow.length;j<z;j++)
			{
				if(this.id != selectShow[j].id)
					$(this).toggleClass("hidden");
			}
		});
	}
	
	// if the gray div already exists, remove it
	if(document.getElementsByClassName("modal"))
	{
		$(".modal").fadeOut("fast",function(){ $(".modal").remove(); });
		if(typeof callback == "function") callback();
		return true;
	}
	var div = document.createElement("div");
	div = $(div);
	if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) )
	{
		var pageWidth = document.body.scrollWidth+'px';
	    var pageHeight = document.body.scrollHeight+'px';
	}
	else if( document.body.offsetWidth )
	{
		var pageWidth = document.body.offsetWidth+'px';
	    var pageHeight = document.body.offsetHeight+'px';
	}
	else
	{
		var pageWidth='100%';
	    var pageHeight='100%';
	}
	var css = {width:pageWidth,height:pageHeight,opacity:0,display:"block"};
	div.css(css);
	div.addClass("modal");
	$("body").append(div);
	
	div.animate({opacity:.7},200,function(){ if(typeof callback == "function") callback(); });
	//div.bind("click",grayOut);
}
/*-----------------------------*/

// start the load flash video process
function initVideo(id,homepage)
{
	if(homepage)
		document.getElementById("homeFlash").innerHTML = "";
	// gray out the page and then show the video pop box
	grayOut(function() { showVideoPop(id) });
}
/*-----------------------------*/

//	show the video pop then load the video
function showVideoPop(id)
{
	var videoPop = $(id);
	var videoPopW = videoPop.width();
	var videoPopH = videoPop.height();
	var viewport = getViewport();
	var scrolled = getScrollLength();
	videoPop.css({top:(viewport["height"]-videoPopH)/2+"px",left:(viewport["width"]-videoPopW)/2+"px"});
	videoPop.fadeIn(function(){ loadVideo(); });
}
/*-----------------------------*/

function loadVideo()
{
	var videoCont = document.getElementById("homepageVideo");
	var fo = new SWFObject("/media/flash/homepage/homepage_video.swf", "homepageVideo", "531", "398", "9.0.0", "#FFFFFF");
	fo.addVariable("wmode", "transparent");
	fo.write("homepageVideo");	
}

function closeVideoPop(id,homepage)
{
	var videoPop = $(id);
	var videoCont = document.getElementById("homepageVideo");
	videoCont.innerHTML = "";
	videoPop.fadeOut(function(){grayOut(function(){ if(homepage) fo.write("homeFlash");})});
}
/*-----------------------------*/



