
var headerUri = "http://www.bsfuji.tv/top/js/R_index.html";
var footerUri = "http://www.bsfuji.tv/top/js/R_footer.html";

/*
var headRnd = Math.floor(Math.random()*2);
*/

$(document).ready(function(){
	$("#header-bodyContent").load(headerUri + " #header-bodyContent div[id=headWrap]",null);
	$("#footerInner").load(footerUri + " #footer-container div[id=footer-content]");
	
	var thisID0;
	var thisID1;
	for(var i = 0; i < 5; i++){
		thisID0 = "#" + i + "Btn";
		thisID1 = i + "Btn";
		$(thisID0).load(headerUri + " #submenuData div[id=" + thisID1 + "] a");
	}
	
	var pageTitle = encodeURI(document.title);
	var pageURL = encodeURI(document.URL);
	var twitterURL = "http://twitter.com/home?status= " + pageTitle + " " + pageURL + " %23bsfuji ";
	
	$("#rightContentBox0").append('<ul class="snsBoxUl"><li style="margin:0px 5px -10px 0px;"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-related="Ume_bsfuji:BSフジオフィシャルアカウント" data-lang="ja">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></li><li style="margin:0px 0px -10px 0px;"><a href="http://mixi.jp/share.pl" class="mixi-check-button" data-key="fe1e67179732e0fbba7c1e62502263f9cbb13243">mixiチェック</a><script type="text/javascript" src="http://static.mixi.jp/js/share.js"></script></li><br class="fclear" /><li style="margin:0px 5px -10px 0px;"><a name="fb_share" type="button" href="http://www.facebook.com/sharer.php?u=' + pageURL + '&amp;t=' + pageTitle + '">シェアする</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></li><br class="fclear" /></ul>');

	
	var imgTagCredit = $(".imgThumb p");
	$(".imgThumb p").html(function(i, html){
							   if(html.match("\n")) {
								   html = html.split("\n").join("<br>");
								   if(html.match("\r")) html = html.split("\r").join(" ");
								   return html;
							   }
							   else if(html.match("\r")) {
								   html = html.split("\r").join("<br>");
								   return html;
							   }
							   else if(html.match("&#10;")) {
								   html = html.split("&#10;").join("<br>");
								   if(html.match("&#13;")) html = html.split("&#13;").join(" ");
								   return html;
							   }
							   else if(html.match("&#13;")) {
								   html = html.split("&#13;").join("<br>");
								   return html;
							   }
							   else return html = html;
	});
	
	
	textAreaBoxHeight = $(".credit textarea");
	ua = navigator.userAgent;
	if(ua.indexOf('MSIE')!=-1) {
		/**
		* Actual function that does all the work. Returns an array with all the info.
		* My Assumption is that most of the browsers will have arial set as their default sans-serif font.
		*/
		var Detector = function(){
			var h = document.getElementsByTagName("BODY")[0];
			var d = document.createElement("DIV");
			var s = document.createElement("SPAN");
			d.appendChild(s);
			d.style.fontFamily = "serif";		//font for the parent element DIV.
			s.style.fontFamily = "serif";		//have to use serif coz in FF3.0, it doesn't fall back to font of parent element.
			s.style.fontSize   = "72px";			//we test using 72px font size, we may use any size. I guess larger the better.
			s.innerHTML        = "mmmmmmmmmml";		//we use m or w because these two characters take up the maximum width. And we use a L so that the same matching fonts can get separated
			h.appendChild(d);
			var defaultWidth   = s.offsetWidth;		//now we have the defaultWidth
			var defaultHeight  = s.offsetHeight;	//and the defaultHeight, we compare other fonts with these.
			h.removeChild(d);
			/* test
			 * params:
			 * font - name of the font you wish to detect
			 * return:
			 * f[0] - Input font name.
			 * f[1] - Computed width.
			 * f[2] - Computed height.
			 * f[3] - Detected? (true/false).
			 */
			 function debug(font) {
				 h.appendChild(d);
				 var f = [];
				 f[0] = s.style.fontFamily = font;       // Name of the font
				 f[1] = s.offsetWidth;                           // Width
				 f[2] = s.offsetHeight;                          // Height
				 h.removeChild(d);
				 font = font.toLowerCase();
				 if (font == "serif") {
					 f[3] = true;    // to set arial and sans-serif true
				 } else {
					 f[3] = (f[1] != defaultWidth || f[2] != defaultHeight); // Detected?
				}
				return f;
			}
			function test(font){
				f = debug(font);
				return f[3];
			}
		this.detailedTest = debug;
		this.test = test;
		}
		var fonts = [];
		/**
		* other stuff
		*/
		
		var detective = new Detector();
	
		if(detective.test('Meiryo') == true){
		}
		else{
			textAreaBoxHeight.css("font-size", "12px");
			textAreaBoxHeight.css("line-height", "16px");
			textAreaBoxHeight.css("width", "300px");
		}
	}
	
});

/*
function headerChange(){
	var h$ = jQuery;
	if(headRnd < 1){
		h$("#header-bannerSet1").css("display", "none");
		h$("#header-bannerSet0").css("display", "block");
	}
	else{
		h$("#header-bannerSet0").css("display", "none");
		h$("#header-bannerSet1").css("display", "block");
	}
}
*/


