/* Implement Ajax Loading Stuff */
var AjaxEvents = {
  'onAjaxRequest': function() {
    $('ajaxLoading').setStyles({
      display:'block',
      top: (window.getScrollTop() + ((window.getHeight() - 32) / 2)) + 'px'
    });
  },
  'onAjaxSuccess': function(responseText, responseXML) {
    $('ajaxLoading').setStyles({display:'none'});
  },
  'onAjaxFailure': function(xhr) {
    $('ajaxLoading').setStyles({display:'none'});
  },
  'onAjaxException': function(headerName, value) {
    $('ajaxLoading').setStyles({display:'none'});
  }
}

Request.prototype.addEvents({
  'onRequest': AjaxEvents.onAjaxRequest,
  'onSuccess': AjaxEvents.onAjaxSuccess,
  'onFailure': AjaxEvents.onAjaxFailure
});

var setValue = function(el, defaultValue) {
  if (el.value == defaultValue) {
    el.value= '';
  } else if (el.value == '') {
    el.value= defaultValue;
  }
}

var decorateContainer = function() {
  $(document.body).getElements('div.container').each(function(item){
      var container_top_left = new Element('div', {'class': 'containerTopLeft'});
      var container_top_right = new Element('div', {'class': 'containerTopRight'});
      var container_bottom_left = new Element('div', {'class': 'containerBottomLeft'});
      var container_bottom_right = new Element('div', {'class': 'containerBottomRight'});
      container_top_left.inject(item,'top');
      container_top_right.inject(item,'top');
      container_bottom_left.inject(item,'top');
      container_bottom_right.inject(item,'top');
  });
}

var mooflowInit = function(id) {
  var mf = new MooFlow($(id), {
             reflection: 0.3,
             heightRatio: 0.5,
             offsetY: 10,
             startIndex: 0,
             interval: 3500,
             factor: 165,
             bgColor: 'transparent',
             useCaption: false,
             useResize: false,
             useSlider: false,
             useWindowResize: false,
             useMouseWheel: false,
             useKeyInput: false,
             useViewer: false,
             'onClickView': function(mixedObject){
               if (mixedObject.alt && mixedObject.alt.match(/^(http|https)/)) window.location = mixedObject.alt;
             }
           });
  mf.play();
}

var ajaxPngFixIE6 = function() {
  var arVersion = navigator.appVersion.split("MSIE");
  var version = parseFloat(arVersion[1]);
  if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
    var images = document.body.getElements('img[src$=png]');
    images = images.concat(document.body.getElements('img[src^=/image/text]'));
    images.each(function(img) {
      DD_belatedPNG.fixPng(img);
    });
  }
}

window.addEvent('load', function () {
	new Tips($$('.globaltip'), {});
  new Tips($$('.globaltip_navi'), {'className':'naviTip'});
});

window.addEvent('domready', function() {
  decorateContainer();
  ajaxPngFixIE6();
});
