$(document).ready(
	function() {
		$('.popup').bind("click",function() {
			winName = $(this).text() + 'Child';
			openChildWindow(this.href,winName.replace(/ /g,''));
			return false;
		});
	}
);

// The following function was written by Peter-Paul Koch (www.quirksmode.org)
function findPos(obj) {
	var curtop = curleft = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop;
		curleft = obj.offsetLeft;
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop;
			curleft += obj.offsetLeft;
		}
	}
	return [curtop,curleft];
}

function showModal(element,id,width,height,url,task) {
	
	var contentID = "#" + id;
	var divID = "#modal" + id;
	var modalWidth = width;
	var modalHeight = height;

	// Build the overlay
	var modalOverlay = "";
	// If we're using IE, we need to overlay an iframe to block out ActiveX elements such as <select> tags
	if ($.browser.msie) {
		modalOverlay += "<iframe id=\"modalHideSelect\" src=\"javascript:false;document.write('');\"></iframe>";
	}
	// This displays the 30% opaque white overlay
	modalOverlay += "<div id=\"modalWashout\">&nbsp;</div>";
	// Add the overlay to the page.
	$("body").append(modalOverlay);

	// Determine the inner dimensions of the browser window
	if (window.innerHeight) {
		var winHeight = window.innerHeight;
		var winWidth = window.innerWidth;
	}
	else {
		var winHeight = document.documentElement.clientHeight;
		var winWidth = document.documentElement.clientWidth;
	}
	
	// Determine the height of the content in the page
	var bodyHeight = document.body.parentNode.scrollHeight;
	var bodyWidth = document.body.parentNode.scrollWidth;

	// Stretch the iframe to cover the content of the page
	if ($.browser.msie) {
		$("#modalHideSelect").height(bodyHeight);
		$("#modalHideSelect").width(bodyWidth);
	}
	// Stretch the overlay to cover the content of the page
	$("#modalWashout").height(bodyHeight);
	$("#modalWashout").width(bodyWidth);

	// Grab the content for the modal from the corresponding div
	var modalContent = $(contentID).html();
	// Build the drop shadowed box around the content
	var modalBox = buildBox("modal",id,modalContent);
	// Insert the modal code into the page
	$("body").append(modalBox);
	// If the width of the modal is wider than the browser window, reduce the size
	if ((modalWidth+30) > winWidth) {
		modalWidth = winWidth-30;
	}
	// Set the width of the modal as declared in the function call
	$(divID).width(modalWidth);
	// If the height of the modal is taller than the browser window, reduce the size
	if ((modalHeight+30) > winHeight) {
		modalHeight = winHeight-30;
	}
	// Set the height of the modal
	$(divID).height(modalHeight);

	// Explicitly set the height and width of the modal content container
	$(divID+" .modalContent").width(modalWidth-12);
	$(divID+" .modalContent").height(modalHeight-24);

	// If the modal contain an iframe holder, pull out the source so we can build the iframe later
	if ($(divID+" .modalContent .iframe")) {
		var iframeSrc = $(divID+" .modalContent .iframe").text();
		// Trim any whitespace, tabs, or line breaks from the URL
		iframeSrc = iframeSrc.replace(/^\s+|\s+$|\t|\n|\r/g, "");
		// Remove the span tag that contained the iframe URL
		$(divID+" .modalContent .iframe").remove();
		// Remove anything left over in the content div as we can't have an iframe co-exist with other content
		$(divID+" .modalContent").empty();
	}
	// Otherwise, just allow the content of the modal to scroll
	else {
	 	$(divID+" .modalContent").css({overflow: "auto"});
	}
	
	// Determine how far down the page has been scrolled.
	var scrollDown = scrollRight = 0;
	if (typeof(window.pageYOffset ) == 'number') {
		scrollDown = window.pageYOffset;
		scrollRight = window.pageXOffset;
	}
	else {
		scrollDown = document.documentElement.scrollTop;
		scrollRight = document.documentElement.scrollLeft;
	}

	// Some math used to position the modal in the horizontal and vertical center of the page
	var endTop = Math.round((winHeight-modalHeight)/2);
	var endLeft = Math.round((winWidth-modalWidth)/2);
	// Find the position of the clicked element on the page
	var coors = findPos(element);
	var startTop = coors[0] - scrollDown;
	var startLeft = coors[1] - scrollRight;
	// IE6 does things backwards, so we need to correct it
	if ($.browser.msie && ($.browser.version <= 6)) {
		endTop = endTop + scrollDown;
		endLeft = endLeft + scrollRight;
		startTop = startTop + scrollDown;
		startLeft = startLeft + scrollRight;
	}

	// Position the starting point of the modal
	$(divID).css({top: startTop, left: startLeft, width: 0, height: 0});

	// Enable shadows immediately since this one isn't fading in
	$(divID).addClass("showShadows");
	$(divID).animate({top: endTop, left: endLeft, width: modalWidth, height: modalHeight},500,
		function() {
			// Add the iframe back in
			if (iframeSrc) {
				$(divID+" .modalContent").append("<iframe frameborder=\"0\"></iframe>");
				// force the iframe src to be that of the 'url' argument.  Fixes IE caching bug.  maldridg 08/25/2007
				$(divID+" .modalContent iframe").attr("src", url);
				$(divID+" .modalContent iframe").show();
			}
		}
	);
	$(divID+" .closeModal").click(function() { hideModal(id); return false; });
}

function hideModal(id) {
	var divID = "#modal" + id;
	// Hide the iframe
	$(divID+" .modalContent iframe").hide();
	// Disable shadows before fading out (only in IE7, controlled via CSS)
	$(divID).removeClass("showShadows");
	// Fade out the modal
	$(divID).fadeOut("normal",function(){
		$(divID).remove();
		// Remove the overlay
		$("#modalWashout").hide(); $("#modalWashout").remove();
		if ($.browser.msie) { // Remove the iframe
			$("#modalHideSelect").hide(); $("#modalHideSelect").remove();
		}
	});
}

function createTip(element,id) {
	// Create a unique ID for the DIV
	var divID = "#tip" + id;
	// Collect the contents of the title attribute and put it in a paragraph tag
	var origTitle = $(element).attr("title");
	// Convert the "format codes" into HTML
	/* Format code syntax:
		All codes MUST have spaces on each side or it to translate properly.
		" :: " (that's [space][colon][colon][space]) separates the preceeding text from rest.
		Any text before " :: " will be the header and wrapped in <p> and <strong> tags.
		" // " (that's [space][slash][slash][space]) translates into line breaks.
		" \\ " (that's [space][backslash][backslash][space]) translates into paragraph breaks.
		Tip: Line breaks can be used in headings by using " // " before " :: "
	*/
	if(origTitle.match(" :: ")) {
		var tip = "<p><strong>" + origTitle.replace(/ :: /, "</strong></p><p>");
	}
	else {
		var tip = "<p>" + origTitle;
	}
	tip = tip.replace(/ \\\\ /g, "</p><p>");	
	tip = tip.replace(/ \/\/ /g, "<br />");
	// Close the paragraph tag
	tip = tip + "</p>";
	// Put together the content for the tool tip box
	var toolTipContent = "<div class=\"toolTipContent\">";
	toolTipContent += tip;
 	toolTipContent += "</div>";
	// Build the drop shadowed box around the content
	var tipBox = buildBox("tip",id,toolTipContent);
	// Insert the tool tip code into the page
	$(tipBox).insertAfter(element);
	// Remove the title attribute so it doesn't show with the tool tip
	$(element).attr("title","");
	// Find the position of the anchor on the page
	var coors = findPos(element);
	var x = coors[1]-5;
	var y = coors[0]+15;
	// Position the tool tip
	$(divID).css({top: y, left: x});
	// Fade in the tool tip quickly.  This is just enough to hide the visible repositioning of the tip
	$(divID).fadeIn("fast",function() {
		// Enable shadows after fading in (only in IE7, controlled via CSS)
		$(divID).addClass("showShadows");
	});
}

function destroyTip(element,id,title) {
	var divID = "#tip" + id;
	// Put the original title content back into the title attribute
	$(element).attr("title",title);
	// Disable shadows before fading out (only in IE7, controlled via CSS)
	$(divID).removeClass("showShadows");
	// Delete the tool tip.
	$(divID).fadeOut("fast",function() {
		$(divID).remove();
	});
}

function buildBox(type,id,content) {
	var buildBox = "";
	// Default to modal
	if (type=="tip") {
		var buildBox = "<div id=\"tip" + id + "\" class=\"sebtToolTip\">";
	}
	else {
		var buildBox = "<div id=\"modal" + id + "\" class=\"sebtModal\">";
	}
	buildBox += "	<div class=\"shadowTopLeft\">&nbsp;</div>";
	buildBox += "	<div class=\"shadowTopRight\">&nbsp;</div>";
	buildBox += "	<div class=\"shadowLeft\">";
	buildBox += "		<div class=\"shadowRight\">";
	if (type=="tip") {
		buildBox += "			<div class=\"shadowTipContent\">";
	}
	else {
		buildBox += "			<div class=\"shadowModalContent\">";
	}
	buildBox += content;
	buildBox += "			</div>";
	buildBox += "		</div>";
	buildBox += "	</div>";
	buildBox += "	<div class=\"shadowBottomLeft\">";
	buildBox += "		<div class=\"shadowBottomRight\">";
	buildBox += "			<div class=\"shadowBottom\">&nbsp;</div>";
	buildBox += "		</div>";
	buildBox += "	</div>";
	buildBox += "</div>";
	return buildBox;
}

function modifyTitle(task) {
	titleText = "Select Your Product or Technology";
	if(task==1) {
		tempID=document.getElementById("i_title");
		tempID.innerHTML = titleText;
	}
	else {
		tempID=document.getElementById("i_title");
		tempID.innerHTML = task +  " - " + titleText;
	}
}