var t;

function back_to_top()
{
    Effect.ScrollTo('top');
}

function scroll_to_edges()
{
    Effect.ScrollTo('more_edges');
}

function addPrompt(element, text, options) {
    options=Object.extend({promptClassName:'prompt',
	hoverClassName:'hover',activeClassName:'active'},options||{});
    element=$(element);

    var focus=function() {
	if(element.value==text){element.value='';
	}
	Element.removeClassName(element,options.promptClassName);
	Element.removeClassName(element,options.hoverClassName);
	Element.addClassName(element,options.activeClassName);
    };

    var blur=function() {
	if(element.value==''||element.value==text){element.value=text;
	    Element.addClassName(element,options.promptClassName);
	}
	Element.removeClassName(element,options.activeClassName);
    }
}

function resizeImg(img_id, s)
{
    var img = $(img_id);
    var h = img.height;
    var w = img.width;
    if (h>w || w==0) {
	img.height = s;
    } else {
	img.width  = s;
    }
    img.show();
}

function tgl_danup(t)
{
    var disp = $('danup_after_'+t).getStyle('display');
    if (disp == 'none') {
	$('danup_after_'+t).show();
	$('danup_link_text_'+t).hide();
	$('danup_close_text_'+t).show();
    } else {
	$('danup_after_'+t).hide();
	$('danup_link_text_'+t).show();
	$('danup_close_text_'+t).hide();
    }
}

function hide(id)
{
    $(id).hide();
}

// 名前チェック
function name_check()
{
    var urle_q = $('urle_q').innerHTML;    
    var url    = "/namecheck/rate/"+urle_q;
    var myAjax = new Ajax.Updater('name_check', url, {method: 'get'});    
}

function callKeyrel(node_id)
{
    var url = '/keyrel/index/'+node_id;
    var myAjax = new Ajax.Updater('keyrel', url, {method: 'get'});
}

//////// 検索

var search_example_text = '氏名・キーワードで人物を検索';

function ch_search_text()
{
  if ($('q').value == '' || $('q').value == search_example_text) {
    $('q').value = search_example_text;
    new Element.setStyle($('q'), {'color':'#999999'});    
  }
  else {
    new Element.setStyle($('q'), {'color':'black'});        
  }
}

function on_focus_search_box()
{
  if ($F('q') == search_example_text) {
    $('q').value = '';
    new Element.setStyle($('q'), {'color':'black'});            
  }
}

//////// 検索実行
function submitSearch() 
{
    if ($F('q') == '') {return false;}
    if ($F('q') == search_example_text) {return false;}
    var q = $F('q');
    var urle_q = encodeURI( encodeURIComponent(q));
    var url = '/q/'+urle_q;
    window.location.href = url;
    return false;
}

//////// Enterをキャンセルして検索実行
function enterSubmit(evt) 
{
    if (evt.keyCode == 13) {
	// 普通のsubmitはキャンセル
	if (evt.preventDefault) {
	    evt.preventDefault();
	} else {
	    evt.returnValue = false;
	}
        // 実行
	submitSearch();
    }
}

//////// v2を使った検索
function submitSearch_v2() 
{
    if ($F('q') == '') {return false;}
    if ($F('q') == search_example_text) {return false;}
    var q = $F('q');
    var urle_q = encodeURI( encodeURIComponent(q));
    var url = '/q_v2/'+urle_q;
    window.location.href = url;
    return false;
}

//////// Enterをキャンセルして検索実行
function enterSubmit_v2(evt) 
{
    if (evt.keyCode == 13) {
	// 普通のsubmitはキャンセル
	if (evt.preventDefault) {
	    evt.preventDefault();
	} else {
	    evt.returnValue = false;
	}
        // 実行
	submitSearch_v2();
    }
}

//////////////////////////////////////////////////////////////////////

function more_video()
{
    $('btn_more_video').hide();
    $('more_video').show();
}

function more_edge()
{
    $('btn_more_edge').hide();
    $('more_edge').show();
}

function more_news()
{
    $('btn_more_news').hide();
    $('more_news').show();
}

function load_rank_box()
{
    var url = "/rank/box/";
    var myAjax = new Ajax.Updater('rank', url, {method: 'get'});        
}

//////// ビデオ再生
function playVideo(yt_id, width, height, autoplay)
{
    $('video_box').innerHTML = '<object height="'+height+'" width="'+width+'"><param name="movie" value="http://www.youtube.com/v/'+yt_id+'&amp;hl=en&amp;fs=1&amp;autoplay=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/'+yt_id+'&amp;hl=en&amp;fs=1&amp;autoplay='+autoplay+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="'+height+'" width="'+width+'"></object>'
    $('video_box').show();
}

//////// タイトルプレビュー
function prevVideoTitle(title)
{
	// $('video_title').title = $('video_title').innerHTML;
	$('video_title').innerHTML = "<font color='green'>"+title+"</font>";
}

//////// ビデオ閉じる
function closeVideo()
{
	$('video_box').innerHTML = '';    
	$('video_box').hide();
}

/////////////////////// 共通関数 /////////////////////////////

//////// ブラウザチェック
function chkBrowser() 
{
    var apl = navigator.appName;
    var ver = navigator.appVersion;

    if(apl.indexOf("Microsoft") >= 0){
	return 'ie';
    }else if(apl.indexOf("Netscape") >= 0){
	return 'nn';
    }else{
	return apl;
    }
}

//////// SafariでAjax文字化け回避
function get_response_text ( req ) {
    var text = req.responseText;
    if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
	var esc = escape( text );
	if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
	        text = decodeURIComponent( esc );
	    }
    }
    return text;
}

//////// 隠す
function Hide(id)
{
    $(id).hide();
}

//////// 見せる
function Show(id)
{
    $(id).show();
}

//////// urlEncode
String.prototype.urlEncode = function() {
    return encodeURIComponent(this);
}

/////// シャッフル
function jumpRandom()
{
    var j = $F('j');
    var urle_j = j.urlEncode();
    var url = "/rand/tag/"+urle_j;
    window.location.href=url;
}

//////// オートプレイ切り替え
function tglAutoPlay()
{
    var check = $F('video_autoplay');
    var url = "/cookie/autoplay/"+check;
    var myAjax = new Ajax.Request(url,{method: 'get'}); 
}

function nega_link(id)
{
    Element.setStyle($(id), {'background':'blue', 'color':'white'});
}

function posi_link(id)
{
    Element.setStyle($(id), {'background':'', 'color':'blue'});
}

//////// ハイライト
function hlight(id, color)
{
  var item = $(id);
  new Element.setStyle(item, {'border':'1px '+color+' solid'});
}

//////// エッジ行のBGを元に戻す
function restore_edge_bg(id)
{
    var def_color = $(id).getAttribute('def_color');
    hlight_bg(id, def_color);
}

//////// ハイライト
function hlight_bg(id, color)
{
  var item = $(id);
  new Element.setStyle(item, {'backgroundColor':color});
}

//////// はてな顔画像に変更
function changeHatena(id)
{
  $(id).src = '/_img/hatena.jpg';
}

//////// ranking
function disp_rank_div(page)
{
    var btns = document.getElementById('btns_rank_div');
    var objs_a = btns.getElementsByClassName('btn_link');    
    for (var n=0; n<objs_a.length; n++ ) {    
        new Element.setStyle( $(objs_a[n].id), {'backgroundColor':'#FFFFFF'});        
        $('rank_div_'+(n+1)).hide();
    }
    new Element.setStyle( $('btn_rank_div_'+page), {'backgroundColor':'#DDDDDD'});
    $('rank_div_'+page).appear();    
}
