/*
 * rollover.js via jQuery
 * $Date: 2008-10-22 $
 * $Rev: 1 $
 * ドキュメントが準備完了状態になったら、ページ内のimgタグを走査し、
 * マウスオーバーのアクションを追加し、ロールオーバーイメージをロードさせる。
 */
jQuery.noConflict();
(function($) {

/*--------------------------------------------------------------------------*
 *  
 *  stylife ヘッダーメニューに使用するJS
 *  
 *  2009 Arcphilia 
 *  http://www.arcphilia.co.jp/
 *  
 *--------------------------------------------------------------------------*/

$(function(){

    $('.layerbg')
        .fadeTo(1,0.0)
        .hide();
        
    $('.layerMenu')
        .fadeTo(1,0.0)
        .hide();

    var lastClicked,
        $body = $('body');

    $.fn.extend({
        close : function(name){
            return this.each(function(i){
            
                $('iframe[class^="layerIframe_"]').hide();
            
                $(this)
                    .removeClass('CurrentMenu')
                    .fadeTo(150,0.0,function(){ $(this).hide() })
                    .prev('.layerbg')
                    .fadeTo(150, 0.0, function(){ $(this).hide() });
                
                
                
            });
        },
        open : function(name){
            return this.each(function(i){

            if(typeof document.body.style.maxHeight == "undefined"){
                $('iframe[class^="layerIframe_"]').hide();
                $('iframe.layerIframe_' + name).show();
            }
                
                $(this)
                    .addClass('CurrentMenu')
                    .show()
                    .fadeTo(300,1.0)
                    .prev('.layerbg')
                    .show()
                    .fadeTo(300,0.7)
            });
        }
    });

    var currentMenu,currentName,lastMenu,lastName;

	//boutiqueHeaderをマウスオーバー/アウトした際のレイヤーメニュー
	$('#BoutiqueLinkHeader')
	    .children('li')
		.click(
		    function(e){
		        currentName = $(this).attr('id');
		        currentMenu = '#layerMenu_' + currentName;
		        
		        if($(e.target).is('.CloseMenu'))
		        {
		            $(currentMenu).close(currentName);
		        }
		        else{
    		        if(currentMenu != lastMenu){
    		            
    		            if(lastMenu != undefined && lastName != undefined){
    		                $(lastMenu).close(lastName);
    		            }
    		            $(currentMenu).open(currentName);
    		        }
    		        else
    		        {
    		            if($(currentMenu).is('.CurrentMenu')){
    		                //$(currentMenu).close();
    		            }
    		            else
    		            {
    		                $(currentMenu).open(currentName);
    		            }
    		        }
		        }
		        lastMenu = currentMenu;
		        lastName = currentName
		    }
		)
		.bind('mouseleave', function(e){
		    $(this).children('.layerMenu').close($(this).attr('id'));
		});
		
		//$('#BoutiqueLinkHeader').mouseout(console.log);
});
$(document).ready(function() {
	function rolloverImg(selector, suffix) {
		// 指定のファイル名を全て走査する
try{
		$(selector).each(function(i) {
			var default_img;
			$(this).hover (
				function() { 
					// 元画像のファイル名を取得
					default_img = $(this).attr('src');
					// ロールオーバ画像のファイル名を確定
					var point = default_img.lastIndexOf('.');
					var rollover_img = default_img.slice(0, point) + suffix + default_img.slice(point);
					// ロールオーバ画像のプリロード
					var preload_img = new Image();
					preload_img.src = rollover_img;
					// ロールオーバの設定
					$(this).attr('src', rollover_img); 
				},
				function() { $(this).attr('src', default_img); 	}
			)
		})
}
catch(e){
//何もしない
}
	}

	function borderChange(selector,color){
try{
		$(selector).hover(function(){
			$(this).css('border-color',color);
		},function(){
			$(this).css('border-color','#cccccc');
		})
}catch(e){
//何もしない
}

	}

	// ファイル名に[swap]のクラスを持つ画像タグ全てに、元画像のファイル名+[_o]のロールオーバアクションを付与させる
	rolloverImg('.swap', '_o');

	borderChange('.productList .item','#00aef2');
	borderChange('.productList .newarrival','#ff005b');
});
})(jQuery);
