if (typeof FE == 'undefined')
 var FE = {};

FE._SAFARI = navigator.userAgent.indexOf('Safari') != -1;
FE._OSX = navigator.userAgent.indexOf('OS X') != -1;
FE._MOZILLA = navigator.userAgent.indexOf('Mozilla') != -1;
FE._scrollFix = true;//(FE._MOZILLA && FE._OSX) || FE._SAFARI;

FE.addListener = function(element, name, observer) {
  if (element.addEventListener) {
      element.addEventListener(name, observer, false);
    } else if (element.attachEvent) {
      element.attachEvent('on' + name, observer);
    }
}
FE.disableSelection = function(element) {
    element.onselectstart = function() {
        return false;
    };
    element.unselectable = "on";
    element.style.MozUserSelect = "none";
    element.style.cursor = "default";
}
FE.openURL = function(url, target) {
 window.open(url, target);
}

FE.cancelEvent = function(eventObject) {
        if(eventObject) {
                if (eventObject.stopPropagation) eventObject.stopPropagation();
                if (eventObject.preventDefault) eventObject.preventDefault();
        }
}

FE.isRightClick = function(e) {
        var rightclick;
        if (!e) var e = window.event;
        if (e.which) rightclick = (e.which == 3);
        else if (e.button) rightclick = (e.button == 2);
        return rightclick;
}

FE._rightClickDown = function(e) {
  var target = e.target || e.srcElement;
  if (target != FE._flash) return;
  if (!FE.isRightClick(e))
   return;
  FE.cancelEvent(e);
  FE._rightDown = true;
  var x = e.pageX || e.clientX; var y = e.pageY || e.clientY;
  FE._flash._rightClickDown(x, y);
  return false;
}
FE._rightDown = false;
FE._rightClickUp = function(e) {
 var target = e.target || e.srcElement;
 if (target == FE._flash && FE._rightDown) {
  FE.cancelEvent(e);
  FE._rightDown = false;
  var x = e.pageX || e.clientX; var y = e.pageY || e.clientY;
//  FE._flash._rightClickUp(x, y);
 }
}

FE._rightClickMove = function(e) {
 if (!FE._rightDown)
  return;
 FE.cancelEvent(e);
 var x = e.pageX || e.clientX; var y = e.pageY || e.clientY;
 FE._flash._rightClickMove(x, y);
}

FE._flash = null;
FE._flashContainer = null;
FE._rightClickTakeover = function(container, flash) {
 FE._rightDown = false;
 if (window.addEventListener) {
  window.addEventListener('mousedown', FE._rightClickDown, true);
  window.addEventListener('mouseup', FE._rightClickUp, true);
  window.addEventListener('mousemove', FE._rightClickMove, true);
 } else {
  document.oncontextmenu = function() {
        return false;
//   if (window.event.srcElement == FE._flash) { return false; } else { return true; };
  }
  FE._flashContainer.onmouseup = function() {
   FE._rightClickUp(window.event);
   this.releaseCapture();
  }
  FE._flashContainer.onmousedown = function() {
   var e = window.event;
   if (!FE.isRightClick(e)) return;
   this.setCapture();
   FE._rightClickDown(e);
  }
  FE._flashContainer.onmousemove = function() {
   FE._rightClickMove(window.event);
  }
 }
}

FE._onMouseScroll = function(e) {
        if (FE._scrollFix) {
         e = e || window.event;
         var delta = e.wheelDelta / -15 || e.detail;
         if (FE._OSX && FE._SAFARI) delta /= 10;
         FE._flash._onMouseScroll(delta);
        }
        if (!e) var e = window.event;
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
        if (e.preventDefault) e.preventDefault();
        e.returnValue = false;
//      return false;
}

if (typeof FE.InfoWindow == 'undefined')
 FE.InfoWindow = {};

FE.InfoWindow._init = function() {
 var ih = document.createElement('div');
 ih.style.position = 'absolute';
 ih.style.display = 'none';
 ih.style.fontSize = '12px';
 ih.style.overflowY = 'auto';
 ih.style.overflow = 'auto';
 ih.style.color = 'black';
 ih.id = 'FE_InfoWindow';
 document.body.appendChild(ih);
 FE.InfoWindow._ih = ih;
}

FE.InfoWindow._getOffset = function(forElement) {
    var valueT = 0, valueL = 0;
    do {
      valueT += forElement.offsetTop  || 0;
      valueL += forElement.offsetLeft || 0;
      forElement = forElement.offsetParent;
    } while (forElement);
    return [valueL, valueT];
}

FE.InfoWindow._show = function(x, y, visible) {
 var offset = FE.InfoWindow._getOffset(FE._flashContainer);
 FE.InfoWindow._ih.style.top = offset[1] + y + 'px';
 FE.InfoWindow._ih.style.left = offset[0] + x + 'px';
 if (visible)
  FE.InfoWindow._ih.style.display = 'block';
 else
  FE.InfoWindow._ih.style.display = 'none';
}

FE.InfoWindow._hide = function() {
 FE.InfoWindow._ih.style.display = 'none';
}

FE.InfoWindow._open = function(width, height) {
 FE.InfoWindow._ih.style.width = width + 'px';
 FE.InfoWindow._ih.style.height = height + 'px';
}

FE.InfoWindow._setContent = function(content) {
 FE.InfoWindow._ih.innerHTML = content;
}

FE.fixWheel = function(flashApplet) {
   try {
    if (flashApplet.addEventListener)
     flashApplet.addEventListener('DOMMouseScroll', FE._onMouseScroll, FE._scrollFix);
    flashApplet.onmousewheel = FE._onMouseScroll;
   } catch(e) {
   }
}

FE.GetWindowSize = function(w) {
        w = w ? w : window;
        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        return [width, height]
}

FE.AC_Generateobj = function(objAttrs, params, embedAttrs)
{
    var str = '';
    if (!FE._MOZILLA && !FE._SAFARI)
    {
                str += '<object ';
                for (var i in objAttrs)
                        str += i + '="' + objAttrs[i] + '" ';
                for (var i in params)
                        str += '><param name="' + i + '" value="' + params[i] + '" /> ';
                str += '></object>';
    } else {
                str += '<embed ';
                for (var i in embedAttrs)
                        str += i + '="' + embedAttrs[i] + '" ';
                str += '> </embed>';
    }

    return str;
}

FE.AC_FL_RunContent = function(){
  var ret =
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return FE.AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

FE._mapGenerator = function(container, swfURL, params) {
			var size = FE.GetWindowSize();
			width = params['width'] || size[0];
			height = params['height'] || size[1];
                        var r = FE.AC_FL_RunContent(
                        'height', height,
                        'width' , width,
                        "src", swfURL,
			'quality' , params['quality'],
                        "bgcolor", params['bgcolor'] || "#000000",
                        "allowFullScreen", "true",
                        "allowScriptAccess","always",
                        "type", "application/x-shockwave-flash",
                        "pluginspage", "http://www.adobe.com/go/getflashplayer",
                        'menu', 'false',
                        'wmode', 'opaque',
			'flashvars', params['flashvars'] || '',
			'id', '_flash'
                        );
                        return r;
};

FE.initialize = function(container, swfURL, params) {
 FE._flashContainer = container;
 container.innerHTML = FE._mapGenerator(container, swfURL, params || {});
 FE._flash = document.getElementById('_flash');
 FE.fixWheel(FE._flash);
 FE.InfoWindow._init();
 setTimeout(function() {
    FE._rightClickTakeover(FE._flashContainer, FE._flash);
   }, 100); 
}
