(function() {
    var baseurl = 'http://omron.web-ir.jp/',
    images = baseurl + 'images/en/';
    jQuery.extend(jQuery.easing,{
	def: 'easeInQuad',
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	}
    });
    function parseFontSize(src) {
	if (src == null) return 2;
        var size = src.replace(/^.*\/fontsize_/, '').replace(/.(gif|css)$/, '');
        switch (size.toLowerCase()) {
            case 'small': return 1;
            case 'large': return 3;
            default: return 2;
        }
    }
    function getScrollOffset() {
     	return {
	  	left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
            	top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        };
    }
    function getWindowDimentions() {
        var target = window, pre = 'inner';
        if (!window.innerWidth) {
            pre = 'client';
            target = document.documentElement || document.body;
        }
        return { width: target[pre + 'Width'], height: target[pre + 'Height'] };
    }
    function getFixedTopS() {
	var d = getWindowDimentions(),
	y = Math.round((d.height - config.sdialog.height) / 2), yy;
	if (d.height > config.sdialog.height*2) {
	    yy = y - config.sdialog.height/2;
	    if (yy > 80) return yy;
	}
	return y;
    }
    function getFixedTop() {
	return Math.round((getWindowDimentions().height - config.dialog.height) / 2);
    }
    var config = {
      position: { top:120 },
      banner: { width:192, height:83 },
      display:{ width:800 },
      sdialog:{ width:479, height:259, background:{ width:479, height:312 } },
      dialog: { width:750, height:491, frame: { width:722, height:407 } },
      close: { width:34 }
    };
    var ie6 = ($.browser.msie && $.browser.version < 7), img, self, dialog, usertype, fontsize, abs_s, abs;
    fontsize = parseFontSize($.cookie('style'));
    
    document.write('<img src="'+images+'banner.png" id="__aa_irmenu" />');
    document.write('<div id="__aa_irmenu_dialog"><div class="__aa_closebutton"></div><div class="__aa_links"><ul class="__aa_left"><li><span><em rel="1">First-time visitor</em></span></li><li><span><em rel="3">Individual investor</em></span></li><li><span><em rel="5">Institutional investor</em></span></li><li><span><em rel="6">Other</em></span></li></ul><ul><li><span><em rel="2">Shareholder</em></span></li><li><span><em rel="4">Analyst</em></span></li><li><span><em rel="7">Omron Group employee</em></span></li></ul></div></div>');
    document.write('<div id="__aa_irmenu_bg"></div>');
    document.write('<div id="__aa_irmenu_bg2"></div>');
    document.write('<div id="__aa_irmenu_dialog2"><div class="__aa_closebutton"></div><div></div></div>');
    var img = $('#__aa_irmenu_bg').css({position:(ie6)?'absolute':'fixed'})
      .css({zIndex:999,display:'none',background:'transparent url('+images+'/bg.png) no-repeat scroll top left'}).width(config.sdialog.background.width).height(config.sdialog.background.width);
    if (ie6) {
	img.css({background:'none'});
	img.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+images+"bg.png')");
    }
    self = $('#__aa_irmenu').width(config.banner.width).height(config.banner.height).css({cursor:'pointer',border:'1px solid #ccc'});
    dialog = $('#__aa_irmenu_dialog').css({zIndex:1000,display:'none', textAlign:'center'}).width(config.sdialog.width).height(config.sdialog.height); 
    $('#__aa_irmenu_bg2').hide();
    dialog.find('div').eq(0).width(config.close.width).height(config.close.width).css({float:'right', background:'transparent url('+images+'c.png) no-repeat scroll top left', margin:'-1px -1px 0 0', cursor:'pointer'}).click(function() {
	var dialog = $('#__aa_irmenu_dialog');
	if (dialog.is(':visible')) {
	    var bg = $('#__aa_irmenu_bg');
	    if (!abs_s) {
	    	bg.width(dialog.width()).height(dialog.height()).css({top:dialog.css('top'), left:dialog.css('left')}).show();
	    	dialog.hide();
	    	var soffset = getScrollOffset(),
	    	m = $('#__aa_irmenu'),
	    	offset = m.offset();
	    	bg.animate({top:offset.top+(m.height()/2)-soffset.top+'px', left:offset.left+(m.width()/2)-soffset.left+'px', width:0, height:0}, 200, 'easeOutQuad', function() { $(this).hide(); });
	    } else {
		dialog.hide();
		bg.hide();
	    }
	}
    });
    if (ie6) {
	var cb = dialog.find('div').eq(0);
	cb.css({background:'none'});
	cb.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+images+"c.png')");
    }
    dialog
      .find('div.__aa_links').css({margin:'58px 0 0 20px'}).height(190)
	.find('ul').css({float:'left'}).width(220)
      .find('li')
      .css({textAlign:'left',lineHeight:'42px',wordSpace:'nowrap'}).height(42)
      .find('span')
      .css({ padding:'0 0 0 12px',background:'transparent url('+images+'ar.gif) no-repeat scroll center left' })
      .find('em')
      .css({fontFamily:'"ƒqƒ‰ƒMƒmŠpƒS Pro W3", "Hiragino Kaku Gothic Pro", "Osaka", "MS PƒSƒVƒbƒN", "MS PGothic", Arial, tahoma, Helvetica, sans-serif',fontSize:'1.15384em',color:'#008cee',fontWeight:'bold',fontStyle:'normal',margin:'0 1px 0 1px',textDecoration:'underline',cursor:'pointer' })
      .click(function() {
	  $('#__aa_irmenu_bg').hide();
	  usertype = parseInt($(this).attr('rel'));
	  var dialog = $('#__aa_irmenu_dialog').hide(),
	  img = $('#__aa_irmenu_bg2')
	  .css({display:'none', position:(abs)?'absolute':'fixed', background:'transparent url('+images+'b2.png) no-repeat scroll top left', zIndex:1001 })
	  .width(dialog.width())
	    .height(dialog.height());
	  if (ie6) {
		img.css('background', 'none');
		img.css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+images+"b2.png')"});
	  }
	  var f = function() {
	      var dialog = $('#__aa_irmenu_dialog2'),
	      frame = dialog.find('iframe');
	      dialog.css({position:(abs)?'absolute':'fixed'});
	      /*if (!abs) dialog.css({left:0, top:getFixedTop()+'px'});
	      else {*/
		  var bg = $('#__aa_irmenu_bg2');
	      dialog.css({left:bg.css('left'), top:bg.css('top')});
	      //}
	      if (frame.length == 0) {
		  dialog.css({zIndex:1002, textAlign:'center', display:'block'}).width(config.dialog.width).height(config.dialog.height);
		  dialog.find('div').eq(0).width(config.close.width).height(config.close.width).css({float:'right', background:'transparent url('+images+'c.png) no-repeat scroll top left', margin:'7px -4px 0 0', cursor:'pointer'}).click(function() {
		    if (dialog.is(':visible')) {
	    		var bg = $('#__aa_irmenu_bg2');
			if (!abs) {
			    bg.width(dialog.width()).height(dialog.height()).css({top:dialog.css('top'), left:dialog.css('left')}).show();
			    dialog.hide();
			    var soffset = getScrollOffset(),
			    m = $('#__aa_irmenu'),
			    offset = m.offset();
			    bg.animate({top:offset.top+(m.height()/2)-soffset.top+'px', left:offset.left+(m.width()/2)-soffset.left+'px', width:0, height:0}, 200, 'easeOutQuad', function() { $(this).hide(); });
			} else {
			    dialog.hide();
			    bg.hide();
			}
		    }
    		  });
		  if (ie6) {
			var cb = dialog.find('div').eq(0);
			cb.css({background:'none'});
			cb.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+images+"c.png')");
    		  }
		  var ff = dialog.find('div').eq(1);
		  ff.css({margin:'64px auto 0 auto', overflow:'hidden'});
		  frame = $('<iframe src="about:blank" />');
		  frame.width(config.dialog.frame.width).height(config.dialog.frame.height).attr('frameBorder', 0).attr('scrolling', 'no').attr('noresize', 'noresize').css('border', '0 solid #fff').attr('src', 'about:blank').appendTo(ff);
	      }
	      frame.attr('src', baseurl + 'html/dialog_en.php?u='+usertype+'&f='+fontsize+ (($.browser.msie && $.browser.version < 8) ? '&ts=' + new Date().getTime() : ''));
	      if ($.browser.msie && $.browser.version < 8)
		dialog.height(420);
	      dialog.slideDown('fast', 'easeOutQuad', function() {});
	      //else dialog.show();
	  };

	  if (!abs) {
	      img.css({top: dialog.css('top'), left: Math.round((config.display.width-config.sdialog.width)/2)+'px', display:'block'}).animate({
		width:config.dialog.width+'px', height:config.dialog.height+'px', top:getFixedTop()+'px', left: Math.round((config.display.width-config.dialog.width)/2)+'px'}, 350, 'easeOutQuad', f);
	  } else {
	      var soffset = getScrollOffset();
	      img.width(config.dialog.width).height(config.dialog.height).css({top:Math.round(getScrollOffset().top + (getWindowDimentions().height - config.dialog.height)/2)+'px', left: Math.round((config.display.width-config.dialog.width)/2)+'px'}).show();
	      f();
	  }
      });
    dialog.find('ul.__aa_left').width(200).css('margin-left', ($.browser.msie && $.browser.version < 7) ? '7px' : '14px');
    self.click(function() {
	var offset = $(this).offset(),w = $(this).width(), h = $(this).height(),
	img = $('#__aa_irmenu_bg');
	if (img.is(':visible') || $('#__aa_irmenu_bg2').is(':visible')) return false;
	var dim = getWindowDimentions();
	abs_s = (ie6 || dim.height < config.sdialog.height);
    	abs = (ie6 || dim.height < config.dialog.height);
	img.css({position:(abs_s)?'absolute':'fixed'});
	dialog.css({position:(abs_s)?'absolute':'fixed'});
	var soffset = getScrollOffset();
	if (!abs_s) {
	    img.css({top:offset.top+(h/2)-soffset.top+'px',left:offset.left+(w/2)-soffset.left+'px'}).width(0).height(0)
	      .animate({
	    	width: config.sdialog.width+'px',
	    	height: config.sdialog.height+'px',
		top: getFixedTopS()+'px',
	    	left: Math.round((config.display.width-config.sdialog.width)/2)+'px'
	      }, 250, 'easeOutQuad', function() {
	    	var dialog = $('#__aa_irmenu_dialog'),
	    	offset = $(this).offset();
		offset.top = getFixedTopS();
		offset.left = Math.round((config.display.width-config.sdialog.width)/2);
	    	dialog.css({top:offset.top+'px',left:offset.left+'px',display:'block'}).slideDown(200, 'easeOutQuad');
	      });
	} else {
	    var s = getScrollOffset(),
	    t = Math.round(s.top + (getWindowDimentions().height - config.sdialog.height)/2)+'px',
	    l = Math.round(s.left + (config.display.width-config.sdialog.width)/2)+'px';
	    img.css({top:t, left:l})
	      .width(config.sdialog.width).height(config.sdialog.height).show();
	    dialog.css({top:t, left:l, display:'block'});
	}
    });
    $('ul.fontsize li a').click(function() {
	var dialog = $('#__aa_irmenu_dialog2');
	if (dialog.is(':visible')) {
	    dialog.find('div.__aa_closebutton').trigger('click');
	}
        fontsize = parseFontSize($(this).find('img').attr('src'));
    });
})()
$(document).ready(function() {
	$('#__aa_irmenu').parent().get(0).style.marginTop = '5px';
});