// JavaScript Document

function get_clock() { 
	stance = 0;
	weekday=new Array("Sun","Mon","Tue","Wed","Thr","Fri","Sat") //現在の時刻の取得 
	get_time = new Date(); 
	get_time.setTime(get_time.getTime() + stance); 
	get_month = get_time.getMonth() + 1;
	switch(get_month) {
		case 1 : set_month = 'Jan'; break;
		case 2 : set_month = 'Feb'; break;
		case 3 : set_month = 'Mar'; break;
		case 4 : set_month = 'Apr'; break;
		case 5 : set_month = 'May'; break;
		case 6 : set_month = 'Jun'; break;
		case 7 : set_month = 'Jul'; break;
		case 8 : set_month = 'Aug'; break;
		case 9 : set_month = 'Sep'; break;
		case 10 : set_month = 'Oct'; break;
		case 11 : set_month = 'Nov'; break;
		case 12 : set_month = 'Dec'; break;
		default : 'Error';
	}
	get_milliseconds = get_time.getMilliseconds(); 
	get_milliseconds = "000" + get_milliseconds.toString(); 
	get_milliseconds = get_milliseconds.slice(-3); 
	time_text = "";
	time_text = time_text + set_month + "/"; 
	time_text = time_text + get_time.getDate() + "/"; 
	get_year = get_time.getFullYear();
	if(get_year > 2000) {
		set_year = get_year - 2000;	
	} else {
		set_year = get_year - 1900;	
	}
	time_text = time_text + set_year + ' ';
	time_text = time_text + "(" + weekday[get_time.getDay()] + ") "; 
	ampm = 'am';
	set_hours = get_time.getHours();
	if(set_hours > 12) {
		ampm = 'pm'
		set_hours = set_hours - 12;
	}
	if(set_hours < 10) {
		set_hours = '0' + set_hours;
	}
	time_text = time_text + set_hours + ":";
	set_minutes = get_time.getMinutes();
	if(set_minutes < 10) {
		set_minutes = '0' + set_minutes;
	}
	time_text = time_text + set_minutes + ':';
	set_seconds = get_time.getSeconds();
	if(set_seconds < 10) {
		set_seconds = '0' + set_seconds;
	}
	time_text = time_text + set_seconds;
	time_text = time_text + ampm;
	$('#header_right p').text(time_text);
	//return time_text;
	setTimeout("get_clock()", 10); // 10/1000秒に指定 
}
$(function() {
	//getClock = get_clock();
	//$('#header_right p').text(getClock);
	
	// Begin Earth
	$('body')
	.append($('<div>').attr('id', 'earth_round')
		.append($('<img>').attr('src', 'images/earth_round.gif'))
	);
	$('#earth_round')
	.css(
		{
			'position':'absolute',
			'top':'0',
			'left':'0',
			'width':'50px',
			'height':'50px',
			'z-index':'90'
		}
	);
	$('#earth_round img')
	.css(
		{
			'width':'50px',
			'height':'50px'
		}
	);
	$('#earth_round').hide();
	// End Earth
	
	// Begin Right Frame
	// function Right Frame
	function get_right_frame_ajax() {		
		$.ajax({
			type:"GET",
			url:"right_frame.php",
			cache:"false",
			complete: function(XHR) {
				//alert(XHR.responseText);
				//var axis = XHR.responseText.split(' ');
				$('#right_frame').html(XHR.responseText);
				$('#earth_round').hide();
			}
		});
	}
	function set_close_area() {
		$('#close_area')
		.css(
			{
				'width': $(window).width() - 200 + 'px',
				'height': $(document).height() + 'px'
			}
		).show();
	}
	function show_right_frame() {
		//alert('test');
		get_window_width = $(window).width();
		$('#earth_round').show();
		$('#earth_round')
		.css(
			{
				'position':'absolute',
				'top':'10px',
				'left': (get_window_width - 60) + 'px'
			}
		);
		$(this)
		.animate(
			{
				'width':'190px',
				'opacity':'1'
			},
			500
		);
		get_right_frame_ajax();
		set_close_area();
		$(this).unbind('mouseover');
	}
	// Set up Right Frame
	$('body').append($('<div>').attr('id', 'right_frame'));
	$('#frame_out').after($('#right_frame'));
	$('#right_frame')
	.css(
		{
			'position':'fixed',
			'top':'0',
			'right':'0px',
			'width':'20px',
			//'height': $(document).height() + 'px',
			'height':'100%',			
			'border':'solid 5px #052c7c',
			'background':'#fff',
			'z-index':'12',
			'opacity':'1'
		}
	);
	$('#right_frame')
	.animate(
		{
			'width':'0px',
			'opacity':'0.5'
		},
		1000
	);
	$('body').append($('<div>').attr('id', 'close_area'));
	$('#right_frame').after($('#close_area'));
	$('#close_area')
	.css(
		{
			
			'position':'absolute',
			'top':'0',
			'left':'0',
			'width': $(window).width() - 200 + 'px',
			'height': $(document).height() + 'px',
			'z-index': '11'
		}
	);
	$('#right_frame')
	.bind('mouseover', show_right_frame);
	$('#close_area')
	.bind('mouseover', function() {
		$('#right_frame')
		.animate(
			{
				'width':'0px',
				'opacity':'0.5'
			},
			500,
			function() {
				$('#right_frame')
				.bind('mouseover', show_right_frame);
			}
		);
		$(this).hide();
		$('#right_frame').html('');	 
	});
	// End Right Frame
	
	// Begin Down and up Arrow to move next or prev post messages.
	$('#next_post')
	.bind('click', function(event) {
		//alert('test');
		event.preventDefault();
		
		x = 0;
		$('#bbs_contents h3').each(function() {
			
			get_next = Math.floor($(this).parents('dl').offset().top - $('#header_out').height() - $('html').scrollTop());
			
			//alert(get_next);
			if(get_next > 0) {
				
				scroll_position = $(this).parents('dl').offset().top - $('#header_out').height();
				return false;
				
			}
		
		x++;
		
		});
		
		$('html')
		.animate(
			{
				'scrollTop':scroll_position
			}
			,200
		);
		
	});
	
	$('#prev_post')
	.bind('click', function(event) {
		
		event.preventDefault();
		
		x = 0;
		$('#bbs_contents h3').each(function() {
			
			get_next = Math.floor($(this).parents('dl').offset().top - $('#header_out').height() - $('html').scrollTop());
			//alert(get_next);
			if(get_next < 0) {
				
				scroll_position = $(this).parents('dl').offset().top - $('#header_out').height();
				//return false;
				
			}
			if(x == 0 && get_next == 0) {
				scroll_position = 0;	
			}
			
		x++;
		
		});
		
		$('html')
		.animate(
			{
				'scrollTop':scroll_position
			}
			,200
		);
		
	});
	// End Down and up Arrow to move next or prev post messages.
	
	// Begin Shape input filed
	
	$('#bbs_action input').css(
		{
			'margin-right':'5px',
			'border':'solid 3px #ccc',
			'width':'300px',
			'height':'31px',
			'font-size':'20px'
		}
	);
	
	// End Shape input filed
	
	// Begin seach action
	
	$('#bbs_action form a')
	.bind('click', function(event) {
		
		event.preventDefault();
		
		$(this).parents('form').submit();
		
	});	
	// End search action
	
	//Begin test code
	$('body').append($('<div id="show_tag">').append($('<button id="get_tag">get whole tag</button>')).append($('<div id="get_whole_tag">')));
	$('#show_tag')
	.css(
		{
			'position':'absolute',
			'top':'0',
			'left':'0',
			'z-index':'90'
		}
	);
	$('#get_tag').click(function(){
		alert($('#left_navi_out').height());
		$('div#get_whole_tag').text($('html').html());
		//alert($('body').html());
	});
	$('#get_tag').hide();
	//End test code
});