// scripts running on homepage only



/* =========================================================
SCRIPT 1: show / hide  the click open windows for divs 
with id of "role", "existing_customers", "compare_editions", 
and "demo_videos"
============================================================*/


	
/* the initDivs function is loaded from line 219 of easymenu/cssmenu.js. Why use ask?
Because I'm adding the initDiv() function to the menu scripts onload function because
doing body onload="initDivs()" was breaking the css menu */

function initDivs() {
// initial state of click open divs.
// first we set display to none so that the next click they will be display block
document.getElementById("role").style.display = "none";
document.getElementById("existing_customers").style.display = "none";
document.getElementById("demo_videos").style.display = "none";

/* next: we have set a cookie on the homepage telling us the id of the last div the user clicked open.
we'll open this div if they return to the homepage */

// grab the cookie.
var divToOpen = Get_Cookie("openedDiv");
// if it is the video demo div they left opened, then we also have to 
// initialize the video player
	if (divToOpen == "demo_videos") {
	createplayer('http://maximizer2.data-fortress.com/mktgadmin/crm10valueprop/new_max_final.flv', false) /* see createplayer function bottom of this document */
	}
	if(divToOpen) { document.getElementById(divToOpen).style.display = "block"; }
}

function showHide(divToShow,divToHide1,divToHide2)
 {
  var show=document.getElementById(divToShow);
  var hide1=document.getElementById(divToHide1);
  var hide2=document.getElementById(divToHide2);
   
  if(show.style.display=="none")
   {
  show.style.display="block";
  hide1.style.display="none";
  hide2.style.display="none";


  }
   else
    {
     show.style.display="none";
     }
		  		// okay this ain't the best way to change the background image on click but it works.
				// here we are showing the button with the [-] sign when they click and showing the button with the [+] sign when that div is display: none
				if(document.getElementById('role').style.display == "block") {
					   document.getElementById('role_button').style.backgroundImage = "url('/images/homepage-images/navs/role-button-over.jpg')"
				 }
				 else {
					 document.getElementById('role_button').style.backgroundImage = "url('/images/homepage-images/navs/role-button-out.jpg')"
				 }
				if(document.getElementById('demo_videos').style.display == "block") {
					   document.getElementById('demoVideos_button').style.backgroundImage = "url('/images/homepage-images/navs/demo-videos-button-over.jpg')"
				 }
				 else {
					 document.getElementById('demoVideos_button').style.backgroundImage = "url('/images/homepage-images/navs/demo-videos-button-out.jpg')"
				 }
				if(document.getElementById('existing_customers').style.display == "block") {
					   document.getElementById('customers_button').style.backgroundImage = "url('/images/homepage-images/navs/existing-customers-button-over.jpg')"
				 }
				 else {
					 document.getElementById('customers_button').style.backgroundImage = "url('/images/homepage-images/navs/existing-customers-button-out.jpg')"
				 }

 }
 
 
 
 
 
 
 /*======================================================================
 SCRIPT 2: Quote Rotator - rotates the quotes divs within their container 
 div with id "quoteContainer"
  ======================================================================*/

function scrollObject(main, width, height, direct, pause, speed) { 
  var self = this;
  this.main = main;
  this.width = width;
  this.height = height;
  this.direct = direct;
  this.pause = pause;
  this.speed = Math.max(1.001, Math.min((direct == "up" || direct == "down") ? height : width, speed));
  this.slope = (direct == "up" || direct == "left") ? 1 : -1;
  this.prev = this.offset = 0;
  this.curr = 1;
  this.mouse = false;
  this.scroll = function() {
    this.main = document.getElementById(this.main);
    this.main.style.overflow = "hidden";
    this.main.style.position = "relative";
    this.main.style.width = this.width + "px";
    this.main.style.height = this.height + "px";
    var b = [], c;
    while (this.main.firstChild) if ((c = this.main.removeChild(this.main.firstChild)).nodeName == "DIV") b.push(c);
    for (var x = 0; x < b.length; x++) {
      var table = document.createElement('table');
          table.cellPadding = table.cellSpacing = table.border = "0";
          table.style.position = "absolute";
          table.style.left = table.style.top = "0px";
          table.style.width = table.style.height = "100%";
		  table.style.paddingLeft = "0";
		  
          table.style.overflow = table.style.visibility = "hidden";
        var tbody = document.createElement('tbody');
          var tr = document.createElement('tr');
            var td = document.createElement('td');
              while (b[x].firstChild)
                  td.appendChild(b[x].removeChild(b[x].firstChild));
              tr.appendChild(td);
            tbody.appendChild(tr);
          table.appendChild(tbody);
      this.main.appendChild(table);
    } b = c = null;
    if (this.main.childNodes.length > 1) {
      this.main.onmouseover = function() { self.mouse = true; };
      this.main.onmouseout = function() { self.mouse = false; };
      setInterval(function() {
        if (!self.offset && self.scrollLoop()) self.main.childNodes[self.curr].style.visibility = "visible";
      }, this.pause);
    } this.main.childNodes[this.prev].style.visibility = "visible";
  };
  this.scrollLoop = function() {
    if (!this.offset) {
      if (this.mouse) return false;
      this.offset = (this.direct == "up" || this.direct == "down") ? this.height : this.width;
    } else this.offset = Math.floor(this.offset / this.speed);
    if (this.direct == "up" || this.direct == "down") {
      this.main.childNodes[this.curr].style.top = (this.offset * this.slope) + "px";
      this.main.childNodes[this.prev].style.top = ((this.offset - this.height) * this.slope) + "px";
    } else {
      this.main.childNodes[this.curr].style.left = (this.offset * this.slope) + "px";
      this.main.childNodes[this.prev].style.left = ((this.offset - this.width) * this.slope) + "px";
    }
    if (!this.offset) {
      this.main.childNodes[this.prev].style.visibility = "hidden";
      this.prev = this.curr;
      if (++this.curr >= this.main.childNodes.length) this.curr = 0;
    } else setTimeout(function() { self.scrollLoop(); }, 30);
    return true;
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.scroll(); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.scroll(); });
}

// scrollObject args: main, width, height, direct, pause, speed
// create the scrollObject
new scrollObject("quoteContainer", 290, 120, "down", 5000, 1.15);






/*===========================================================
SCRIPT 3: creating the video player object... the video player
this is used after swfobject.js is called in the body. Note that
it works in conjunction with /mediaplayer/swfobject.js. which has
to be brought in with script tags in the head of the document
in which you want to create a video player.
=============================================================*/

	function createplayer(theFile, go) {
			var so = new SWFObject('/mediaplayer/mediaplayer.swf',"thePlayerId","313","236","7");
				so.addParam('allowscriptaccess','always');
				so.addParam('allowfullscreen','true');  
				so.addParam("wmode", "transparent");
				so.addVariable("file",theFile);
				so.addVariable('height','236');
				so.addVariable('width','313');
				so.addVariable('backcolor','0x000000');
				so.addVariable('frontcolor','0x7f96bf');
				so.addVariable('lightcolor','0xCfbb63');
				so.addVariable('screencolor','0x000');
				so.addVariable('searchbar','false');
				so.addVariable('overstretch','true');
				so.addVariable('showstop','true');
				so.addVariable('javascriptid','thePlayerId');
				so.addVariable('enablejs','true');
				if (go) { so.addVariable("autostart","true"); }
				so.write('flashVideoPlayer');
	}

 // JavaScript Document