﻿//************検索結果の強調表示************************

$(function(){
var url=decodeURI(document.referrer);
if(url.substring(0,50) == "http://aomi-sailing.com/msearch/msearch.cgi?query="){//リンク元のチェック

var words = []; 

　　//************検索語部分の切り出し
if(url.lastIndexOf("&num") == -1){
  query=url.substring(url.lastIndexOf("query=")+6, url.length);	
	}else{
	query=url.substring(url.lastIndexOf("query=")+6, url.lastIndexOf("&num"));
};

　　//***********複数検索語を一つずつに分離、配列に代入
   words=query.replace(/^\++|\++$|　|\(|\)/g, "+")  //前後の空白を除去(gオプションは繰り返し)
        .replace(/\++|　+/g, "+")    //連続する空白を1つに
        .split("+");              //空白で分割して配列にして代入


　　//************ページ頭作成
 
var pagehead = "";

      for (i in words) { 
        if (words[i] != "") {   
        pagehead= pagehead+"<span>"+words[i]+"&nbsp; &nbsp;</span>";
		}}; 
		
$("body").prepend(
"<div class='search-result'>以下の単語が、ページ内に強調表示されています。<br>"+pagehead+"<br></div>"

);



　　//************語句ハイライト
     for (i in words) {       
        if (words[i] != "") {      　　//空文字スキップ
        $("body").highlight(words[i]); //語句をハイライト
		};};		
		
		
$(".search-result").slideDown("normal");




};

});

　　//**********強調表示用、プラグイン
/*

highlight v3

Highlights arbitrary terms.

<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>

MIT license.

Johann Burkard
<http://johannburkard.de>
<mailto:jb@eaio.com>

*/

jQuery.fn.highlight = function(pat) {
 function innerHighlight(node, pat) {
  var skip = 0;
  if (node.nodeType == 3) {
   var pos = node.data.toUpperCase().indexOf(pat);
   if (pos >= 0) {
    var spannode = document.createElement('span');
    spannode.className = 'highlight';
    var middlebit = node.splitText(pos);
    var endbit = middlebit.splitText(pat.length);
    var middleclone = middlebit.cloneNode(true);
    spannode.appendChild(middleclone);
    middlebit.parentNode.replaceChild(spannode, middlebit);
    skip = 1;
   }
  }
  else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
   for (var i = 0; i < node.childNodes.length; ++i) {
    i += innerHighlight(node.childNodes[i], pat);
   }
  }
  return skip;
 }
 return this.each(function() {
  innerHighlight(this, pat.toUpperCase());
 });
};

jQuery.fn.removeHighlight = function() {
 return this.find("span.highlight").each(function() {
  this.parentNode.firstChild.nodeName;
  with (this.parentNode) {
   replaceChild(this.firstChild, this);
   normalize();
  }
 }).end();
};

//**********End of 検索結果の強調表示************************


//bluewater story main page smooth scroll
/*$(function(){

$("a.bws-board-button").click(function(){
	e=$(this).attr('href');	
 $('html, body').animate({scrollTop:$(e).offset().top}, 2000);
 return false;

})
})*/

//bws page map-appear
$(function(){
  $(".BlueWaterStory .map-appear a")
  .live("mouseover",function(){
	$(this).before("<img src=\""+$(this).attr("href")+"\" style='position:absolute;top:0px;left:0px'>");
	$(this).prev().hide(0).fadeIn(400)
  })
  
  .live("mouseout",function(){
		$(this).prev().fadeOut(700,function(){
		$(this).remove()
		})
  })
  
  .click(function(){
	  return false;
	  
  })


});


//ページに入ったあと、.html#xxx の指定場所までスクロール
/*$(function(){

	window.scroll(0,200);
})

*/
