	var ProductXML;		// Global holder
	var viewpage=1;		
	var totalpages=1;
	var totalScrollItems = 0;
	var itemsDisplayed = 4;
	var masterScrolObj;
	
	$(document).ready(function($) {		
		loadProductXML();
					
		$("#scrollBreadcrum").click(function() { 
			$("#scrollBreadcrum").html("");
			$('#inside-target').html("");
			parseCategoryXML();
			$('#update-target').scrollable().reload().begin();											  
		});
			 
	}); //close $(
	 
	 
	 function loadProductXML(){
	  // Grab XML file and parse for categories
		 $.ajax({
			 type: "GET",
			 url: "/kerr/xml/data.xml",
			 dataType: "xml",
			 success: function(xml) {	// WE HAVE XML HOUSTON
				 ProductXML = xml;
				 
				 //Parse xml categories for display
				 parseCategoryXML();
				 
				 updatePageCountDisplay();
				 
				 // Execute the scroller once the content has populated
				 executeCategoryDisplay();
			 }
		 }); //close $.ajax(
	 }
	 
	 function parseCategoryXML(){
		var categoryCounter=0;

		//Parse each category out of XML File
		$(ProductXML).find('category').each(function(){
			 var title_text = $(this).attr('title');
			 var thumbimg_text = $(this).attr('thumbnail');
			 categoryCounter++;
			 $('<div></div>')
				 .html('<img class="itemImage" alt="' + title_text + '" src="http://kerrdental.com' + thumbimg_text + '"/><p class="itemTitle">' + title_text + '</p>')
				 .appendTo('#inside-target');
		});//close each(  

		// Set the click function handler
		 $(".items div").click(function() {  

				var myItem = $(this);
				
				var mytxt = myItem.find("img").attr("alt"); 
				
				getProducts(mytxt);
		  }); 
		totalScrollItems = categoryCounter;
		
		return;
	 }
	 
	 function executeCategoryDisplay(){
		$('#update-target').scrollable({
			nextPage:'.scnext', 
			prevPage:'.scback',
			speed:2000,
			size:4,
			disabledClass:'disableNavs',
			clickable:false,
			onSeek: function(){
				viewpage = 1+Math.round(this.getPageIndex());
				totalpages = this.getPageAmount();
				updatePageCountDisplay();

			},
			onReload:function(){
				//alert('Reload');
				//this.seekTo(0);	
				$('.disableNavs').removeClass('disableNavs');
				viewpage = 1+Math.round(this.getPageIndex());
				totalpages = this.getPageAmount();
				updatePageCountDisplay();

			}
		  });
					
		 
	 }
	 
	 function updatePageCountDisplay(){
		
		 $('#prod_total_page').html(totalpages);
		 $('#prod_view_page').html(viewpage);
		 return;
	 }
	 

	 function getProducts(prod_title){
		 /* ***************************
		 1. First unload the categories from the scroller
		 2. parse out the products
		 3. 
		 
		  ***************************  */
		 $("#update-target").scrollable().setPage(0);
		 //return;
		 
		 //Set the bread crumb trail
		 $("#scrollBreadcrum").html(" &gt; " + prod_title);
		 
		 // Clear out all of the categories
		 $('#inside-target').html("");
		 		 
		 // copy master xml for use here
		 var xml = ProductXML;
		 
		 //Count how many items we have
		 var categoryCounter=0;
		
		 // itterate through each category until we find the one we want
		 $(xml).find('category').each(function()
		 {
			  var title_text = $(this).attr('title');  // category title
			  
			  if (title_text == prod_title)
			  {
				  //var textTest = 'Found Products: ';
				  $(this).find('product').each(function()
					  {
						  categoryCounter++;
						  
						  var product_title_text = $(this).attr('title');
						  var product_thumbimg_text = $(this).attr('thumbnail');
						  var product_link_text = $(this).attr('link');
						  
						 $('<div></div>')
							 .html('<img class="itemImage" alt="' + product_link_text + '" src="http://kerrdental.com' + product_thumbimg_text + '"/><p class="itemTitle">' + product_title_text + '</p>')
							 .appendTo('#inside-target');
					  }); // close product each
				  
			  }
			  
		 });// close category each

	  // Set the click function handler for products
	  $(".items div").click(function() {  
			var myItem = $(this);
			var mylink = myItem.find("img").attr("alt"); 
			//alert("will link to :" + mylink);
			window.open(mylink,"_self");
	  });



		// Reset it all
	  $('#update-target').scrollable().reload();

	  //viewpage=1;
	  totalScrollItems = categoryCounter;
	  totalpages = $('#update-target').scrollable().getPageAmount();
	  //alert(categoryCounter);
	  updatePageCountDisplay();
		 
		 
	 }