$(function(){
					 
	//input text (disappear inside text)
  $('input.keywords').val($('input.keywords').attr('title'));
  $('input.keywords')
    .blur(function(){
      var $$=$(this);
      if($$.val()=='' || $$.val()==$$.attr('title')){
        $$.css('color', '#999')
          .val($$.attr('title'));
      }
    })
    .focus(function(){
      var $$=$(this);
      if($$.val()==$$.attr('title')){
        $(this).css('color', '#000')
               .val('');
      }
    })
    .parents('form:first').submit(function(){
      var $$=$('#text');
      if($$.val()==$$.attr('title')){
        $$.triggerHandler('focus');
      }
    }).end()
    .blur();
	
					 
					 
	/* タブ切り替え
	------------------------------------------------------------------------------*/
	Array.prototype.clone = function(){
		return Array.apply(null,this)
	}  
		   
	tabArrayAll = new Array();
	/* fundsTab
	------------*/
	tabArrayAll["fundsTab"] = ["funds_mr","funds_yr","funds_tc","funds_nab"];
	
	var cookieStockTab = $.inArray($.cookie("fundsTab"), tabArrayAll["fundsTab"]);
	if(cookieStockTab >= 0){
		clickTab(tabArrayAll["fundsTab"][cookieStockTab], "fundsTab");
	}
	$.each(tabArrayAll["fundsTab"], function(){
		var tab = this;
		$("#" + tab).click(function(){
			clickTab(tab, "fundsTab");
			$.cookie("fundsTab", tab);
		});
	});
	
	/* stockTab
	------------*/
	tabArrayAll["stockTab"] = ["stock_up","stock_down","stock_vol","stock_value"];
	
	var cookieStockTab = $.inArray($.cookie("stockTab"), tabArrayAll["stockTab"]);
	if(cookieStockTab >= 0){
		clickTab(tabArrayAll["stockTab"][cookieStockTab], "stockTab");
	}
	$.each(tabArrayAll["stockTab"], function(){
		var tab = this;
		$("#" + tab).click(function(){
			clickTab(tab, "stockTab");
			$.cookie("stockTab", tab);
		});
	});
	
});




/* 数字の埋め込みなど
------------------------------------------------------------------------------*/
function getAnalyst(){
	for(i = 0; i < 5; i++){
		document.write('<li><p class="date">'+ analyst[i]["date"] +'</p>');
		document.write('<div class="rgt"><p class="ttl"><a href="'+ analyst[i]["link"] +'">'+ analyst[i]["title"] + analyst[i]["cat"] +'</a></p>');
		if(i == 0){
			document.write('<p class="txt">'+ analyst[i]["outline"] +'...</p>');
		}
		document.write('</div></li>');
	};
}


function getReport(){
	for(i = 0; i < 5; i++){
		document.write('<li><p class="date">'+ report[i]["date"] +'</p>');
		document.write('<div class="rgt"><p class="ttl"><a href="'+ report[i]["link"] +'">'+ report[i]["title"] + report[i]["cat"] +'</a></p>');
		if(i == 0){
			document.write('<p class="txt">'+ report[i]["outline"] +'...</p>');
		}
		document.write('</div></li>');
	};
}


function getVideo(){
	$.each(video, function(i){
		$.each(["ttl", "date"], function(){
			$("#video_" + this + (i + 1)).html(video[i][this]);
		});
		$("#video_img" + (i + 1)).attr("src", video[i]["img"]);
		$("#video_link" + (i + 1)).attr("href", video[i]["link"]);
		$("#video_link" + (i + 1) + "_2").attr("href", video[i]["link"]);
	});
}

function getFunds_cat(){
	$('span#funds_cat_total').html(funds_cat["cat"]['total']);
	$.each(["j-stock", "j-bond", "j-hybrid", "g-stock", "g-bond", "g-hybrid", "particular"], function(){
		$('li#funds_cat_' + this+ ' span.number').html(funds_cat["cat"][this]);
		$('li#funds_cat_' + this+ ' a').attr('href',funds_cat["cat"][this + '-link']);
	});
}

function getFunds_star(){
	document.write('<ul class="ratings">');
	$.each(funds_star, function(i){
		document.write('<li>');
		if(i != 0){document.write('&nbsp;&nbsp;');}
		document.write('<a href="'+ funds_star[i]['category-link'] +'">'+ funds_star[i]['category'] +'</a>&nbsp;'+ funds_star[i]['number'] +'本</li>');							
	});
	document.write('</ul>');
}

function getFunds_description(){
	document.write(funds_description["description"]["kind"]);
}

function getFunds_ranking(category){
		switch(category){
			case "mr" :
				$.each(funds_ranking["mr"], function(i){
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td><a href="'+ this["link"]+ '">'+ this["mr-title"] +'</a></td>');//title
					document.write('<td class="vam">'+ this["mr-company"]+ '</td>');
					document.write('<td class="tar nowrap vam">'+ this["mr-value"]+ '</td>');
					document.write("</tr>");
				});
				break;
				
			case "yr":
				$.each(funds_ranking["yr"], function(i){
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td><a href="'+ this["link"]+ '">'+ this["yr-title"] +'</a></td>');//title
					document.write('<td class="vam">'+ this["yr-company"]+ '</td>');
					document.write('<td class="tar nowrap vam">'+ this["yr-value"]+ '</td>');
					document.write("</tr>");
				});
				break;
			
			case "tc":
				$.each(funds_ranking["tc"], function(i){
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td><a href="'+ this["link"]+ '">'+ this["tc-title"] +'</a></td>');//title
					document.write('<td class="vam">'+ this["tc-company"]+ '</td>');
					document.write('<td class="tar nowrap vam">'+ this["tc-value"]+ '</td>');
					document.write("</tr>");
				});
				break;
			
			case "nab":
				$.each(funds_ranking["nab"], function(i){
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td><a href="'+ this["link"]+ '">'+ this["nab-title"] +'</a></td>');//title
					document.write('<td class="vam">'+ this["nab-company"]+ '</td>');
					document.write('<td class="tar nowrap vam">'+ this["nab-value"]+ '</td>');
					document.write("</tr>");
				});
				break;

	}

}


function getStock_description(){
	document.write(stock_description["description"]["total"]);
}

function getStock_ranking_desc(category){
	switch(category){
			case "kind" :
				document.write(stock_ranking_desc["description"]["kind"]);
				break;
			
			case "market" :
				document.write(stock_ranking_desc["description"]["market"]);
				break;
	}
}

function getStock_ranking(category){
	var linkurl = 'http://www.morningstar.co.jp/new_stock/detail_01.asp?ric=';
		switch(category){
			case "up" :
				$.each(stock_ranking["up"], function(i){
					this["link"] = linkurl + this["up-code"];
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td class="tac"><a href="'+ this["link"]+ '" target="_blank">'+ this["up-code"] +'</a></td>');//code
					document.write('<td><a href="'+ this["link"]+ '" target="_blank">'+ this["up-title"] +'</a></td>');//title
					document.write('<td>'+ this["up-market"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["up-price"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["up-volume"] + '</td>');
					document.write('<td class="vam tar nowrap">'+ this["up-rate"] + '%</td>');
					document.write("</tr>");
				});
				break;
				
			case "down":
				$.each(stock_ranking["down"], function(i){
					this["link"] = linkurl + this["down-code"];
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td class="tac"><a href="'+ this["link"]+ '" target="_blank">'+ this["down-code"] +'</a></td>');//code
					document.write('<td><a href="'+ this["link"]+ '" target="_blank">'+ this["down-title"] +'</a></td>');//title
					document.write('<td>'+ this["down-market"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["down-price"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["down-volume"] + '</td>');
					document.write('<td class="vam tar nowrap">'+ this["down-rate"] + '%</td>');
					document.write("</tr>");
				});
				break;
			
			case "vol":
				$.each(stock_ranking["vol"], function(i){
					this["link"] = linkurl + this["vol-code"];
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td class="tac"><a href="'+ this["link"]+ '" target="_blank">'+ this["vol-code"] +'</a></td>');//code
					document.write('<td><a href="'+ this["link"]+ '" target="_blank">'+ this["vol-title"] +'</a></td>');//title
					document.write('<td>'+ this["vol-market"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["vol-price"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["vol-volume"] + '</td>');
					document.write("</tr>");
				});
				break;
			
			case "value":
				$.each(stock_ranking["value"], function(i){
					this["link"] = linkurl + this["value-code"];
					document.write("<tr>");
					document.write('<th class="tac">'+ (i + 1) +'</th>');//rank
					document.write('<td class="tac"><a href="'+ this["link"]+ '" target="_blank">'+ this["value-code"] +'</a></td>');//code
					document.write('<td><a href="'+ this["link"]+ '" target="_blank">'+ this["value-title"] +'</a></td>');//title
					document.write('<td>'+ this["value-market"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["value-closeprice"]+ '</td>');
					document.write('<td class="vam tar nowrap">'+ this["value-compare"] + '</td>');
					document.write('<td class="vam tar nowrap">'+ this["value-shares"] + '</td>');
					document.write("</tr>");
				});
				break;

	}

}

function getIndicator(){
	$.each(["date", "nikkei-price", "nikkei-ap", "topix-price", "topix-ap", "jasdaq-price", "jasdaq-ap", "tokyo-value"], function(){
		$("#indicator_" + this).html(indicator[this]);
	});
}

function getNews(){
	$("p#news_date").html(news["date"]);
	for(i = 0; i < news["article"].length; i++){
		document.write('<dt>'+news["article"][i]["time"]+'</dt>');
		document.write('<dd><a href="'+news["article"][i]["link"]+'">'+news["article"][i]["title"]+'</a></dd>');
	};
}

function getNewsfunds(){
	for(i = 0; i < newsfunds.length; i++){
		document.write('<dt>'+newsfunds[i]["date"]+'</dt>');
		document.write('<dd><a href="'+newsfunds[i]["link"]+'">'+newsfunds[i]["title"]+'</a></dd>');
	};
}

function getInfo(){
	if(info.length > 0){
		document.write("<dl>");
		$.each(info, function(i){
			document.write("<dt>"+ this.date +"</dt>");
			if(i == info.length - 1){
				document.write('<dd class="last"><a href="'+ this.link+ '"');
			}else{
				document.write("<dd><a href=\""+ this.link+ "\"");
			}
			if(this.winopen == 1){
				document.write(" target=\"_blank\"")
			}
			document.write(">"+ this.title +"</a></dd>");
		});
		document.write("</dl>");
	}

}

function getStrCuts(str){
	ns = str.substr(0, 5);	
	ns = ns.replace("月","/"); 
   	ns = ns.replace("日",""); 
	
return ns;
}

function getGlobalNews5(){
	for(i = 0; i < newsglobal.length; i++){
		document.write('<dt>'+getStrCuts(newsglobal[i]["datetime"])+'</dt>');
		document.write('<dd><a href="'+newsglobal[i]["RncNo"]+'">'+newsglobal[i]["HeadLine"]+'</a></dd>');
	};
}