/* *********************************************************************** */
/* Object literal for rotating banner and AVB images ********************* */
/* *********************************************************************** */

imgRotater = {
// imgRotater rotates banner and AVB images on the home page.

	cookieStatus:questionnairePopup.checkCookiesEnabled(),
	avb:"",
	banner:"",
	video_link:"",
	
	initRotater:function()
	{
		// Initialize banner and AVB image id's and verify DOM compliance.	  
		if (!document.getElementById) {return;} // getElementById not implemented. Exiting function.
		imgRotater.avb = document.getElementById("avb1_image");
		imgRotater.banner = document.getElementById("banner_image");
		imgRotater.video_text_link = document.getElementById("avb1_text_link");
		imgRotater.video_img_link = document.getElementById("avb1_img_link");
		imgRotater.banner_link = document.getElementById("banner_link");		
	  if ((!imgRotater.avb) || (!imgRotater.banner)) {return;} // Can't find elements on page. Exiting function.
		var newAvbSrc = new Object;
		var newBannerSrc = new Object;
		newAvbSrc = imgRotater.getRandomAvb();
		newBannerSrc = imgRotater.getRandomBanner();
		imgRotater.avb.setAttribute("src",newAvbSrc.img);
		imgRotater.avb.setAttribute("title",newAvbSrc.title);
		imgRotater.video_text_link.innerHTML = newAvbSrc.text;
		imgRotater.video_text_link.setAttribute("href",newAvbSrc.link);
		imgRotater.video_img_link.setAttribute("href",newAvbSrc.link);
		imgRotater.banner.setAttribute("src",newBannerSrc.img);
		imgRotater.banner.setAttribute("alt",newBannerSrc.title);
		imgRotater.banner_link.setAttribute("title",newBannerSrc.title);		
		imgRotater.banner_link.setAttribute("href",newBannerSrc.link);		
	},
	
  getRandomNum:function(min,max) 
  {
      var R = min + Math.floor(Math.random() * (max-min +1)); 
      return R;
  },
    // Select an avb image
  getRandomAvb:function()
  {
      var avb_images = new Array;
      var avb_titles = new Array;
      var avb_ids = new Array;
      var new_AVB = new Object;
			var randomNum ="";
      var cookieName ="Home_page_AVB";
      var cookieValue = "";               
      var timeInDays = 1;
      var currentAvbSrc =""; // The array position/AVB currently stored in the cookie.
			var avb_link_base = "http://"; 
			var avb_link_host = location.host;
			var avb_link_pathname = location.pathname;
			var avb_link_file = "?url=/pro/success/venue/";
			var number_of_avbs = 9; // Update this with the current number of avbs in the rotation.
			var upper_limit = number_of_avbs-1;  // Use upper_limit when calculating random numbers.

			if (avb_link_pathname == "/")  // Fix for live site when first landing on home page.
			{	
				avb_link_pathname="/ProController";
			}

			avb_link_base = avb_link_base + avb_link_host + avb_link_pathname + avb_link_file;
		  // alert(location.host + ", " + location.pathname + ", " + avb_link_base)    
							  
      avb_images[0] = ['/images/pro/home/avb_shepherdofthevalley.jpg'];
      avb_images[1] = ['/images/pro/home/avb_stoutnyc.jpg'];
      avb_images[2] = ['/images/pro/home/avb_bostonharborhotel.jpg'];
      avb_images[3] = ['/images/pro/home/avb_harleydavidson.jpg'];
      avb_images[4] = ['/images/pro/home/avb_whichwich.jpg'];
      avb_images[5] = ['/images/pro/home/avb_tabernacle.jpg'];
      avb_images[6] = ['/images/pro/home/avb_renaissance.jpg'];
      avb_images[7] = ['/images/pro/home/avb_lake_elsinore.jpg'];
      avb_images[8] = ['/images/pro/home/avb_how.jpg'];
                 
      avb_titles[0] = ['Shepherd of the Valley Lutheran Church'];
      avb_titles[1] = ['Stout NYC'];
      avb_titles[2] = ['Boston Harbor Hotel'];
      avb_titles[3] = ['High Desert Harley-Davidson'];
      avb_titles[4] = ['Which Wich? Superior Sandwiches'];
      avb_titles[5] = ['Tabernacle Baptist Church'];
      avb_titles[6] = ['Renaissance Hotel'];
      avb_titles[7] = ['Lake Elsinore Diamoond'];
      avb_titles[8] = ['Houses of Worship'];

      avb_ids[0] = ['campaign/campaign.jsp?vid=shepherd_of_the_valley'];
      avb_ids[1] = ['campaign/campaign.jsp?vid=stout_nyc'];
      avb_ids[2] = ['campaign/campaign.jsp?vid=boston_harbor_hotel'];
      avb_ids[3] = ['campaign/campaign.jsp?vid=harley_davidson'];
      avb_ids[4] = ['campaign/campaign.jsp?vid=which_wich'];
      avb_ids[5] = ['campaign/campaign.jsp?vid=tabernacle'];
      avb_ids[6] = ['campaign/campaign.jsp?vid=renaissance'];
      avb_ids[7] = ['campaign/campaign.jsp?vid=lake_elsinore'];
      avb_ids[8] = ['how/index.jsp'];
                    
			if (!imgRotater.cookieStatus)  // If cookies are not enabled, generate a "random" number
			{
				randomNum = imgRotater.getRandomNum(0,upper_limit); 
			}
			else 	// If cookies are enabled check the cookie for the AVB source and select a different AVB
			{
				currentAvbSrc = questionnairePopup.checkCookie(cookieName,1);
        randomNum = imgRotater.getRandomNum(0,upper_limit);
        while (randomNum == currentAvbSrc)
        {
					randomNum = imgRotater.getRandomNum(0,upper_limit);
        }
				cookieValue = randomNum;
				questionnairePopup.setCookie(cookieName,cookieValue,timeInDays);        
			}
	    new_AVB.img = avb_images[randomNum];
	    new_AVB.title = avb_titles[randomNum];
			new_AVB.link = avb_link_base + avb_ids[randomNum];
			new_AVB.text = randomNum == 8 ? "Learn more" : "See video case story";
			// alert(avb_link_base);
	    return new_AVB;
	},
		
	// Select a banner image
	getRandomBanner:function()
	{
	  var banner_images = new Array;
	  var banner_titles = new Array;
	  var banner_ids = new Array;	  
	  var new_Banner = new Object;
		var randomNum ="";   
	  var cookieName ="Home_page_banner";
	  var cookieValue = "";   
	  var timeInDays = 1;
	  var currentBannerSrc =""; // The array position/Banner currently stored in the cookie. 
		var banner_link_base = "http://"; 
		var banner_link_host = location.host;
		var banner_link_pathname = location.pathname;
	  var number_of_banners = 9; // This is the number of banners that are currently active.
		var upper_limit = number_of_banners-1; // Use upper_limit when calculating random numbers.
		
		if (banner_link_pathname == "/")  // Fix for live site when first landing on home page.
			{	
				banner_link_pathname="/ProController";
			}

			banner_link_base = banner_link_base + banner_link_host + banner_link_pathname;
		  // alert(location.host + ", " + location.pathname + ", " + banner_link_base)    
		  
	  banner_images[0] = ['/images/pro/home/banner_ds100se.jpg'];        
	  banner_images[1] = ['/images/pro/home/banner_fs4400.jpg'];
	  banner_images[2] = ['/images/pro/home/banner_ds16s.jpg'];        
	  banner_images[3] = ['/images/pro/home/banner_l1m2.jpg']; 
	  banner_images[4] = ['/images/pro/home/banner_t1.jpg'];
	  banner_images[5] = ['/images/pro/home/banner_esp88.jpg'];
	  banner_images[6] = ['/images/pro/home/banner_panaray502.jpg'];
	  banner_images[7] = ['/images/pro/home/banner_panaray802.jpg'];
	  banner_images[8] = ['/images/pro/home/banner_panarayltsystems.jpg'];	  
	  banner_images[9] = ['/images/pro/home/banner_panarayma12.jpg'];	  
	  
	  banner_titles[0] = ['FreeSpace DS 100SE surface-mount loudspeakers'];
	  banner_titles[1] = ['FreeSpace FS 4400 four-zone system'];
	  banner_titles[2] = ['FreeSpace DS 16S and DS 16SE surface-mount loudspeakers'];
	  banner_titles[3] = ['L1 Model II system'];
	  banner_titles[4] = ['T1 ToneMatch audio engine'];
	  banner_titles[5] = ['ControlSpace ESP-88 sound processor'];
	  banner_titles[6] = ['Panaray 502 A loudspeakers'];
	  banner_titles[7] = ['Panaray 802 Series III loudspeaker'];
	  banner_titles[8] = ['Panaray LT Systems'];
	  banner_titles[9] = ['Panaray MA12 modular line array loudspeakers'];
	  
    banner_ids[0] = ['?url=/pro/products/freespace/ds100se/ds100se.jsp'];
    banner_ids[1] = ['?url=/pro/products/freespace/fs4400/fs4400.jsp'];
    banner_ids[2] = ['?url=/pro/products/freespace/ds16s/ds16s.jsp'];
    banner_ids[3] = ['?url=/pro/products/l1/l1.jsp'];
    banner_ids[4] = ['?url=/pro/products/l1/l1.jsp'];
    banner_ids[5] = ['?url=/pro/products/controlspace_esp88.jsp'];
    banner_ids[6] = ['?url=/pro/products/panaray/panaray502a.jsp'];
    banner_ids[7] = ['?url=/pro/products/panaray/panaray802.jsp'];
    banner_ids[8] = ['?url=/pro/products/panaray_lt/index.jsp'];
    banner_ids[9] = ['?url=/pro/products/panaray/panarayma12.jsp'];
      	  
		if (!imgRotater.cookieStatus)
		// If cookies are not enabled,,, generate a "random" number
		{
		  randomNum = imgRotater.getRandomNum(0,upper_limit);	        
	  }
	  else
		// If cookies are enabled check the cookie for the current banner and select a different banner        
	  {
			currentBannerSrc = questionnairePopup.checkCookie(cookieName,1);
	    randomNum = imgRotater.getRandomNum(0,upper_limit);
	    while (randomNum == currentBannerSrc)
	    {
				randomNum = imgRotater.getRandomNum(0,upper_limit);
	    }		
	    cookieValue = randomNum;	
			questionnairePopup.setCookie(cookieName,cookieValue,timeInDays);        
	  }
		new_Banner.img = banner_images[randomNum];
		new_Banner.title = banner_titles[randomNum];
		new_Banner.link = banner_link_base + banner_ids[randomNum];    
	  return new_Banner;      
  }
};

/* *********************************************************************** */
/* End object literal for rotating AVB image ***************************** */
/* *********************************************************************** */

// Attach listener to window.onload.
DOM_Utilities.addEvent(window,'load', imgRotater.initRotater, false); 