//Global, is Accessible Site Set?
//Flag to turn off/set DHTML features
//to fire in accessible way.
//Set via Cookie found at EOF
var bAccessibleSet = 0;

var miscFuncContent = new Array();
miscFuncContent[0] = "addthis.html";
miscFuncContent[1] = "sharethis.html";

function callContentMiscFunc(i,parentId,targetId) {
	if ($("#placeHolder").length <= 0) {
		$("<div id=\"placeHolder\"></div>").insertAfter($("ul#" + parentId + " li a#" + targetId));
		$("ul#" + parentId + " li" + " div").load(miscFuncContent[i] + " .SmallPopUp",'',loadShareThisContent);
	}
}

function loadShareThisContent () {
    //Path to be updated:w
	var URI = "http:\/\/www.menactra.com\/"
    var iMktNum = "#";
	
	var sharedContent = $("<div></div>");
	sharedContent.html($("div#mainContent").clone());
	sharedContent.find("ul#miscFuncBox").remove();
	sharedContent.find("a.StyledLink1").remove();
	
	/* Elements */
	var wrapElement = sharedContent.find("div#mainContent");
	var h3Title = sharedContent.find("h3");
	var h3TitleSpan = sharedContent.find("h3 span");
	var h4Title = sharedContent.find("h4");
	var h4TitleSpan = sharedContent.find("h4 span");
	var pElement = sharedContent.find("p");
	var ulElement = sharedContent.find("ul");
	var liElement = sharedContent.find("ul li");
	var aLinkElement1 = $("<a></a>");
	var aLinkElement2 = sharedContent.find("a.StyledLink2");
	var downloadLink = sharedContent.find("ul.DownloadLink li a")
	var supElement = sharedContent.find("sup a");
	var allLink = sharedContent.find("a");
	
	var logoElement = $("<a href=\"http://www.menactra.com\" target=\"_blank\"><img src=\"" + URI + "images\/logo-share.gif\" width=\"104\" height=\"59\" alt=\"Menactra Logo\" border=\"0\" /></a>")
	var footerElement = $("<div></div>");
    //var mktNumElement=$("<div style=\"font-size: 12px; font-family: Arial,Tahoma,san-serif;color:#8f8f8f;\">MKT14930-"+iMktNum+"</div>");	


	/* Make href becomes absolute path */
	var ie = document.all;
	if (!ie) {
		allLink.attr("href", function () { 
								   return URI + $(this).attr("href");
								   })
	}
	/* Change alink content and attribute*/
	aLinkElement1.text("Learn More");
	aLinkElement1.attr("title", "Learn More");
	aLinkElement1.attr("href", window.location);
	aLinkElement1.appendTo(footerElement);
	/* Append Logo */
	logoElement.appendTo(footerElement);
	
	/* Append Footer */
	footerElement.appendTo(wrapElement)

    /* Append Market Number */
    //mktNumElement.appendTo(wrapElement);
	
	/* Styling */
	wrapElement.css({ width: "520px", overflow: "hidden", border: "1px solid #bdd8f2", position: "relative", padding: "20px" });
	h3Title.css({ color: "#0053A0", fontWeight: "normal", fontSize: "24px", fontFamily: "Helvetica, Arial, Tahoma,san-serif", margin: "0px", padding: "0px" });
	h3TitleSpan.css({ fontWeight: "bolder" })
	h4Title.css({ color: "#0053A0", fontWeight: "normal", fontSize: "16px", fontFamily: "Helvetica, Arial, Tahoma,san-serif", margin: "20px 0px 5px 0px", padding: "0px" });
	h4TitleSpan.css({ fontWeight: "bolder" })
	pElement.css({ color: "#505050", fontSize: "12px", fontFamily: "Arial, Tahoma,san-serif", margin: "5px 0px 5px 0px", padding: "0px" });
	ulElement.css({ margin: "5px 0px 15px 0px", padding: "0px", listStyle: "none" });
		liElement.css({ color: "#505050", fontSize: "12px", fontFamily: "Arial, Tahoma,san-serif", background: "url(" + URI + "images\/bullet1.gif) no-repeat left 6px", paddingLeft: "8px" });
	aLinkElement1.css({ color: "#0053A0", fontSize: "12px", fontWeight: "bolder", fontFamily: "Arial, Tahoma,san-serif", textDecoration: "none", textTransform: "uppercase" });
	aLinkElement2.css({ color: "#0053A0", fontSize: "12px", fontWeight: "bolder", fontFamily: "Arial, Tahoma,san-serif", textDecoration: "none" });
	downloadLink.css({ color: "#0053A0", fontSize: "12px", fontWeight: "bolder", fontFamily: "Arial, Tahoma,san-serif", textDecoration: "none" })
	supElement.css({ color: "#0053A0", fontSize: "10px", fontFamily: "Arial, Tahoma,san-serif", textDecoration: "none" });
	footerElement.css({ overflow: "hidden", width: "100%", marginTop: "25px" })
	logoElement.css({ "float": "right" })
	
	/* Add share this content */
	$("div#sharedContent").text(sharedContent.html());
}

function hideSmallPopUp(i) {
	$("div#placeHolder").remove();
}

var currentFontSize;

function fontResize() {
	$("a.increase").click(function () {
									if (currentFontSize < 77.5) {
										currentFontSize = currentFontSize + 5;
										$("body").css("fontSize", currentFontSize + "%");
										setCookie("globalFontSize",currentFontSize,365);
										return false;
									}
									});
	$("a.decrease").click(function () {
									if (currentFontSize > 62.5) {
										currentFontSize -= 5;
										$("body").css("fontSize", currentFontSize + "%");
										setCookie("globalFontSize",currentFontSize,365);
										return false;
									}
									});
}

//Cookies for fontsize
function getCookie(cookiesName) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(cookiesName + "=");
		if (c_start!=-1) { 
			c_start=c_start + cookiesName.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(cookiesName,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie=cookiesName+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie() {
	currentFontSize = getCookie('globalFontSize');
    currentFontSize = parseFloat(currentFontSize);

	if (currentFontSize) {
		$("body").css("fontSize", currentFontSize + "%");
	}
	else {
		currentFontSize = 62.5;
		$("body").css("fontSize", currentFontSize + "%");
	}
}

function setAccessibleCookie() {
    setCookie('bAccessible','1');
    //Reload
    location.href = location.href.replace(/\#.*$|\?.*$/,'');;
}


/*SET GLOBAL ACCESSIBLE FLAG*/
bAccessibleSet = getCookie('bAccessible');
/*SET GLOBAL ACCESSIBLE FLAG*/


//Global DOM ready applications
$(document).ready(function () {

    /* Don't set some DHTML features */
    if(bAccessibleSet) {
        $('.accessibleLink').remove();
        $('*').removeAttr("onclick");
        return false;
    }

	//Text Resize
	$("<li><span><a href=\"#\" class=\"decrease\" title=\"Decrease Font Size\">A</a></span> <a href=\"#\" class=\"increase\" title=\"Increase Font Size\">A</a> Text Resize</li>").insertAfter($("ul.MiscList li.Email"));
	
	fontResize();
	checkCookie();
	
	//Add this & Share this
	$("ul#miscFuncBox").css("display", "block");
	
    //Bind accessible link
    $('.accessibleLink').bind('click',setAccessibleCookie);
});

