function showLensCalculator() {
  $.get('/tools/calculator', {}, function(html) {
    var element = $(html);
    var popup = $.popup(element, 'calculator_popup', { closeOnClickMask: true });
  }, 'html');
}

$(function() {
  $('button').each(function() {
    $(this).wrapInner('<span><span></span></span>')
  });
  $('#global_navigation div.current').append('<img src="/images/empty.gif" />');
  $('#footer').css('bottom', '1px');
  
  var path = $('#start_flash').attr('data-flash');
  $('#start_flash').flash({
    swf: path,
    width: 939,
    height: 131,
    hasVersion: 8,
    wmode: 'opaque'
  });
  
  var vision_path = $('#vision_flash').attr('data-flash');
  $('#vision_flash').flash({
    swf: vision_path,
    width: 939,
    height: 185,
    hasVersion: 8,
    wmode: 'opaque'
  });
});


(function($) {

  function _ajax_request(url, data, callback, type, method) {
      if (jQuery.isFunction(data)) {
          callback = data;
          data = {};
      }
      return jQuery.ajax({
          type: method,
          url: url,
          data: data,
          success: callback,
          dataType: type
          });
  }

  $.extend({
      put: function(url, data, callback, type) {
          return _ajax_request(url, data, callback, type, 'PUT');
      },
      delete_: function(url, data, callback, type) {
          return _ajax_request(url, data, callback, type, 'DELETE');
      }
  });
  
  /* Nano Templates (Tomasz Mazur, Jacek Becela) */
  $.nano = function(template, data) {
    return template.replace(/\{([\w\.]*)}/g, function(str, key) {
      var keys = key.split("."), value = data[keys.shift()]
      $.each(keys, function(){ value = value[this] })
      return value
    });
  }
  
  $.fn.template = function() {
    return this.html().replace('%7B', '{').replace('%7D', '}')
  }
  

  try {
  function overlayStyles() {
    return {
      'display': 'block',
      'position': 'absolute',
      'top': '0',
      'left': '0',
      'width': '100%',
      'height': $(document).height(),
      'z-index': '15000'
    }
  }

  function popupObject(elements, handler) {
    return {
      'elements': elements,
      'handler': handler,
      'close': function() { 
          $(window).unbind('scroll', this.handler);
          $(window).unbind('resize', this.handler);
          this.elements.remove();
        }
    }
  }

  $.popup = function(element, containerClass, options) {
    if (typeof(containerClass) == 'undefined') { containerClass = 'default'; }
    if (typeof(options) == 'undefined') { options = {} }

    var elements = $('<div class="' + containerClass + '"></div>')
    var overlay = $('<div class="mask"></div>').css(overlayStyles()).appendTo(elements);
    $(element).css({
      'z-index': '15001',
      'position': 'absolute'
    });
    elements.appendTo('body');
    element.addClass('popup').appendTo(elements).center();

    var resizeHandler = function() { 
      try {
        element.center(); 
        overlay.fillWindow(); 
      } catch(e) { alert(e); }
    };
    $(window).scroll(resizeHandler);
    $(window).resize(resizeHandler);

    var result = popupObject(elements, resizeHandler);
    if (options['closeOnClickMask']) {
      overlay.click(function() { result.close(); });
    }

    return result;
  }

  $.fn.center = function() {
    var top = ($(window).height() - this.height()) / 2+$(window).scrollTop();
    var left = ($(window).width() - this.width()) / 2+$(window).scrollLeft();
    if (top < 0 || $(window).height() < this.height()) { top = 0; }
    if (left < 0 || $(window).width() < this.width()) { left = 0; }
    
    this.css("top", "" + top + "px");
    this.css("left", "" + left + "px");
    
    return this;
  }
  
  $.fn.fillWindow = function() {
    this.css('width', '100%');
    this.css('height', $(document).height());
  }

  $.notice = function(element, width) {
    if (typeof(width) == 'undefined') { width = 400; }

    $('h1', element).addInnerDivs(3);
    $('.body', element).addInnerDivs(3);
    $('.footer', element).addInnerDivs(3);

    $('button', element).each(function() {
      $(this).html($(this).text());
      $(this).wrapInner('<span><span></span></span>');
    });

    return $.popup(element, 'notice');
  }

  $.fn.addInnerDivs = function(count) {
    for (var ix = 0; ix < count; ++ix) {
      this.wrapInner('<div class="inner-' + (count - ix) + '"></div>');
    }
    return this;
  }
  } catch(e) { alert(e); }
  
})(jQuery);

/**
 * jquery.swfobject.1-0-7.js
 */
(function(E,B){var C=function(G){var F,H=[];for(F in G){H.push(F+'="'+G[F]+'"')}return H.join("")},D=function(H){var F,J,I=[],G;for(F in H){if(typeof H[F]=="object"){G=[];for(J in H[F]){G.push([J,"=",encodeURIComponent(H[F][J])].join(""))}H[F]=G.join("&amp;")}I.push(['<param name="',F,'" value="',H[F],'" />'].join(""))}return I.join("")},A=false;E[B]=(function(){var F="0,0,0",G=navigator.plugins["Shockwave Flash"]||ActiveXObject;F=G.description||(function(){try{return(new G("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(H){}}());F=F.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);return{available:F[1]>0,activeX:!G.name,version:{major:F[1]*1,minor:F[2]*1,release:F[3]*1},hasVersion:function(I){var L=this.version,J="major",K="minor",H="release";I=(/string|number/.test(typeof I))?I.toString().split("."):I||[0,0,0];I=[I[J]||I[0]||L[J],I[K]||I[1]||L[K],I[H]||I[2]||L[H]];return(I[0]<L[J])||(I[0]==L[J]&&I[1]<L[K])||(I[0]==L[J]&&I[1]==L[K]&&I[2]<=L[H])},expressInstall:"expressInstall.swf",create:function(H){if(!E[B].available||A||!typeof H=="object"||!H.swf){return false}if(H.hasVersion&&!E[B].hasVersion(H.hasVersion)){H={swf:H.expressInstall||E[B].expressInstall,attrs:{id:"SWFObjectExprInst",height:Math.max(H.height||137),width:Math.max(H.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(E[B].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};A=true}else{H=E.extend(true,{attrs:{height:H.height||180,width:H.width||320},params:{wmode:H.wmode||"opaque",flashvars:H.flashvars}},H)}return"<object "+(C(H.attrs))+(E[B].activeX?' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+H.swf+'" />':' type="application/x-shockwave-flash" data="'+H.swf+'">')+(D(H.params))+"</object>"}}}());E.fn[B]=function(F){if(typeof F=="object"){this.each(function(){var G=document.createElement(B);G.innerHTML=E[B].create(F);if(G.childNodes[0]){this.appendChild(G.childNodes[0])}})}else{if(typeof F=="function"){this.find("object").andSelf().filter("object").each(function(){var H=this,G="jsInteractionTimeoutMs";H[G]=H[G]||0;if(H[G]<660){if(H.clientWidth||H.clientHeight){F.call(this)}else{setTimeout(function(){E(H)[B](F)},H[G]+66)}}})}}return this}}(jQuery,"flash"));

