// Pink Ver. for vol.3

var dir_img = 'images/';
var dir_ymenu = dir_img + 'ymenu/';
var dir_hmenu = dir_img + 'hmenu/';

// 右肩の英文タイトルのタグ
var shoulderImage = '<img src="images/common/englishTitle.gif" width="17" height="362" alt="Yebisu International Festival for Art & Alternative Visions" />';

// 恵比寿映像祭メニューのタグを取得
function ymenu()
{
	var code="";
	
	code += '<a href="/">';
	code += '<img id="ymenu_logo" src="'+dir_ymenu+'ymenu_0.png" style="margin:9px 0px 0px 7px;" width="87" height="140" alt="恵比寿映像祭" /></a>';
	code += '<br style="clear:left;" />';
	code += '<div class="ymenu_main">';
	code += '    <img class="ymenu_btn_main" id="ymenu_info" src="'+dir_ymenu+'ymenu_1.png" width="86" height="53" alt="総合案内/INFORMATION" />';
    code += '    <img class="ymenu_btn_main" id="ymenu_arch" src="'+dir_ymenu+'ymenu_3.png" width="86" height="53" alt="アーカイブ/ARCHIVES" />';
    code += '    <img class="ymenu_btn_main" id="ymenu_foru" src="'+dir_ymenu+'ymenu_5.png" width="86" height="53" alt="フォーラム/FORUM" />';
    code += '    <img class="ymenu_btn_main" id="ymenu_blog" src="'+dir_ymenu+'ymenu_7.png" width="86" height="53" alt="ブログ/BLOG" />';
    code += '</div>';
    code += '<div class="ymenu_markerBox">';
    code += '    <img class="ymenu_marker" src="'+dir_ymenu+'arrow.png" width="3" height="5" style="margin-top:24px;" />';
    code += '    <img class="ymenu_marker" src="'+dir_ymenu+'arrow.png" width="3" height="5" />';
    code += '    <img class="ymenu_marker" src="'+dir_ymenu+'arrow.png" width="3" height="5" />';
    code += '    <img class="ymenu_marker" src="'+dir_ymenu+'arrow.png" width="3" height="5" />';
    code += '</div>';
    code += '<br style="clear:left;" />';
    code += '<div class="ymenu_sub">';
    code += '    <img id="ymenu_link" src="'+dir_ymenu+'ymenu_9.png" width="86" height="30" alt="関連団体リンク/LINKS" />';
    code += '    <img id="ymenu_pres" src="'+dir_ymenu+'ymenu_10.png" width="86" height="30" alt="プレスリリース/PRESS RELEASE" />';           
    code += '</div>';
    code += '<div class="ymenu_main">';
    code += '    <img class="ymenu_btn_main" id="ymenu_upda" src="'+dir_ymenu+'ymenu_12.png" width="86" height="53" alt="更新情報/UPDATES" />';
    code += '</div>';
    code += '<div class="ymenu_markerBox">';
    code += '    <img class="ymenu_marker" src="'+dir_ymenu+'arrow.png" width="3" height="5" style="margin-top:24px;" />';
    code += '</div>';
	//code += '</div>';
	
	return code;
}

// 会期中メニューのタグを取得
function hmenu()
{
	var code="";
	
	//code += '<div class="hmenu">';
    code += '<div class="hmenu_ontime">';
    code += '    <img style="float:left; margin:7px 10px 0px 15px;" src="'+ dir_hmenu + 'omenu_5.png" width="103" height="21" alt="2012.2.10fri-2.26sun" />';
    code += '    <img class="hmenu_btn_ontime" id="omenu_contents" src="'+ dir_hmenu + 'omenu_0.png" width="121" height="38" alt="第4回 開催情報/CONTENTS" style="border-left:1px solid #333333;" />';
    code += '    <img class="hmenu_btn_ontime" id="omenu_artists" src="'+ dir_hmenu + 'omenu_1.png" width="119" height="38" alt="出品アーティスト/ARTISTS" />';
    code += '    <img class="hmenu_btn_ontime" id="omenu_bySection" src="'+ dir_hmenu + 'omenu_2.png" width="101" height="38" alt="セクション別/SORT BY SECTION" />';
    code += '    <img class="hmenu_btn_ontime" id="omenu_byDate" src="'+ dir_hmenu + 'omenu_3.png" width="90" height="38" align="日程別" />';
    code += '</div>';
    code += '<div class="hmenu_syabi"><div>';
    code += '    <img class="btn_syabi" id="smenu_access" src="'+ dir_hmenu + 'smenu_2.png" width="29" height="10" style="margin-top:10px; margin-left:5px; float:left;" alt="ACCESS" />';
    code += '    <img class="btn_syabi" id="smenu_terms" src="'+ dir_hmenu + 'smenu_3.png" width="55" height="10" style="margin-top:10px; margin-left:8px; float:left;" alt="TERMS OF USE" />';
    code += '    <img class="btn_syabi" id="smenu_privacy" src="'+ dir_hmenu + 'smenu_4.png" width="62" height="10" style="margin-top:10px; margin-left:8px; float:left;" alt="PRIVACY POLICY" />';
    code += '    <img class="btn_syabi" id="smenu_syabi" src="'+ dir_hmenu + 'smenu_0.png" width="104" height="12" style="margin-top:9px; margin-left:10px; float:left;" alt="東京都写真美術館" /></div>';
    code += '    <img src="'+ dir_hmenu + 'smenu_1.png" width="283" height="15" id="copyright" alt="Copyright (C) 2011 Tokyo Metropolitan Museum of Photography All Rights Reserved." />';
    code += '</div>';
	//code += '</div>';
	
	return code;
}

// 会期中メニュー用のＸＭＬを取得
function load_hmenuXML( isupdate )
{
	var self = this;
	$.ajax(
	{
		type:"GET", url:"xml/hmenu.xml", contentType:"application/x-www-form-urlencoded", dataType:"xml",
		success:  function( xml )
		{
			var active, type, href, btn;
			// フェスティバルメニューの設定
			$(xml).find("ontimeMenus").each(function()
			{
				$(this).find("ontimeMenu").each( function()
				{
					var active = $(this).attr("active");
					var type = $(this).attr("type");
					var href = "./#/"+type;
					var btn = $("#omenu_" + type);
					if( active == "1" )
					{
						btn.css("cursor","pointer");
						if( isupdate )
						{
							// <a>タグの挿入（target指定のため）
							//btn.wrap('<a href="' + $(this).attr('href') + '" target="' + target + '"></a>');
							var href_update = $(this).attr("href");
							btn.click( function(){	 location.href = href_update } );
						}
						else
						{
							btn.click( function(){	 
							//self.readContent(type); // call by jq.history
							location.hash = type;
							});
						}
						btn.mouseover( function(){ onover( $(this) ); } );
						btn.mouseout( function(){ onout( $(this) ); } );
					}
					else
					{
						onover( btn );
					}
				});
			});
			
			// 写美メニューの設定
			$(xml).find("syabiMenus").each(function()
			{
				$(this).find("syabiMenu").each( function()
				{
					type = $(this).attr("type");
					href = $(this).attr("href");
					target= $(this).attr("target");
					btn = $("#smenu_" + type);
					btn.css("cursor","pointer");
					// <a>タグの挿入（target指定のため）
					btn.wrap('<a href="' + href + '" target="' + target + '"></a>');
					btn.mouseover( function(){ onover( $(this) ); } );
					btn.mouseout( function(){ onout( $(this) ); } );
				});
			});
			
			//続いて映像祭のＸＭＬを読み込む
			//self.load_ymenuXML();
		},
		error: function( XMLHttpRequest, textStatus, errorThrown )
		{
			//alert("error");
			//self.load_ymenuXML();
		}
	});	
}

// 恵比寿映像祭メニュー用のＸＭＬを取得
function load_ymenuXML( isupdate )
{
	$.ajax(
	{
		type: "GET",url: "xml/ymenu.xml",	contentType:"application/x-www-form-urlencoded",dataType: "xml",
		success:  function( xml )
		{
			// Yebizoメニューの設定
			$(xml).find("menus").each(function()
			{
				$(this).find("menu").each( function()
				{
					var menuType = $(this).attr("menuType");
					var href=  $(this).attr("href");
					var active = $(this).attr("active");
					var btn = $("#ymenu_" + menuType);
					if( active == "1" )
					{
						btn.css("cursor","pointer");
						btn.click( function(){	 location.href = href; } );
						btn.mouseover( function(){ onover( $(this) ); } );
						btn.mouseout( function(){ onout( $(this) ); } );
					}
					else
					{
						onover( btn );
					}
				});
			});
			//　ロゴのマウスアクションを設定
			$("#ymenu_logo").mouseover( function(){ onover( $(this) ); } );
			$("#ymenu_logo").mouseout( function(){ onout( $(this) ); } );
			
		},
		error: function( XMLHttpRequest, textStatus, errorThrown )
		{
			//alert("error");
		}
	});
}

// メニューを構築
function initMenus( isupdate )
{
	$(".ymenu").append( ymenu() );
	
	$(".hmenu").append( hmenu() );
	
	load_hmenuXML( isupdate );
	
	load_ymenuXML( isupdate );
}
