﻿function showHideDots(show,regionkey) 
{
    var dots = $j('div.dot.'+regionkey);
    var onDots = $j('div.doton.'+regionkey);
    if (show == 'hide') 
    {
        dots.hide();
        onDots.show();
    }
    else if (show == 'show') 
    {
        onDots.hide();
        dots.show();
    }
}
function showLocationContent(callingLocation) 
{
    var location = $j(callingLocation);
    location.show();
}
function hideLocationContent(callingLocation) 
{
    var location = $j(callingLocation);
    location.hide();
}
function showHideLocationContent(show, callingDot) 
{
    var dot = $j(callingDot);    
    var id = dot.attr('id');
    var longLatStr = "";
    var locationID = "";        
    if (id) {
        longLatStr = id.replace(/dot/,"");
        locationID = "locationpop"+longLatStr;
    }    
    var locationpop = null;
    if (locationID) {
        locationpop = $j('#'+locationID);
        if (locationpop.length == 0) {
            // make a locationpop div for this office location above the current dot div
            var locationTemplate = $j("#locationpop_template");
            var office = $j("#office"+longLatStr);
            if (locationTemplate.length == 1 && office.length == 1) {            
                // create a new copy of the locationTemplate
                var locationContent = locationTemplate.html().replace(/locationpopid/, locationID);
                dot.before(locationContent);
                locationpop = $j('#'+locationID);
                if (locationpop.length == 1) {
                    var bubbleContent = locationpop.find(".bubble_content");
                    if (bubbleContent.length == 1) {
                        // create a copy of the office content
                        bubbleContent.html(office.html());
                    }
                    var locationpopCss = {
                        left: dot.css('left'),
                        top: dot.css('top')
                    }
                    locationpop.css(locationpopCss);
                    //locationpop.style.top = dot.style.top;
                }                
            }
        }
    }
    if (locationpop.length == 1)
    {
        if (show == 'show')
            showLocationContent(locationpop);
        else
            hideLocationContent(locationpop);
    }
    
    // get corresponding location div
    var a = 0;
}

function mouseOver(onimage, regionkey, eventObject) 
{
    MM_swapImage('Image1','',onimage,1);
    showZoom('clickToZoom', eventObject);
    showHideDots('hide',regionkey);
    return true;
}
function mouseOut(regionkey) 
{
    MM_swapImgRestore();
    MM_showHideLayers('clickToZoom','','hide');
    showHideDots('show',regionkey);
}

function MapCallbackResults(results) {
    $j("#globe_loc").html(results);
    $j("#globe_loc a.external, #globe_loc a.genzymeother").bind("click", buildExternalModalBox);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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_showHideLayers() { //v6.0
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v; }
}

// for older browsers
if (document.all || document.getElementById){ //if IE4 or NS6+
	document.write('<style type="text/css">\n')
	document.write('.location_US{display: none; width: 500px; height: 150px;}\n')
	document.write('</style>')
}
	
var currentState="ALL"

function getElementByClass(classname){

	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++){
		if (classname.length > 0) {
			if ((alltags[i].className.indexOf(currentState)) > -1) alltags[i].style.display="none"//; alert("old "+currentState)
			if ((alltags[i].className.indexOf(classname)) > -1) alltags[i].style.display="block"//; alert("new "+classname)
		} else {
			if ((alltags[i].className.indexOf(currentState)) > -1) alltags[i].style.display="block"
		}
	}
	if (classname.length > 0) currentState=classname
	if (classname.length < 1) alert("name less than 1")
	}


	window.onload=function(){
	if (document.all || document.getElementById){
		getElementByClass(currentState)
	}
}

function showZoom(layer, eventObject){
	//shows click to zoom image near mouse location

	eventObject = $j.event.fix(eventObject); // get jquery event object to enable use of pageX/Y in IE
	var element, show;
	
	var $elementTest = $j(element);	
	
	mousePositionX = eventObject.pageX + document.body.scrollLeft;
	mousePositionY = eventObject.pageY + document.body.scrollTop;
	
	element = document.getElementById(layer);
	
	if (element != null) {
		element.style.left = (mousePositionX + 5) + 'px';
		element.style.top = (mousePositionY + 5) + 'px';
		show = true;
		element.style.display = show ? 'block' : 'none';
		element.style.visibility = show ? 'visible' : 'hidden';
	}
}

