jQuery(document).ready(function($){
    
    if ($('body').attr('id') === 'home') {
        flashembed('paradia-logo', {src: './images/logo.swf', wmode: 'transparent'}, {url: './'});
    } else {
        flashembed('paradia-logo', {src: '../images/logo.swf', wmode: 'transparent'}, {url: '../'});
    }
    
    // !メニューバー
    colorStack = ['#65AADD', '#F39800', '#727171', '#65AADD', '#F18D00', '#C4D700', '#65AADD'];

    $('ul.submenu').css({display:'none'});
    
    var li = $('#menu ul li').not($('#menu ul.submenu li'));
    li.each(function(i, el){
    
    	if ($(el).hasClass('active')) {
            var self = $(this);
            var a = $('a:first', self);

            $.data(self.get(0), 'eng', a.text());
            
            a.text(a.attr('title'));
            $(this).css('backgroundColor', colorStack[i]);
    	}
    	
    	if ($(el).find('ul.submenu li.active').length) {
            var self = $(el);
            var a = $('a:first', self);

            $.data(self.get(0), 'eng', a.text());
            
            a.text($(el).find('ul.submenu li.active a').attr('title'));
            $(this).css('backgroundColor', colorStack[i]);
    	}
    
        $(el).hover(
            // mouseover
            function(){
            	if (!$(el).hasClass('active')) {
	                var self = $(this);
	                var a = $('a:first', self);
	                
	                $.data(self.get(0), 'eng', a.text());
	                
	                a.text(a.attr('title'));
	                $(this).css('backgroundColor', colorStack[i]);
                }
                
                $(this).find('ul.submenu')
                	.css({position: 'absolute', top: 20 + $(this).position().top, left: $(this).position().left, zIndex: 777})
                    .slideDown('fast').show();	
                	
            },
            //mouseout
            function(){
            	if (!$(el).hasClass('active')) {
        	        var self = $(this);
    	            var a = $('a:first', self);
                
	                a.text($.data(self.get(0), 'eng'));
                	$(this).css('backgroundColor', '#9FA0A0');
                }
                
                $(this).find('ul.submenu').slideUp('slow');
            }
        );
    });
    
    // !ボックスコンテンツの表示
    $('li[rel], img[rel], a[rel], div[rel]').overlay({
        top: '15%',
        oneInstance: false, 
        effect: 'apple',
        fixed: false,
        mask: {
		  color: '#FFF',
		  loadSpeed: 200,
		  opacity: 0.7
	   },
	   api: true,
	   onBeforeLoad:  function() {
          this.getOverlay().appendTo('body');
          
          var el = this.getOverlay();
	      var id = el.attr('id');
	      
	      switch(id) {
	           case 'chance-03':
	               $('#chance-03 img').replaceWith('<div id="chance-03-swf" style="width:800px;height:600px;"></div>');
	               $('#chance-03-swf').flashembed({src:'../common/swf/airflow.swf', width: 800, height:600});
	               break;
	           case 'tech-02':
	               $('#tech-02').css({width:480});
	               $('#tech-02 img').replaceWith('<div id="tech-02-swf" style="width:480px;height:360px;"></div>')
	               $('#tech-02-swf').flashembed({src:'../common/swf/compact.swf', width: 480, height:360});
	               break;
	           case 'tech-04':
	               $('#tech-04').css({width:800});
	               $('#tech-04 img').replaceWith('<div id="tech-04-swf" style="width:800px;height:400px;"></div>')
	               $('#tech-04-swf').flashembed({src:'../common/swf/rooftype-floortype.swf', width: 800, height:400});
	               break;
	           case 'tech-05':
	               $('#tech-05').css({width:480});
	               $('#tech-05 img').replaceWith('<div id="tech-05-swf" style="width:480px;height:360px;"></div>')
	               $('#tech-05-swf').flashembed({src:'../common/swf/airmix.swf', width: 480, height:360});
	               break;
	           case 'tech-09':
	               $('#tech-09').css({width:800});
	               $('#tech-09 img').replaceWith('<div id="tech-09-swf" style="width:800px;height:400px;"></div>')
	               $('#tech-09-swf').flashembed({src:'../common/swf/zone-controll.swf', width: 800, height:400});
	               break;
	      }
	      
       },
	   //onLoad: function() {
	   //    // ムービーを再生
	   //    var el = this.getOverlay();
	   //    var id = $(el).attr('id');
	   //    
	   //    if (id == 'chance-04' || id == 'stylish-01') {
	   //        //$f(0).play();
	   //    }
	   //},
	   onClose: function() {
	       // ムービーを停止
	      var el = this.getOverlay();
	      var id = el.attr('id');
	      
	      switch(id) {
	           case 'chance-04':
	           case 'stylish-01':
	               $f(0).stop();
	               break;
	      }

	   }
    });
    
    // !タブ
/*
$('#tech-04 ul').tabs('#tech-04 div.tabs', {
        effect: 'fade',
        fadeOutSpeed: 0,
        fadeInSpeed: 400
    });
*/
    
    // !ツールチップの表示
    if ($('img.hover').length) {
        $('img.hover').each(function(i, el){
            
            // スタイリッシュのページ
            if ($('body#plife-stylish').length) {
                
                if (i%2) {　// 奇数列
                    var o = [40, 210];
                    if ($.browser.msie) {
                        switch ($.browser.version) {
                            case '6.0':
                                var o = [40, 310];
                                break;
                            case '7.0':
                                var o = [40, 210];
                                break;
                            
                            case '8.0':
                                var o = [40, 120];
                                break;
                            default:
                        }
                    }
                    
                } else { // 0含む偶数列
                    var o = [40, 40];
                    if ($.browser.msie) {
                        switch ($.browser.version) {
                           case '6.0':
                                var o = [40, 140];
                                break;
                           case '7.0':
                                var o = [40, 40];
                                break;
                           
                           case '8.0':
                                var o = [40, -40];
                                break;
                            default:
                        }
                    }
                }
                
            } else {
                var o = [-80, 80];
                if ($.browser.msie) {
                    switch ($.browser.version) {
                        case '6.0':
                            var o = [-80, 120];
                            break;
                        case '7.0':
                            var o = [-80, 40];
                            break;
                        
                        case '8.0':
                            var o = [-80, -40];
                            break;
                        default:
                    }
                }
            }
            
            $(el).tooltip({
                tip: '#' + $('body').attr('id') + '-' + (i + 1),
                position: 'top left',
                //offset: [-80, 80],
                offset: o,
                effect: 'slide'
            });
        });
    }
    
});

