
var headerUri = "http://www.bsfuji.tv/top/js/index.html";
var footerUri = "http://www.bsfuji.tv/top/js/footer.html";

$(document).ready(function(){
	$("#menuContent").load(headerUri + " #header-container ul[id=header-content]",null,headerLoaded);
	$("#header-flash").load(headerUri + " #header-body div[id=header-bodyContent]");
	$("#footerInner").load(footerUri + " #footer-container div[id=footer-content]");
});

function headerLoaded(){
	var j$ = jQuery;
	var jArray = new Array();
	var closeArray = new Array();
	var btnArray = new Array();

	j$(function(){

		function setBackground() {
			var $last = j$("#header-content > li:last > a");
			if($last.hasClass("close"))
				$last.css("background-position", "left top");
			else
				$last.css("background-position", "left top");
		}

		j$("#header-content").each(function(){
			j$(".menuSection > ul", this).wrap("<div></div>");
			j$(".menuSection > div:not(:last)", this).prepend("<div class='topP'>&nbsp;</div>");
			j$(".menuSection > div:not(:last)", this).append("<div class='bottomP'>&nbsp;</div>");
			j$(".menuSection > div:last"      , this).prepend("<div class='topP'>&nbsp;</div>");
			j$(".menuSection > div:last"      , this).append("<div class='bottomP'>&nbsp;</div>");
		
			j$("li > a", this).each(function(index){
				var $this = j$(this);
			
				$this.addClass("close").next().hide();
				setBackground();

				var prms = {height:"toggle", opacity:"toggle"};
			
				var thisUri = this.toString();
				var thisURIFlag = thisUri.indexOf("htm", 0);
				if(thisURIFlag < 0){
					var closeStr = $this.attr("name");
					if(closeStr.length > 0){
						closeArray.push($this);
						var thisNumStr = $this.attr("href");
						var thisNum = thisNumStr.charAt(thisNumStr.length-1);
						closeArray[thisNum].click(function(){
							jArray[thisNum].click();
							return false;
						});
					}
					else{
						jArray.push($this);
					}
					
					$this.click(function(){
						j$(this).toggleClass("close").next().animate(prms, {duration:"fast"})
							.parent().siblings().children("div:visible").animate(prms, {duration:"fast"}).prev().addClass("close");
						setBackground();
						return false;
					});
				}
				else {
					$("a[href^=../]").click(function(){
						window.open(this.href, "_top");
					});
				}
				
			});
		});
			
		j$("#header-btnBox").each(function(){
			j$("li > a", this).each(function(index){			 
				var $btns = j$(this);
				btnArray.push($btns);
				$btns.click(function(){
					var thisNum = $btns.attr("name");
					jArray[thisNum].click();
					return false;
				});
			});
		});
	});
	
	$(window).load(function() {
		$("#rFrame0").contents().find("#news").bind("click", function() {
			$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
			   	'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;


		});			
	});
	
};
