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


var Rules = {
  'a.load:click': function(element,event) {
    Event.stop(event);
    element = Event.findElement(event,'a');
    var options = element.className.split('load ')[1].split(' ');
    Controller.Top = Event.pointerY(event);
    if (options[0] == 'update')
      new Ajax.Updater(options[1],element.href);
    else if (options[0] == 'cover')
      new Ajax.Request(element.href,{onComplete: Controller.Cover.Load});
    else
      new Ajax.Request(element.href);
  },
  'h1:loaded': function(element) {
    element.innerHTML = Controller.FlashTag("/fonts/maximo.swf", element.offsetWidth, element.offsetHeight, "txt=" + element.innerHTML.replace(/\+/ig,"%2B").replace(/\&/g,"%26").replace(/\"/g, "%22") + "&w=" + element.offsetWidth + "&h=" + element.offsetHeight);
  },
  'h2:loaded': function(element) {
    element.appendChild(Builder.node("img",{alt: "h2_left", className: "top_left", src: "/images/corners/h2_left.gif"}));
    element.appendChild(Builder.node("img",{alt: "h2_right", className: "top_right", src: "/images/corners/h2_right.gif"}));
  },
  "input.swap:click": function(element) {
    var options = element.className.split("swap ")[1].split(" ");
    Element.hide(options[0]);
    Element.show(options[1]);
    if (options[2])
      eval(options[2] + "();");
  },
  '.tab:click': function(element) {
    var options = element.className.split("tab ")[1].split(" ");
    var current_tab = $$(".tab.active")[0];
    current_tab.className = current_tab.className.replace(" active","");
    if (img = Element.down(current_tab,"img")) {
      img.src = img.src.replace("_active","");
    }
    element.className +=" active";
    if (img = Element.down(element,"img")) {
      img.src = img.src.replace("tab_","tab_active_");
    }
    $("tabset").getElementsByClassName("tab_holder").each(function(holder) {
      if (holder.id == options[0])
        holder.style.display = "";
      else
        holder.style.display = "none";
    });
  },
  '#newsletter_textbox:focus': function(element) {
    if (element.value == "your e-mail")
      element.value = "";
  },
  '#newsletter_textbox:blur': function(element) {
    if (element.value == "")
      element.value = "your e-mail";
  },
  '#cover_opacity:click, #cover_close:click': function() {
    $('cover').style.display = "none";
  }
}

var Controller = {
  Cover: {
    Load: function(response) {
      var container = $('cover_container');
      if (response)
        container.innerHTML = response.responseText;
      var opacity = $('cover_opacity');
      var cover = $('cover');
      var close = $('cover_close');
      var dimensions = Element.getDimensions(document.body);
      var cdimensions = Element.getDimensions(container);
      if (Controller.Top && (Controller.Top - cdimensions.height - 30) > 0) {
        container.style.top = (Controller.Top - cdimensions.height - 30) + 'px';
        close.style.top = (Controller.Top - cdimensions.height - 23) + 'px';
      } else {
        container.style.top = "10px";
        close.style.top = "3px";
      }
      if (Element.getDimensions(cover).height < dimensions.height)
        cover.style.height = dimensions.height + 'px';
      cover.style.display = "";
      container.style.display = "";
    }
  },
  FlashTag: function(src, width, height, vars, bgcolor) {
    var version = '7,0,14,0';
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var tag = new String();
    if (ie) {
      tag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
      tag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" ';
      tag += 'width="'+width+'" ';
      tag += 'height="'+height+'">';
      tag += '<param name="movie" value="'+src+'"/>';
      tag += '<param name="quality" value="best"/>';
      tag += '<param name="wmode" value="transparent"/>'
      tag += '<param name="flashvars" value="'+vars+'"/>';
      tag += '</object>';
    } else {
      tag += '<embed src="'+src+'" ';
      tag += 'quality="best" ';
      tag += 'wmode="transparent" '
      tag += 'width="'+width+'" ';
      tag += 'height="'+height+'" ';
      tag += 'type="application/x-shockwave-flash" ';
      tag += 'flashvars="'+vars+'" ';
      tag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
      tag += '</embed>';
    }
    return tag;
  }
}

var Handlers = {
  onCreate: function() {

  },
  onComplete: function() {
    if (Element.visible('spinner') && Ajax.activeRequestCount == 0) {
      new Effect.Fade('spinner',{queue:'end',duration:.5});
      EventSelectors.assign(Rules);
    } else
      setTimeout("Handlers.onComplete()",1000);
  }
}
Ajax.Responders.register(Handlers);


function parseBoolean(value) {
  return value.toLowerCase() == 'true'
}

function reapply() {
  EventSelectors.assign(Rules);
}




// EventSelectors 
// Copyright (c) 2005-2006 Justin Palmer (http://encytemedia.com)
// Examples and documentation (http://encytemedia.com/event-selectors)
// 
// EventSelectors allow you access to Javascript events using a CSS style syntax.
// It goes one step beyond Javascript events to also give you :loaded, which allows 
// you to wait until an item is loaded in the document before you begin to interact
// with it.
//
// Inspired by the work of Ben Nolan's Behaviour (http://bennolan.com/behaviour)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
// This version of the software includes the Sasser fix to remove the infinite
// loop on element:loaded when there are more than one element

var EventSelectors = {
  version: '1.0_pre',
  cache: [],
  
  start: function(rules) {
    this.rules = rules || {};
    this.timer = new Array();
/*    this.startTime = new Date(); */
    this._extendRules();
    this.assign(this.rules);
  },
  
  assign: function(rules) {
    var observer = null;
	  var x = 0;
    this._unloadCache();
    rules._each(function(rule) {
      var selectors = $A(rule.key.split(','));
      selectors.each(function(selector) {        
        var pair = selector.split(':');
        var event = pair[1];
        $$(pair[0]).each(function(element) {
          if(pair[1] == '' || pair.length == 1) return rule.value(element);
          if(event.toLowerCase() == 'loaded') {
			      x++;
            this.timer[pair[0] + x] = setInterval(this._checkLoaded.bind(this, element, pair[0] + x, rule), 15);
          } else {
            observer = function(event) {
              var element = Event.element(event);
              if (element.nodeType == 3) // Safari Bug (Fixed in Webkit)
            		element = element.parentNode;
              rule.value($(element), event);
            }
            this.cache.push([element, event, observer]);
            Event.observe(element, event, observer);
          }
        }.bind(this));
      }.bind(this));
    }.bind(this));
/*    document.write('event:Selectors Execution: ' + (new Date() - this.startTime) + 'ms');*/
  },
  
  // Scoped caches would rock.
  _unloadCache: function() {
    if (!this.cache) return;
    for (var i = 0; i < this.cache.length; i++) {
      Event.stopObserving.apply(this, this.cache[i]);
      this.cache[i][0] = null;
    }
    this.cache = [];
  },
  
  _checkLoaded: function(element, timer, rule) {
    var node = $(element);
    if(element.tagName != 'undefined') {
      clearInterval(this.timer[timer]);
      rule.value(node);
    }
  },
  
  _extendRules: function() {
    Object.extend(this.rules, {
     _each: function(iterator) {
       for (key in this) {
         if(key == '_each') continue;         
         var value = this[key];
         var pair = [key, value];
         pair.key = key;
         pair.value = value;
         iterator(pair);
       }
     }  
    });
  }
}

// Remove/Comment this if you do not wish to reapply Rules automatically
// on Ajax request.
// Ajax.Responders.register({
//   onComplete: function() { EventSelectors.assign(Rules);}
// })