// JavaScript Document
//this function includes all necessary js files for the application
function include(file)
{

  var script  = document.createElement('script');
  script.src  = file;
  script.type = 'text/javascript';
  script.defer = true;

  document.getElementsByTagName('head').item(0).appendChild(script);

}

/* include any js files here */
//include('/include/animatedcollapse.js');
//include('/include/debug/trace.js');

//********Image Swap & Show/Hide Layers***********

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

function MM_showHideLayers2() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers2.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
  rnd.seed = (rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0);
}

function rand(number) {
  return Math.ceil(rnd()*number);
}

function PopUp(url,w,h,sb,rs,st,tb,mb,ti,lc)
{
  lft = (screen.availWidth -w)/2;
  t = (screen.availHeight -h)/2;
  p = "scrollbars=" + sb + ",resizable=" + rs + ",status=" + st + ",toolbar=" + tb + ",menubar=" + mb + ",titlebar=" + ti + ",location=" + lc + ",top=" + t + ",left=" +lft + ",width=" + w + ",height=" + h;
  window.open(url, rand(101)-1, p);
}

// this array consists of the id attributes of the divs we wish to alternate between
	var divs_to_fade = new Array('box-1','box-2','box-3','box-4','box-5','box-6','box-7','box-8','box-9');
	var news_to_fade = new Array('news-1','news-2','news-3','news-4');
	
	// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
	var e = 0;
	var p = 0;
	var o = 0;
	var f = 0;

// the number of milliseconds between swaps.  Default is five seconds.
var wait = 7000;
var fader = -1;
var faderNews = -1;

function stopFade()
{
	if( fader != -1 ) {
		clearInterval(fader);
		fader = -1;
	}
}

function stopNewsFade()
{
	if( faderNews != -1 ) {
		clearInterval(faderNews);
		faderNews = -1;
	}
}

function startFade( numMSDelay ) 
{
	if( typeof numMSDelay == "undefined" || isNaN( numMSDelay ) ) {
		numMSDelay = 0;
	}
	if( numMSDelay > 0 ) {
		setTimeout('startFade()',numMSDelay);
	} else {
		if( fader == -1 ) {
			fader = setInterval('swapFade()',wait);
		}
	}
}

function startFadeNews( numMSDelay ) 
{
	if( typeof numMSDelay == "undefined" || isNaN( numMSDelay ) ) {
		numMSDelay = 0;
	}
	if( numMSDelay > 0 ) {
		setTimeout('startFadeNews()',numMSDelay);
	} else {
		if( faderNews == -1 ) {
			faderNews = setInterval('swapFadeNews()',wait);
		}
	}
}

// the onload event handler that starts the fading.
function startPage() {
	startFade();
	if(document.getElementById('hmNews'))
	startFadeNews();
}


/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}

/*
function addEvent(el, sEvt, PFnc)
{
	if(el)
	{
		if(el.addEventListener)
			el.addEventListener(sEvt, PFnc, false);
		else
			el.attachEvent("on" + sEvt, PFnc);
	}
}
*/

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}


var previousLayer = 'lyrWhirlpool';

function switchContent(contentLayer,bucket,obj){
	bottomBorder = document.getElementById('clientArrow');
	bottomBorder.style.backgroundImage = 'url(/images/vision/client_success/border_bottom_' +  bucket + '.gif)';

	if (previousLayer != contentLayer){
		curEle = document.getElementById(previousLayer);
		nextEle = document.getElementById(contentLayer);
		Spry.Effect.DoFade(previousLayer, {duration:750,from:100,to:0,toggle:false,finish:function(){curEle.style.display="none";}});
		Spry.Effect.DoFade(contentLayer, {duration:750,from:0,to:100,toggle:false,setup: function(){nextEle.style.display="block";nextEle.style.opacity="0"; nextEle.style.filter="alpha(opacity=0)"; }});
	}
	
	previousLayer = contentLayer;
	
	var mylist=document.getElementById("allLinks")
	var listitems= mylist.getElementsByTagName("a")
	for (i=0; i<listitems.length; i++)
	{
		listitems[i].className = "";
	}
	
	obj.className = "on";
}

function createCookie(name, value, days) 
{
	if(days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
		var expires = '';
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
			
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	
	return null;
}

function eraseCookie(name) 
{
	createCookie(name, "", -1);
}

function popUpClosed(){
	if( typeof startFade != "undefined" ) {
		try { startFade(); } catch( e ) {}
	}
}

function get_content(url)
{
	var ck = readCookie('cvg_form_data');
	
	if(ck)
	{
		//alert('found cookie - serve up content here');
		window.open('/include/view_collateral.php?url=' + url);
	}
	else
	{
		if( typeof stopFade != "undefined" ) {
			try { stopFade(); } catch( e ) {}
		}
		showPopWin("/include/reg_popup.php?action=form&url=" + url, 490, 275, popUpClosed,false);
		setPopTitle("Loading");
	}
}

function VideoPopUp(id){
	PopUp('/flash/mediaplayer.php?mediaID=' + id + '','757','539','no','no','no','no','no','no','no');
}


