// JavaScript Document


	/* --------------------------------------------------------------------*/
	/*  this.javascript.made.by tsuyoshi higuchi	 __wpe__
	/*  Copyright 2009
	/* --------------------------------------------------------------------*/
	

	/* call functions from here    */
	$(document).ready(function(){		
		
		/* for all pages header search block */	
		var pageurl = location.href.split('/');
		if( pageurl[3] != 'search' ) headersearch();
		else
		{
			$('.extrahas').remove();
			$('#headersearchblk').remove();
			var isMSIE = /*@cc_on!@*/false; 
			if (isMSIE)
			{
				$('#mainheaderblk').css('margin-top','-10px');
				$('#others').css('padding-top','10px')
			}
		}
		/* for home right column search block */
		contentslist();
	});
	
	
	
	function headersearch()
	{
		var hsblk = $('#headersearchbox');
		var onbtn = $('#searchon p');
		var onbtnoffset = onbtn.offset();
		var searchboxoffset = hsblk.offset();
		var onlist = $('#h_selectcontentslist');
			
		if( hsblk.html() )
		{
			/* init */
			var isMSIE = /*@cc_on!@*/false; 
			if (isMSIE) postop = Number( onbtnoffset.top ) + Number( onbtn.height() ) - 4;
			else postop = Number( onbtnoffset.top ) + Number( onbtn.height() ) - 2;
			
			hsblk.css('top', postop+'px');
			h_index(onlist,0);
			hsblk.slideToggle();
			onbtn.click
			(
				function ()
				{
					hsblk.slideToggle();
				}
			);
			
			$("#h_searchkeyform").submit
			(
				function()
				{
					if( !$("#h_searchkey").attr("value") || $("#h_searchkey").attr("value") == " " || $("#h_searchkey").attr("value") == null )
					{
						alert( "検索キーを入力してください。" );
						return false;
					}
				}
			);
		}	
	}
	
	function h_index(o,s)
	{
		$("#h_selectcontentslist").empty()
		var listobj = new Object();
		var view = '';
		var select_element = document.getElementById("selectcontents_header");
		for ( var i = 0; i < select_element.options.length; i++ )
		{
			inde = select_element.options[i].value;
			sele = select_element.options[i].selected;
			listobj [ inde ] = select_element.options[i].text;
			if( s == inde ) vie = '<li id="h_sel_'+inde+'" class="select">'+listobj [ inde ]+'</li>';
			else vie = '<li id="h_sel_'+inde+'">'+listobj [ inde ]+'</li>';
			view += vie;
		}
		o.append("<ul></ul>");
		$( '#'+o.attr('id') +" > ul").html(view);
			
		$("#h_selectcontentslist > ul > li").click
		(
			function()
			{
				blg = $( this ).attr("id");
				bid = blg.split("_");
				$("#h_includeblog").attr("value",bid[2]);
				h_index($('#h_selectcontentslist'), bid[2]);
			}
		);
	}
		
		
	
	
	
	function contentslist()
	{
		var listobj = new Object();
		var view = '<li id="sel_a"></li>';
		if( $("#others").html() )
		{
			$("#contentblk").css("padding-top","170px");
			if (typeof document.body.style.maxHeight == "undefined")
			{
				$("#contentblk").css("padding-top","150px");
			}
		}
		
		if( $("#selectcontents").html() )
		{
			var select_element = document.getElementById("selectcontents");
			for ( var i = 0; i < select_element.options.length; i++ )
			{
				inde = select_element.options[i].value;
				listobj [ inde ] = select_element.options[i].text;
				vie = '<li id="sel_'+inde+'">'+listobj [ inde ]+'</li>';
				view += vie;
			}
			$("#selectcontentslist").append("<ul></ul>");
			$("#selectcontentslist > ul").html(view);
			$("#others .hidden").hide();
			$("#selectcontentslist > ul > li").hide();
			$("#selectcontentslist > ul > li:first").show();
			$("#selectcontentslist > ul > li#sel_a").html($("#selectcontentslist > ul > li:eq(1)").html());
			$("#selectcontentslist > ul > li").click
			(
				function()
				{
					blg = $( this ).attr("id");
					$("#selectcontentslist > ul > li#sel_a").html($("#selectcontentslist > ul > li#"+blg).html());
					
					bid = blg.split("_");
					$("#includeblog").attr("value",bid[1]);
					//alert($("#includeblog").attr("value"));
					$("#selectcontentslist > ul > li").hide();
					$("#selectcontentslist > ul > li:first").show();
				}
			);
			
			$("#selectcontentslist > ul > li").mouseover
			(
				function ()
				{
					$(this).css("backgroundColor","#00abe3");
					$(this).css("color","#fff");
				}
			);
			$("#selectcontentslist > ul > li").mouseout
			(
				function ()
				{
					$(this).css("backgroundColor","#fff");
					$(this).css("color","#666");
				}
			);
			
			$("#selectcontentslist > ul").hover
			(
				function ()
				{
					$("#selectcontentslist > ul > li").show();
					$("#selectcontentslist > ul > li:first").hide();
				},
				function ()
				{
					$("#selectcontentslist > ul > li").hide();
					$("#selectcontentslist > ul > li:first").show();
				}
			);
			
			$("#searchkeyform").submit
			(
				function()
				{
					if( !$("#searchkey").attr("value") || $("#searchkey").attr("value") == " " || $("#searchkey").attr("value") == null )
					{
						alert( "検索キーを入力してください。" );
						return false;
					}
				}
			);
		}		
	}
	
