IE7_PNG_SUFFIX=".png";

Prototype.Browser.IE6 = Prototype.Browser.IE && (
  parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6
);

var currentBubble;
var bubbleInfo;
var bubbleTransition = false; 

function setCurrentBubble(bubble) {
  bubbleInfo = {
    originalTop: bubble.getStyle('top'),
    originalLeft: bubble.getStyle('left')
  };
  currentBubble=bubble;
}

Event.observe(document, 'dom:loaded', function() {
  $$(".bubble").each(function(b) {
    
    if(Prototype.Browser.IE) {
      b.insert(new Element("div", { className: "top-left" }));
      b.insert(new Element("div", { className: "top-right" }));
      b.insert(new Element("div", { className: "right" }));
      b.insert(new Element("div", { className: "bottom-left" }));
      b.insert(new Element("div", { className: "bottom-right" }));
    }
    
    
    b.observe('mouseover', function() {
      if(currentBubble==b || bubbleTransition) return;
      b.addClassName("active");
    });
    b.observe('mouseout', function() {
      if(currentBubble==b || bubbleTransition) return;
      b.removeClassName('active');
    });
    b.observe('click', function() {
      if(currentBubble==b && !bubbleTransition) {
        document.location.href = b.select("a")[0].getAttribute('href');
      };
      if(bubbleTransition) return;
      
      setCurrentBubble(b);
      
      // Bring to foreground, hack for ie6
      b.addClassName("front");
      if(Prototype.Browser.IE6)
        b.siblings().each(function(s) { s.hide(); });
      
      var closeButton = b.select(".closeButton")[0];
      var m =  b.select(".m")[0];
      
      new Effect.Parallel([
        new Effect.Move(b, {
          sync: true,
          x: 0, y: 0,
          mode: 'absolute',
          transition: Effect.Transitions.sinoidal
        }),
        new Effect.Scale(b, 460, {
          sync: true,
          scaleY: true,
          scaleContent: false,
          scaleMode: { originalHeight: 189, originalWidth: 98 },
          transition: Effect.Transitions.sinoidal
        }),
        new Effect.Scale(b, 205, {
          sync: true,
          scaleContent: true,
          scaleX: false,
          scaleMode: { originalHeight: 189, originalWidth: 98 },
          transition: Effect.Transitions.sinoidal
        })
      ], {
        afterFinish: function() {
          var cimg = m.select(".img")[0];
          cimg.hide();
          b.removeClassName("active");
          b.addClassName("expanded");
          bubbleTransition = false;
          closeButton.show();
          new Effect.Fade(cimg, { from: 0, to: 1, beforeSetup: function() { cimg.show(); } });
          closeButton.observe('click', function() {
            b.removeClassName('expanded');
            if(window['IE7']) {
              cimg.remove();
              m.insert(new Element("div", { className: "img" }));
            }
            bubbleTransition = true;
            closeButton.hide();
            new Effect.Parallel([
              new Effect.Scale(b, 22, { sync: true, scaleY: false, transition: Effect.Transitions.sinoidal }),
              new Effect.Scale(b, 47, { sync: true, scaleX: false, transition: Effect.Transitions.sinoidal }),
              new Effect.Move(b, {
                transition: Effect.Transitions.sinoidal,
                sync: true,
                x: parseInt(bubbleInfo.originalLeft),
                y: parseInt(bubbleInfo.originalTop),
                mode: 'absolute'
              })
            ], {
              afterFinish: function() {
                currentBubble=null;
                b.removeClassName('front');
                if(Prototype.Browser.IE6)
                  b.siblings().each(function(s) { s.show(); });
                bubbleTransition = false;
              }
            });
          });
        }
      });
    });
  });
  $("video-container").hide();
  $("play_movie").observe("click", function() {
    playVideo()
  });
  
});

var videoContainer = null;
var video = null;
function playVideo() {
  $("homeCol02").setStyle({'visibility': 'hidden'});
  videoContainer = $("video-container").show();
  video = new SWFObject("/media/manor-video.swf", "manor_video", "640", "360", "6.0.65");
  video.addParam("wmode", "transparent");
  video.write("video-container");
}

window.closeVideo = function() {
  $("homeCol02").setStyle({'visibility': 'visible'});
  $("video-container").hide();
  while($("video-container").childElements().length) $("video-container").childElements()[0].remove();
}