var myHighlightsXML='/highlights_xml/'+item_type+'_'+item_id+'.xml';
var myLearnmoreXML='/learnmore_xml/'+item_type+'_'+item_id+'.xml';
var atLeastOneHighlight=false;

$(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: myHighlightsXML,
    dataType: "xml",
    success: parsePageXml
  });
});

$(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: myLearnmoreXML,
    dataType: "xml",
    success: parsePageXml
  });
});

function parsePageXml(xml)
{
  var className = $(xml).find("className").text();
  $(className).css('display', 'block');  //make the header visible
  $(xml).find("highlight").each(function()
  {
  	if ($(this).find("domainId").text() == '20') {
		//usun custom styles
	    	$("#body-row02-col03").css('display','block');
	    	$("#body-row02-col01andcol02").css('width','695px'); // when there is no left nav
	    	$("#body-row02-col02").css('width','535px'); // when there IS a left nav
	    	$("#body-row02-col02").css('background','none'); 
		//usun styles for the accordian - they are named differently than what's in "className" var,
		// so we have to make sure we turn on the right one.
		if (className.indexOf('highlights') != -1) {
  			$("#highlights").css('display', 'block');
  			$("#highlights-body").css('display', 'block');
			// always show the highlights accordian pre-opened if there are highlights
			$("#highlights").removeClass("closed").addClass("open");
			atLeastOneHighlight=true;
		}
		else {
  			$("#learn-more").css('display', 'block');
			if (!atLeastOneHighlight) {
				// show the learnmore accordian pre-opened since there were no highlights at all
  				$("#learnmore-body").css('display', 'block');
				$("#learn-more").removeClass("closed").addClass("open");
			}
		}
	}
	if ($(this).find("domainId").text() == '11') {
          //pepfar custom styles
          $("#highlights-tier3-short").css('display','block');
          $("#highlights-tier3-long").css('display','block');
    }
	if ($(this).find("domainId").text() == '15') {
                //diplomacy.state.gov custom styles
        }
  	if ($(this).find("domainId").text() == '23') {
		//ecoparterships custom styles
	    	//$("#right_content_well_container").css('width','570px');  // down from 770 default
	    	//$("#right_content_well_container").css('float','left');
	    	//$("#highlights-container").css('display','block'); 
	}
  	if ($(this).find("domainId").text() == '24') {
		//ghi custom styles
	    	$("#left-content").css('width','700px');  // down from 930 default
	    	$("#sidebar-right").css('display','block');
	    	$("#highlights").css('display','block');
	}
  	if ($(this).find("domainId").text() == '25') {
		//apec custom styles
	}
  	if ($(this).find("domainId").text() == '26') {
		//strategictrade (exbs) custom style to reduce content width when highlight or learnmore is present
	    	$("#content-well").css('width','696px');
	}
  	if ($(this).find("domainId").text() == '27') {
		//crc custom styles
	    	$("#highlights").css('display','block');
	}
  	if ($(this).find("domainId").text() == '3') {
		//fpc custom styles
		if (className.indexOf('highlights') != -1) {
	    		$("#highlights-headline-fpc").css('display','block');
		}
		else {
	    		$("#learnmore-headline-fpc").css('display','block');
		}
	    	$("#body-row02-col01andcol02").css('width','670px');
	    	$("#body-row02-col02").css('width','530px');
	}
  	if ($(this).find("domainId").text() == '2') {
		//oig custom style for content width when left nav present
	    	$("#body-row02-col02andcol03").css('width','530px'); // down from 770
	    	$("#body-row02-col01andcol02andcol03").css('width','670px');  // down from 910
		//oig styles for the accordian - they are named differently than what's in "className" var,
		// so we have to make sure we turn on the right one.
		if (className.indexOf('highlights') != -1) {
  			$("#highlights").css('display', 'block');
  			$("#highlights-body").css('display', 'block');
			// always show the highlights accordian pre-opened if there are highlights
			$("#highlights").removeClass("closed").addClass("open");
			atLeastOneHighlight=true;
		}
		else {
  			$("#learn-more").css('display', 'block');
			if (!atLeastOneHighlight) {
				// show the learnmore accordian pre-opened since there were no highlights at all
  				$("#learnmore-body").css('display', 'block');
				$("#learn-more").removeClass("closed").addClass("open");
			}
		}
	}
	var highlightId = $(this).find("highlight_id").text();
	var highlightDiv = $(this).find("highlight_container").text();
    	//$(highlightDiv).append("<strong>" + $(this).find("name").text() + "</strong><br />");
	//alert($(this).find("highlightPath").text());
  	$.ajax({
	    type: "GET",
	    url: $(this).find("highlightPath").text(),
	    dataType: "xml",
	    success: function(highlightXml) {
  		var name = $(highlightXml).find("name").text();
		//alert(name);
	  	var highlightHtml = $(highlightXml).find("highlightHtml").text();
    		$(highlightDiv).html("<strong class='highlight-header'>" + name + "</strong>");
		$(highlightDiv).append(highlightHtml + "<hr>");
    		$(highlightDiv).css('display','block');
	    }
	  });
  });
}

