var successNum = 0;
var incNum = 2;

function loaderHtml(headerId,headerHtml,footerId,footerHtml,bMenuId,bMenuHtml,filepath) {
	filepath = filepath || "/shared/include";
	headerId = headerId || "header";
	headerHtml = headerHtml || "header.html";
	footerId = footerId || "footer";
	footerHtml = footerHtml || "footer.html";


	$("#" + headerId).load(filepath + "/" + headerHtml, null, CallBackHandler);
	$("#" + footerId).load(filepath + "/" + footerHtml, null, CallBackHandler);
}

function loadMenu(targetID){
	var path = "/shared/include/";
	var htmlName = targetID + ".html";
	$("#" + targetID).load(path + htmlName, null);
}

function CallBackHandler(responseText, status, XMLHttpRequest) {
	if (status == "success") {
		successNum++;
	}
	init();
}

function init() {
	
	if(successNum == incNum){
		$.fsize();
		$.preloadCssImages();
		$(document).pngFix();
		$("#gnavi ul li a img").mouseover(function(){
		$(this).attr("src",$(this).attr("src").replace(".png", "_over.png"));
		}).mouseout(function(){
		$(this).attr("src",$(this).attr("src").replace("_over.png", ".png"));
		});
		$("#gnavi ul li a span").mouseover(function(){
		$(this).attr("rel",$(this).attr("rel").replace(".png", "_over.png"));
		$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).attr("rel")+"',sizingMethod='crop')")
		}).mouseout(function(){
		$(this).attr("rel",$(this).attr("rel").replace("_over.png", ".png"));
		$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).attr("rel")+"',sizingMethod='crop')")
		});
		$("a[href$='.pdf']").addPdfIcon("after");
		$('a[href^="http"]').addlinkEX("after");
	}
	
}


$.fn.extend(
{
	addPdfIcon: function(param)
	{
		var pdfElem = $(this);
		if(param == "after")
		{
			pdfElem.not(".noIcon").after("<span class='linkPDF'>&nbsp;</span>");
		}
		else if (param == "before")
		{
			pdfElem.not(".noIcon").before("<span class='pdfBefore'>&nbsp;</span>");
		}
		pdfElem.click(function()
		{
			this.target = "_blank";
		});
	}
});


$.fn.extend(
{
	addlinkEX: function(param)
	{
		var notParam = '[href^="http://autorace.jp/"], [href^="http://info.autorace.jp/"], [href^="https://info.autorace.jp/"], [href^="http://www.totor.xux.jp/"], [href^="https://www.totor.xux.jp/"], [href^="http://autorace.futurebox.jp/"], a:has(img), #autoTwi a, #autotv a, #rightArea a, a.linkEX';
		var linkElem = $(this);
		if(param == "after")
		{
			linkElem.not(notParam).after("<span class='linkEX'>&nbsp;</span>");
		}
	}
});
