function catalog_xsl(xmlContent) {
  if (window.DOMParser) {
    parser     = new DOMParser();
    catalogXSL = parser.parseFromString(xmlContent, "text/xml");
  } else { // IE.
    catalogXSL = new ActiveXObject("Microsoft.XMLDOM");
    catalogXSL.async = false;
    catalogXSL.loadXML(xmlContent);
  }
}

// Here, we can't call the variable "catalog" because of IE.
function catalog_callback(xmlContent) {
  if (window.DOMParser) {
    parser   = new DOMParser();
    catalogX = parser.parseFromString(xmlContent, "text/xml");
  } else { // IE.
    catalogX = new ActiveXObject("Microsoft.XMLDOM");
    catalogX.async = false;
    catalogX.loadXML(xmlContent);
  }
  catalogId              = catalogX.getElementsByTagName('Id')[0].childNodes[0].nodeValue;
  catalogXMLs[catalogId] = catalogX;
  
  doCatalogDisplay(catalogId)
}

function item_xsl(xmlContent) {
  if (window.DOMParser) {
    parser  = new DOMParser();
    itemXSL = parser.parseFromString(xmlContent, "text/xml");
  } else { // IE.
    itemXSL = new ActiveXObject("Microsoft.XMLDOM");
    itemXSL.async = false;
    itemXSL.loadXML(xmlContent);
  }
}

// Here, we can't call the variable "item" because we have a function of that name.
function item_callback(xmlContent) {
  if (window.DOMParser) {
    parser = new DOMParser();
    itemX  = parser.parseFromString(xmlContent, "text/xml");
  } else { // IE.
    itemX = new ActiveXObject("Microsoft.XMLDOM");
    itemX.async = false;
    itemX.loadXML(xmlContent);
  }
  itemId           = itemX.getElementsByTagName('Id')[0].childNodes[0].nodeValue;
  itemXMLs[itemId] = itemX;
  
  doItemDisplay(itemId)
}

function doCatalogDisplay(catalogId) {
  if (window.ActiveXObject) {
    catalogHTML = catalogXMLs[catalogId].transformNode(catalogXSL);
  } else if (document.implementation && document.implementation.createDocument) {
    xsltProcessor = new XSLTProcessor();
    xsltProcessor.importStylesheet(catalogXSL);
    catalogNode = document.createElement("div");
    catalogNode.appendChild(xsltProcessor.transformToFragment(catalogXMLs[catalogId],document))
    catalogHTML = catalogNode.innerHTML;
  } else {
    alert("We're sorry, your browser does not support our catalog interface.");
    return false;
  }

	var myViewWidth = 0, myViewHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myViewWidth = window.innerWidth;
    myViewHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myViewWidth = document.documentElement.clientWidth;
    myViewHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myViewWidth = document.body.clientWidth;
    myViewHeight = document.body.clientHeight;
  }
	var myHeight = myViewHeight-40;
	
	uberWin = new Ext.Window({
		id:'catWin',
		title:'Catalog Viewer',
		autoScroll:true,
		width:520,
		height:myHeight,
		layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:catalogHTML
	});
  uberWin.addListener('beforeshow', onOpenWindow);
  uberWin.addListener('close', onCloseWindow);
	
	uberWin.setPosition(20);
	uberWin.show();

	var div = document.createElement('DIV');
	
	if (navigator.userAgent.toLowerCase().match('firefox')) {
		var catV = $('catalog-viewport');
		var catS = $('catalog-summary-view');
		var catD = $('catalog-details-view');
		var catT = $('catalog-terms-view');

		div.innerHTML = catV.innerHTML;
		catV.innerHTML = div.textContent;

		div.innerHTML = catS.innerHTML;
		catS.innerHTML = div.textContent;

		div.innerHTML = catD.innerHTML;
		catD.innerHTML = div.textContent;

		div.innerHTML = catT.innerHTML;
		catT.innerHTML = div.textContent;
	}
		
		$$('.itemListText').each(function(text) {
			div.innerHTML = text.innerHTML.replace('&gt;', '>').replace('&lt;', '<');
			text.innerHTML = div.textContent;
		});
	
	$('catalog-loading').hide();
	return false;
}

function doItemDisplay(itemId) {
  if (window.ActiveXObject) {
    itemHTML = itemXMLs[itemId].transformNode(itemXSL);
  } else if (document.implementation && document.implementation.createDocument) {
    xsltProcessor = new XSLTProcessor();
    xsltProcessor.importStylesheet(itemXSL);
    itemNode = document.createElement("div");
    itemNode.appendChild(xsltProcessor.transformToFragment(itemXMLs[itemId],document))
    itemHTML = itemNode.innerHTML;
  } else {
    alert("We're sorry, your browser does not support our catalog interface.");
    return false;
  }
    
  var myViewWidth = 0, myViewHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myViewWidth = window.innerWidth;
    myViewHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myViewWidth = document.documentElement.clientWidth;
    myViewHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myViewWidth = document.body.clientWidth;
    myViewHeight = document.body.clientHeight;
  }
	var myHeight = myViewHeight-40;
	var myWidth  = 750;
	var myFrameWidth = 710;
	var myFrameHeight = 710;

	uberWin = new Ext.Window({
		id:'itemWin',
		title:'Item Viewer',
		autoScroll:true,
		width:myWidth,
		height:myHeight,
		layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:itemHTML
	});
	
	uberWin.show();

	if (navigator.userAgent.toLowerCase().match('firefox')) {
	  var itemD = $('item-details-view-details');
	  var itemM = $('item-directions-view');
	  var div = document.createElement('DIV');

	  div.innerHTML = itemD.innerHTML;
	  itemD.innerHTML = div.textContent;
	  
	  div.innerHTML = itemM.innerHTML;
	  itemM.innerHTML = div.textContent;
	}
	
	if ($('slider5') != null) {
    featuredcontentslider.init({
      id: "slider5",  //id of main slider DIV
      contentsource: ["inline", ""],  //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
      toc: "markup",  //Valid values: "#increment", "markup", ["label1", "label2", etc]
      nextprev: ["", ""],  //labels for "prev" and "next" links. Set to "" to hide.
      revealtype: "mouseover", //Behavior of pagination links to reveal the slides: "click" or "mouseover"
      enablefade: [true, 0.1],  //[true/false, fadedegree]
      autorotate: [true, 3500],  //[true/false, pausetime]
      onChange: function(previndex, curindex){  //event handler fired whenever script changes slide
        //previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)
        //curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)
      }
    });
  }

	return false;
}
