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

  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.style.display = 'none';
          div.style.zIndex = 2000;

          /*offset = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
          if (!offset) {
            offset = 0; // stupid ie5/mac
          }

          div.style.top = (offset + event.clientY)+'px';
          div.style.left = event.clientX+'px';*/

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

      //insert div before anchor tag
      a.parentNode.insertBefore(div, a);

      div.style.top  =  (a.offsetTop - a.clientHeight - div.clientHeight) + 'px';
	  if(a.offsetLeft > 350) {
	  	div.style.left = (a.offsetLeft - 180) + 'px';
	  } else {
	  	div.style.left = a.offsetLeft + 'px';
	  }
      div.style.display = 'block';

      this.current = 'div_'+id;

      //close removes the dynamically created div
      //div.parentNode.removeChild(div);
    };

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

    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").html('<img src="/img/textsize_sm_off.gif" />');
	$("a#textmed").html('<img src="/img/textsize_med_off.gif" />');
	$("a#textlarge").html('<img src="/img/textsize_lg_off.gif" />');
	$("a#textsmall_hcp").html('<img src="/img/textsize_hcp_sm_off.gif" />');
	$("a#textmed_hcp").html('<img src="/img/textsize_hcp_med_off.gif" />');
	$("a#textlarge_hcp").html('<img src="/img/textsize_hcp_lg_off.gif" />');
	
	if (font_size == "small" || !font_size) {
		$("a#textsmall, a#textsmall_hcp").html('<img src="/img/textsize_sm_on.gif" />');
	}
	if (font_size == "medium") {
		$("a#textmed, a#textmed_hcp").html('<img src="/img/textsize_med_on.gif" />');
	}
	if (font_size == "large") {
		$("a#textlarge, a#textlarge_hcp").html('<img src="/img/textsize_lg_on.gif" />');
	}
	
	// ------------------------------------------------------------------------

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

    // ------------------------------------------------------------------------
    
    var body = document.getElementById('content');

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

    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;
  }
  
  // --------------------------------------------------------------------------

  var hbx = undefined;

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

  Zoomedia.Form = new function() {

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

    this.submit = function(form) {
      if (hbx != undefined) {
        hbx.pn += '+FORM+SUBMIT';
      }
      document.getElementById(form).submit();
    };

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

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

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

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

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

  };

  // --------------------------------------------------------------------------
  
  var topVal;
  var leaving;
    
  $(document).ready(function () {
	
  	$("select[id='specialty']").change(function () {
	  window.location = $(this).val();
    });
	
	$("input[id='mailbrochures']").click(function () {
	  $("#mailbrochures_form").fadeIn("normal");
    });
	
	$("input[id='callme']").click(function () {
	  $("#callme_form").fadeIn("normal");
    });
	
	$("a.prompt").click(function(e) {
		topVal = null;
		topVal = e.pageY - 10 + "px";
		destiNation = $(this).attr("href");
		leaving = "The information provided in this section is intended expressly for healthcare professionals in the United States. Click 'Continue' to enter if you are a U.S. healthcare professional.";
		doLeave(destiNation, false);
		return false;	
	});
	
	$("a.leaving_prompt").click(function(e) {
		topVal = null;
		topVal = e.pageY - 10 + "px";
		destiNation = $(this).attr("href");
		leaving = "Links to these third-party websites are provided as a convenience. We have no control over the information you will find there. Providing these links does not imply any endorsement of their content on our part. We assume no responsibility or liability for any third-party content. ";
		doLeave(destiNation, false);
		return false;	
	});
	
	$("a.us_info_popup").click(function(e) {
		topVal = null;
		topVal = e.pageY - 10 + "px";
		leaving = "Information posted to this Web site is intended for U.S. residents. The telescope implant is a medical device used in the CentraSight treatment patient care program. The telescope implant has been granted a CE Mark in Europe and MOH approval in Israel, but is not yet available for sale outside the US.";
		destiNation = $(this).attr("href");
		doLeave(false, false);
		return false;	
	});
  
  });
  
  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.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;

    var left = (scrolledX + screenWidth - $("#divFloatPop").width())/2;
    var top = (scrolledY + screenHeight - $("#divFloatPop").height())/2;

    //Set the popup window to center
    $("#divFloatPop").css('top',  topVal);
    $("#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) {
		$("#divFloatPop").append('<a href="'+ destiNation +'" onclick="setCookie(\'US\', \'1\', null);">Continue</a>');
	} 
	
  }
  
  function stay() {
		destiNation = '';
		$("#divFloatPop").fadeOut("normal");
		return false;	  
  }


  // --------------------------------------------------------------
  
  function toggleVideo(show, hide, videoinfo) {	
	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.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;
	
	var viddata = videoinfo.split("|");
	
	if (hide != "") {
		hide = hide.split(",");
		for (x in hide) {
			if (hide[x] != show) {
				document.getElementById(hide[x]).style.display = "none";
			}
		}
	}
		
	if (show != "") {	
		show = show.split(",");
		for (y in show) {
			if (show[y] != hide) {	
				var left = (scrolledX + screenWidth - $("#"+show[y]).width())/2;
	   		    var top = (scrolledY + screenHeight - $("#"+show[y]).height())/2;			  
				$("#"+show[y]).css('top',  ''+top+'px');
			    $("#"+show[y]).css('left', ''+left+'px');
				$("#"+show[y]).fadeIn("normal");
				$("#"+show[y]).html('');
				html = "<embed width=\"438\" height=\"350\" flashvars=\"div_container=" + show[y] + "\" allowscriptaccess=\"always\" wmode=\"transparent\" quality=\"high\" bgcolor=\"#000000\" src=\"/swf/flv_player.swf?div_container=" + show[y] + "&videoName=" + viddata[0] + "&videoTitle=" + viddata[1] + "&divName=" + show[y] + "\" type=\"application/x-shockwave-flash\"/>";
				$("#"+show[y]).html(html);
			}
		}
	}
		
  }
  
  function close_div (divid) {
		document.getElementById(divid).innerHTML = "";
		document.getElementById(divid).style.display = "none";
  }
  
  // -------------------------------------------------------------


