$(document).ready(function(){
	var menus = $('#MainPanel ul.Menu');
	var marquee = menus.find('span .marquee');
	var submenu = menus.find('ul.subMenu');

	var hmenu = $("#HeaderArea ul.Menu");
	var smenu = $("#LeftArea ul.Menu,#RightArea ul.Menu");
	
	// kami@20110905
	// for IE9。
	if(window.location.hash !== "")window.location.hash = window.location.hash;

	if(submenu) submenu.show();
	if(marquee.length){
		for(var i=0;i < marquee.length;i++){
			$div = $("<a>"+$(marquee[i]).html()+"</a>").hide();
			$div.css("font-weight", "bold");
			$("body").append($div);

			var menu_width = $(marquee[i]).parent().parent().outerWidth();
			var max = menu_width - (parseInt($(marquee[i]).parent().css('marginLeft').replace("px","")) + parseInt($(marquee[i]).parent().css('marginRight').replace("px","")));
			var mywidth = parseInt($div.outerWidth());

			if(mywidth <= max){
				var html = $(marquee[i]).html();
				$(marquee[i]).removeClass('marquee');
				$(marquee[i]).parent().html(html);
			}
			$div.remove();
		}
		
		//流れる文字
		menus.find('span .marquee').marquee('pointer').mouseover(function () {
			$(this).trigger('start');
		}).mouseout(function () {
			$(this).trigger('stop');
		});

		if(submenu){
			hmenu.find("li").hover(function(){
				$(this).children("ul").stop(true,true).animate({height:'show'},200,"swing");
			},function(){
			});

			hmenu.parent().hover(function(){
			},function(){
		        $($(this).find("li ul")).stop(true,true).animate({height:'hide'},200,"swing");
			});

			smenu.find("li").hover(function(){
				$(this).children("ul").stop(true,true).animate({height:'show'},200,"swing");
			},function(){
			});

			smenu.parent().hover(function(){
			},function(){
		        $($(this).find("li ul")).stop(true,true).animate({height:'hide'},200,"swing");
			});
		}
	}
	if(submenu) submenu.hide();

	var $head_li;
	$(hmenu).hover(function(){
		var $head_menu = $(this).parent();
		var $head_li = $(this).children();
		
		$head_li.bind('mousemove', function(e){
			var pos = $head_menu.offset();
			var $head_sub_menu = $(this).find("ul.subParentMenu");
		
			if($(window).height() < (pos.top + $head_sub_menu.outerHeight()) && ($(window).height()-100) < e.clientY){
				if(e.pageY < (pos.top + $head_sub_menu.outerHeight()-20)){
					window.scrollBy(0, 7);
				}
			}
		});
	},function(){
		var $head_li = $(this).find("ul.Menu").children();
		$head_li.unbind("mousemove");
	});
	
	var $side_menu;
	$(smenu).hover(function(){
		$side_menu = $(this).parent();
		$(this).bind('mousemove', function(e){
			var pos = $side_menu.offset();
			if($(window).height() < (pos.top + $side_menu.outerHeight()) && ($(window).height()-100) < e.clientY){
				if(e.pageY < (pos.top + $side_menu.outerHeight() - 100)){
					window.scrollBy(0, 7);
				}
			}
		});
	},function(){
		$(this).unbind("mousemove");
	});

	var $content_div = $('#ContentsArea div');
	var $content_a = $('#ContentsArea a');

	//レコードタイトルの角丸等
	if($("#title_corner_type").val()){
		var obj = $content_div.filter(function(index){return $(this).hasClass("record_title");});
		if(obj.length){
			obj.corner($("#title_corner_type").val());
		}
	}

	//拡大・詳細アイコン 速度によってズレる時があるのでload関数に移動
	$(window).bind
	(
		"load",
		
		function ()
		{
			var obj = $content_a.filter(function(index){return $(this).hasClass("iconScale");});
			if(obj.length){
				for(var i=0;i < obj.length;i++){
					var child = $(obj[i]).children()[0];
					$(child).css('position','relative');
					var pos = $(child).position();
					
					var elem = $("<a class='icon'>&nbsp;</a>");
					
					if(!jQuery.support.opacity)
					{
						$(elem).css('top',pos.top+($(child).height()-18));
						$(elem).css('left',pos.left+($(child).width()-18));
					} else {
						$(elem).css('top',pos.top+($(child).height()-22));
						$(elem).css('left',pos.left+($(child).width()-22));
					}
					
					$(obj[i]).append(elem);
				}
			}
		}
	);

	var obj = $content_a.filter(function(index){return $(this).hasClass("iconDetail");});
	if(obj.length){
		for(var i=0;i < obj.length;i++){
			var child = $(obj[i]).children()[0];
			$(child).css('position','relative');
			
			var pos = $(child).position();
			
			var elem = $("<a class='icon'>&nbsp;</a>");
			
			if(!jQuery.support.opacity)
			{
				$(elem).css('top',pos.top+($(child).height()-13));
				$(elem).css('left',pos.left+($(child).width()-13));
			} else {
				$(elem).css('top',pos.top+($(child).height()-17));
				$(elem).css('left',pos.left+($(child).width()-17));
			}

			$(obj[i]).append(elem);
		}
	}
	
	//画像保存禁止
	if(($("#img_preserve_flg").val() == "1" || $("#img_preserve_flg").val() == "2") && !$("#admin_flg").val()){
		if($("#img_preserve_flg").val() == "1"){
			$("body").bind("contextmenu",function(e){
				return false;
			});
		}else if($("#img_preserve_flg").val() == "2"){
			var obj = $("img");
			if(obj.length){
				for(var i=0;i < obj.length;i++){
					var pos = $(obj[i]).position();
					
					var elem = $("<a class='blank_icon'>&nbsp;</a>");
					$(elem).width($(obj[i]).width());
					$(elem).height($(obj[i]).height());
					$(elem).css('top',pos.top);
					$(elem).css('left',pos.left);
					$(elem).css('z-index',$(obj[i]).css('z-index')+1);
					
					$(obj[i]).parent().append(elem);
				}
			}
		}
	}

/*
	var obj = $('#ContentsArea div.block_icon_box div.block_icon_img');
	if(obj.length){
		for(var i=0;i < obj.length;i++){
			var parent = $(obj[i]).parent();
			
			var width  = parent.width();
			var height = parent.height();
			
			var pos_top  = Math.floor((height - $(obj[i]).height()) / 2);
			var pos_left = Math.floor((width  - $(obj[i]).width())  / 2) ;
			
			if(pos_top  < 0) pos_top  = 0;
			if(pos_left < 0) pos_left = 0;
			
			$(obj[i]).css('top',  pos_top  + 'px');
			$(obj[i]).css('left', pos_left + 'px');
		}
	}
*/


});

