
  // --------------------------------------------------------------------------

  Zoomedia = {

    version: '1.0',

    redirect: function(url) {
      var anchor_pos = url.indexOf("#");
      document.location.href = (anchor_pos == -1) ? url : url.substr(0, anchor_pos);
    },

    print: function() {
      if (window.print) {
        window.print();
      } else {
        alert("Sorry, your browser doesn't support this feature.\nPlease use your browser's print button");
      }
      return false;
    }
  };

  // --------------------------------------------------------------------------

  Zoomedia.Menu = function(id) {
    if (id) {
      try { this.build( document.getElementById( id ) ); } catch(err) {}
    }
  };

  // --------------------------------------------------------------------------

  Zoomedia.Menu.prototype = {

    // ------------------------------------------------------------------------

    ptr: null,
    timer: null,
    delay: 1000,
    liList: [],

    // ------------------------------------------------------------------------

    setTimeOut: function(el) {
      var self = this;
      var id = el.getAttribute('id');
      this.timer = window.setTimeout(function() { self.mouseOut(document.getElementById(id)); }, this.delay);
    },

    // ------------------------------------------------------------------------

    mouseOut: function(el) {
      if (this.timer != null && this.ptr != null&& this.ptr.id == el.id) {
        if (!el.firstChild.getAttribute('on')) {
          el.firstChild.className = '';
        }

        for(var ulList = el.getElementsByTagName('ul'), i=0; i < ulList.length; ++i) {
          ulList.item(i).style.visibility = 'hidden';
        }

        for(var liList = el.getElementsByTagName('li'), i=0; i < liList.length; ++i) {
          liList.item(i).firstChild.className = '';
        }

        this.ptr = null;
        this.liList = new Array();

        return;
      }

      var className = '';
      for(var i=0; i < this.liList.length; i++) {
        if (this.liList[i] == el.id) {
          className = 'hover';
          break;
        }
      }

      if (!el.firstChild.getAttribute('on')) {
        el.firstChild.className = className;
      }
    },

    // ------------------------------------------------------------------------

    mouseOver: function(el) {
      for(var i=0; i < this.liList.length; ++i) {
        if (this.liList[i] == el.id) {
          break;
        }
      }

      if (i == this.liList.length) {
        this.liList[i] = el.id;
      }

      if (this.timer != null && this.ptr != null) {
        if (!this.ptr.firstChild.getAttribute('on')) {
          this.ptr.firstChild.className = '';
        }
        for(var ulList = this.ptr.getElementsByTagName('ul'), i=0; i < ulList.length; ++i) {
          ulList.item(i).style.visibility = 'hidden';
        }
        window.clearTimeout(this.timer);
        this.timer = null;
        this.liList = new Array();
      }

      this.ptr = el;

      if (this.ptr.tagName.toLowerCase() == 'li') {
        if (!this.ptr.firstChild.getAttribute('on')) {
          this.ptr.firstChild.className = 'hover';
        }
      }

      var ulList = this.ptr.getElementsByTagName('ul');

      if (ulList.length > 0) {
        ulList.item(0).style.visibility = 'visible';
      }
    },

    // ------------------------------------------------------------------------

    build: function(el) {
      var self = this;
      for(var i=0; i < el.childNodes.length; ++i) {
        if (el.childNodes[i].nodeName.toLowerCase() == 'li') {
          for(var j=0; j < el.childNodes[i].childNodes.length; ++j) {
            //if (el.childNodes[i].childNodes[j].nodeName.toLowerCase() == 'ul') {
              el.childNodes[i].onmouseover = function() { try { self.mouseOver(this); } catch(err) {} };
              el.childNodes[i].onmouseout = function() { try { self.setTimeOut(this); } catch(err) {} };
              //this.build(el.childNodes[i].childNodes[j]);
              //break;
            //}
          }
        }
      }
    }

    // ------------------------------------------------------------------------

  }//Zoomedia.Menu

  // --------------------------------------------------------------------------

  Zoomedia.Glossary = new function() {

    // ------------------------------------------------------------------------

    this.current = null;

    // ------------------------------------------------------------------------

    this.items = {};

    // ------------------------------------------------------------------------

    this.tpl = '<div class="glossary">'+
                '<div class="header">%POPUP_TITLE%</div>'+
                '<div class="main">%POPUP_CONTENT%</div>'+
                '<div class="footer"><a href="#" onclick="Zoomedia.Glossary.hide(\'div_%GLOSSARY_ID%\'); return false;">close</a></div>'+
               '</div>';

    // ------------------------------------------------------------------------

    this.setItems = function(items) {
      this.items = items;
    };

    // ------------------------------------------------------------------------

    this.show = function(a, id, event) {
      if (this.current) {
        this.hide(this.current);
      }

      var div = document.createElement('div');
          div.setAttribute('id', 'div_'+id);
          div.onclick = function() { Zoomedia.Glossary.hide( 'div_'+id ); };
          div.className = 'gloss_def';
          div.style.position = 'absolute';
      $(div).css('display','none');
      $(div).css('z-index', '2000');
      $(div).css('text-align','left');

    
      div.innerHTML = this.tpl.replace('%GLOSSARY_ID%', id).replace('%POPUP_TITLE%', this.items[id].title).replace('%POPUP_CONTENT%', this.items[id].content);

      $(div).insertAfter('body');

      $(div).offset({left: $(a).offset().left, top : $(a).offset().top});
      $(div).fadeIn('fast');
      
      this.current = 'div_'+id;

    };

    // ------------------------------------------------------------------------

    this.hide = function(eleId) {
      var div = document.getElementById(eleId);
      if (div) {
        div.parentNode.removeChild(div);
      }
    };

    // ------------------------------------------------------------------------

  };

  // --------------------------------------------------------------------------

  Zoomedia.FontSize = function(font_size) {
	  
	  // Write the text images
	  $("a#textsmall").css("background-position","0px 0px");
	  $("a#textmed").css("background-position","0px 0px");
	  $("a#textlarge").css("background-position","0px 0px");
	    
	  if (font_size == "small" || !font_size) {
		  $("a#textsmall").css("background-position","0px -16px");
	  }
	  if (font_size == "medium") {
		  $("a#textmed").css("background-position","0px -16px");
	  }
	  if (font_size == "large") {
		  $("a#textlarge").css("background-position","0px -16px");
	  }

    // ------------------------------------------------------------------------

    var sizes = ['small', 'medium', 'large'];

    // ------------------------------------------------------------------------

    var body = document.getElementById('wrapper');

    // ------------------------------------------------------------------------

    var current_font_size = 'medium';

    // ------------------------------------------------------------------------

    var match = document.cookie.match(/(?:font_size=(.+)(?:;?|$))/);

    // ------------------------------------------------------------------------

    if (match) {
      current_font_size = match[1];
      if (font_size == current_font_size) {
        //return;
      }
    }

    // ------------------------------------------------------------------------

    if (body) {
        
        body.className = body.className.replace('/ '+current_font_size+'/', '');

        body.className = ' '+font_size;

    }
    
    // -----------------------------------------------------------------------
    
    document.cookie = 'font_size='+font_size+';path=/;';

  };
  
  function getCookie(c_name) {
      if (document.cookie.length>0) {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1) {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
                return unescape(document.cookie.substring(c_start,c_end));
        }
      }
      return false;
  }

  // --------------------------------------------------------------------------

  Zoomedia.Form = new function() {

    // ------------------------------------------------------------------------

    this.submit = function(form) {
      document.getElementById(form).submit();
    };

    // ------------------------------------------------------------------------

    this.formatNumber = function(value) {
      return value.replace(/[^\d.]/g, '');
    };

    // ------------------------------------------------------------------------

    this.formatTelephoneNumber = function(value) {
      return value.replace(/[^\d]/g, '');
    };

    // ------------------------------------------------------------------------

  };

    // --------------------------------------------------------------------------

  Zoomedia.SharePage = new function(id) {

    // ------------------------------------------------------------------------

    this.timer = null;

    // ------------------------------------------------------------------------

    this.delay = 500;

    // ------------------------------------------------------------------------

    this.active = false;

    // ------------------------------------------------------------------------

    this.setActive = function(enabled) {
      this.active = enabled;
    };

    // ------------------------------------------------------------------------

    this.isActive = function() {
      return this.active;
    };

    // ------------------------------------------------------------------------

    this.setTimeOut = function(el) {
      var self = this;
      var id = el.getAttribute('id');
      this.timer = window.setTimeout(function() { self.mouseOut(document.getElementById(id)); }, this.delay);
    };

    // ------------------------------------------------------------------------

    this.hide = function(el) {
      this.setActive(false);
      document.getElementById('share-page-widget').style.display = 'none';
    };

    // ------------------------------------------------------------------------

    this.show = function(a) {
      //if (this.isActive()) {
        //return;
      //}

      this.setActive(true);

      var widget = document.getElementById('share-page-widget');
      if (widget) {
        widget.style.top  = (a.offsetTop + a.offsetHeight) + 'px';
        widget.style.left = a.offsetLeft+'px';
        widget.style.display = 'block';
      }

      return false;
    };

    // ------------------------------------------------------------------------

  }; //Zoomedia.SharePage

  // --------------------------------------------------------------------------

  function doLeave(href, cancel) {
      var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset;
      var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset;

      if (!scrolledX) { scrolledX = 0; }

      if (!scrolledY) { scrolledY = 0; }

      var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth;
      var screenHeight = document.documentElement.clientHeight || self.innerHeight;
      //alert(document.body.clientHeight);
      var left = (scrolledX + screenWidth - $("#divFloatPop").width())/2;
      var top = ((screenHeight - $("#divFloatPop").height())/2) + scrolledY;

      //Set the popup window to center
      $("#divFloatPop").css('top',  ''+top+'px');
      $("#divFloatPop").css('left', ''+left+'px');

      $("#divFloatPop").fadeIn("normal");
      $("#divFloatPop").html(leaving);
      $("#divFloatPop").append('<div style="clear: both; height: 25px"><!-- c --></div>');

      if (cancel) { $("#divFloatPop").append('<a href="#" onclick="return stay();">Cancel</a>'); }
      else { $("#divFloatPop").append('<a href="#" onclick="return stay();">Close</a>'); }

      if (href) {
          newtarget = 'target="_blank" onclick="stay();"';
          $("#divFloatPop").append('<a href="'+ destiNation +'" '+newtarget+'>Continue</a>');
      }
  }

  // --------------------------------------------------------------------------
  
  $(document).ready(function(){

	    // Cycle functions for HP Masthead
		$('#masthead div#cycle ul').cycle({ 
		    fx:     'fade', 
		    speed:  1000, 
		    timeout: 6000,
			easeIn: 'easeOutExpo',
			easeOut: 'easeOutExpo', 
			cleartype: false,
		    //next:   '#arrow-next', 
		    //prev:   '#arrow-previous',
			//after:	chgBodyBg, 
			pager: '#cyclePager',
			pagerAnchorBuilder: function(idx, slide) { 
		        // return selector string for existing anchor 
		        return '#cyclePager a:eq(' + idx + ')'; 
		    } 
		});
		
		// Txt resizer
        var currSize = ($.cookie('gerontxt')) ? $.cookie('gerontxt') : 0;
        if(!$('#content-main').hasClass('fontsize-'+ currSize)) {
            $('#content-main').addClass('fontsize-'+ currSize);
			$('#content-left').addClass('fontsize-'+ currSize);
        }
        $('#link-resize').click(function(e) {
			e.preventDefault();
            $('#content-main').removeClass('fontsize-'+ currSize);
			$('#content-left').removeClass('fontsize-'+ currSize);
            if(currSize == 2) {
                currSize = 0;
                $.cookie('regntxt', parseInt(currSize));
            } else {
                currSize = parseInt(currSize) + 1;
                $.cookie('regntxt', parseInt(currSize));
            }
            $('#content-main').addClass('fontsize-'+ currSize);
			$('#content-left').addClass('fontsize-'+ currSize);
        });
		
		// Arrow Links
		$('.secondary-block').click(function(e) {
			var linkObj = $(this).find('a.hpArrowLink');
			if(linkObj.attr('target') == "_blank" || linkObj.attr('target') == "_new") {
				window.open(linkObj.attr('href'));
			} else {
				window.location = linkObj.attr('href');
			}
			
		});
		
		//Hide (Collapse) the toggle containers on load
	    //$("#social").hide(); 

	    $("#link-share").click(function(){
	    	$('#social').animate({width: 'toggle'}, 1000);
	    });
	    
		$('a.details').click(function(e) {
			e.preventDefault();
			var id = $(this).attr('href');
			if($(id).css('display') == 'none') {
				$(id).slideDown();
			} else {
				$(id).slideUp();
			}
		});
		
		$('.timeline-section h2').click(function() {
			var timelineItem = $(this).parent('.timeline-section').find('ul');
			if(timelineItem.css('display') == 'none') {
				timelineItem.slideDown();	
			} else {
				timelineItem.slideUp();
			}
		})
	    
	 // MODAL WINDOW ACTIONS
	    $('a[name=modal]').click(function(e){
	        // Cancel the link behavior
	        e.preventDefault();
	        launchWindow($(this).attr('href'));
	    });

	    // MODAL WINDOW CONTROLS
	    // if close button is clicked
	    $('.window .close, #popup_container .close').click(function(e){
	        if ($(this).hasClass('go') == false) {
	            // Cancel the link behavior
	            e.preventDefault();
	        }
	        
	        $('#mask, .window').hide();
	    });
	    $('#popup_container a.close').click(function(e){
	        e.preventDefault();
	        $('#popup_container').fadeOut();
	    });

	    $('a.closePop, #fade').live('click', function(e){ //When clicking on the close or fade layer...
	        e.preventDefault();
	        $('#fade , .popup_block').fadeOut(function(){
	            $('#fade, a.close').remove(); //fade them both out
	        });
	        
	    });
	    
		// Init tabs
		//$("#tabs").tabs();
		
				
 		// Flow player functions
		var objRegEx = /^[0-9]*$/;
		// get the query string using JQuery.Query plugin
		var start = $(document).getUrlParam('start');
		// validate the query string and dump the <a> content to autoplay
		if (!(objRegEx.test(start)) || start == "") { start = "0" };
		if (start > 0) { $("#rtmpPlayer").html(""); }
        // run flowplayer once the page is ready
        try {
			flowplayer("rtmpPlayer", "/swf/flowplayer-3.2.7.swf", {
				plugins: {
					rtmpt: {
						url: '/swf/flowplayer.rtmp-3.2.3.swf',
						netConnectionUrl: 'rtmpt://shdks8wxy6j5o.cloudfront.net/cfx/st',
						durationFunc: 'getStreamLength'
					}
				},
				clip: {
					provider: 'rtmpt',
					start: start,
					scaling: 'fit',
					autobuffering: 'true',
					bufferLength: 3
				},
				key: '#$6385e3f9d657f220223'
			});
		} catch (err) {
			return;
		}
        

	});

