﻿
//fader for the default home page
function Fader()
{ 
	$('#gallery').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 7500, 
	    pause:   1,
		//next: 	'#gallery', //remove if you want to click on the image to do something
	    before:  onBefore, 
	    after:   onAfter 
	    
	});
	 	
	$('#excerpt').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 0
	});	 		
}
function onBefore() { 
} 
function onAfter() { 
	$('#excerpt').cycle('next');
}

//Fader for the microsites
function MicroSiteFader()
{ 
	$('#micrositegallery').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 7500, 
	    pause:   1,
		//next: 	'#micrositegallery', //remove if you want to click on the image to do something
	    before:  onMicrositeBefore, 
	    after:   onMicrositeAfter 
	    
	});
	 	
	$('#micrositeexcerpt').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 0
	});	 		
}
function onMicrositeBefore() { 
} 
function onMicrositeAfter () { 
	$('#micrositeexcerpt').cycle('next');
}

 
//fader for the header banners to go to microsites
function SubSiteFader()
{ 
	$('#subsitegallery').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 7500, 
	    pause:   1,
		//next: 	'#subsitegallery', //remove if you want to click on the image to do something
	    before:  onSubsiteBefore, 
	    after:   onSubsiteAfter 
	    
	});
	 	
	$('#subsiteexcerpt').cycle({ 
	    fx:     'fade', 
	    speed:   300, 
	    timeout: 0
	});	 		
}
function onSubsiteBefore() { 
} 
function onSubsiteAfter () { 
	$('#subsiteexcerpt').cycle('next');
}



		var Headline=""; 
		var Details=""; 
		var ImagePath=""; 
		var TargetUrl= "#";
		 
		$(document).ready(function() {
		
		$.getScript("/SiteAssets/MicroSiteNav.js");

		
		//Set up the main banner - these have NO SiteMapLink item.
		var query = "<Query><Where><IsNull><FieldRef Name='SiteMapLink'/></IsNull></Where><OrderBy><FieldRef Name='Ranking'/></OrderBy></Query>"; 
		
		$().SPServices({
			operation: "GetListItems",
			async: false,
			listName: "TahoeBannerList",
			CAMLQuery: query,
			CAMLViewFields: "<ViewFields><FieldRef Name='Headline text'/><FieldRef Name='Detailed Text'/><FieldRef Name='ImagePath'/><FieldRef Name='TargetUrl'/></ViewFields>",
			CAMLRowLimit: 10,
			// Even though setting IncludeMandatoryColumns to FALSE doesn't work as the docs describe, it fixes a bug in GetListItems with mandatory multi-selects
			CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='Recursive' /></QueryOptions>",
			completefunc: function(xData, Status) {
				
				$(xData.responseXML).find("[nodeName='z:row']").each(function() {					
					Headline = $(this).attr("ows_Headline");
					Details= $(this).attr("ows_DisplayText");
					ImagePath= $(this).attr("ows_ImagePath");		
					TargetUrl= $(this).attr("ows_TargetUrl");		
					if (TargetUrl == undefined) TargetUrl = "#";
					
				//build the lists
				var myUL = "<div class='content'><div class='head'><div>" + Headline + "</div></div><div class='display'><div>" + Details + "</div></div></div>";
				$("div[id=excerpt]").append(myUL);
				$("div[id=gallery]").append("<a href='" + TargetUrl + "'><img src=" + ImagePath + " alt='' /></a>");
				});
			}
		}); 
		Fader();
		
		//Check to see if we are in a MicroSite
		//AC: HACK!!! If the URL has Pages/Healthcare, do the work. Note that if we do this work
		//and we are not in the microsite, it won't hurt cause the div tags are not present.
		var query = "<Query><Where><Eq><FieldRef Name='SiteMapLink'/><Value Type='Text'>HealthcareSubsite</Value></Eq></Where></Query>"; 

		$().SPServices({
			operation: "GetListItems",
			async: false,
			listName: "TahoeBannerList",
			CAMLQuery: query,
			CAMLViewFields: "<ViewFields><FieldRef Name='Headline text'/><FieldRef Name='Detailed Text'/><FieldRef Name='ImagePath'/><FieldRef Name='TargetUrl'/></ViewFields>",
			CAMLRowLimit: 10,
			// Even though setting IncludeMandatoryColumns to FALSE doesn't work as the docs describe, it fixes a bug in GetListItems with mandatory multi-selects
			CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='Recursive' /></QueryOptions>",
			completefunc: function(xData, Status) {
				//var out = $().SPServices.SPDebugXMLHttpResult({
				//	node: xData.responseXML
				//});
				//$("div[id=ctl00_MSO_ContentDiv]").html("").append("<b>This is the output from the GetList operation:</b>" + out);
			 
				var itemCount = $(xData.responseXML).find("[nodeName='rs:data']").attr("ItemCount");
				if (itemCount == 0)
				{					
					return; 
				}
				 
				$(xData.responseXML).find("[nodeName='z:row']").each(function() {					
					Headline = $(this).attr("ows_Headline");
					Details= $(this).attr("ows_DisplayText");
					ImagePath= $(this).attr("ows_ImagePath");		
					TargetUrl= $(this).attr("ows_TargetUrl");		
					if (TargetUrl == undefined) TargetUrl = "#";
					
				//build the lists
				var myUL = "<div class='micrositecontent'><div class='micrositehead'><div>" + Headline + "</div></div><div class='micrositedisplay'><div>" + Details + "</div></div></div>";
				$("div[id=micrositeexcerpt]").append(myUL);
				$("div[id=micrositegallery]").append("<a href='" + TargetUrl + "'><img src=" + ImagePath + " alt='' /></a>");
				});
				//show it
				$("div[id=micrositeslider]").show();
			}
		}); 
		MicroSiteFader();


		//code for the bananer subsite 
		var queryStringVals = $().SPServices.SPGetQueryString();
		var ContentID = queryStringVals["Root"];
		if (ContentID == 'undefined')
		{
			//Hide the entire banner section!
			$("div[subsiteslider]").hide();			
			return; 
		}
		//do the same for the subsite (microsite) banner!
		var query = "<Query><Where><Eq><FieldRef Name='SiteMapLink'/><Value Type='Text'>" + ContentID + "</Value></Eq></Where></Query>"; 

		$().SPServices({
			operation: "GetListItems",
			async: false,
			listName: "TahoeBannerList",
			CAMLQuery: query,
			CAMLViewFields: "<ViewFields><FieldRef Name='Headline text'/><FieldRef Name='Detailed Text'/><FieldRef Name='ImagePath'/><FieldRef Name='TargetUrl'/></ViewFields>",
			CAMLRowLimit: 10,
			// Even though setting IncludeMandatoryColumns to FALSE doesn't work as the docs describe, it fixes a bug in GetListItems with mandatory multi-selects
			CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='Recursive' /></QueryOptions>",
			completefunc: function(xData, Status) {
				//var out = $().SPServices.SPDebugXMLHttpResult({
				//	node: xData.responseXML
				//});
				//$("div[id=ctl00_MSO_ContentDiv]").html("").append("<b>This is the output from the GetList operation:</b>" + out);
			 
				var itemCount = $(xData.responseXML).find("[nodeName='rs:data']").attr("ItemCount");
				if (itemCount == 0)
				{					
					return; 
				}
				 
				$(xData.responseXML).find("[nodeName='z:row']").each(function() {					
					Headline = $(this).attr("ows_Headline");
					Details= $(this).attr("ows_DisplayText");
					ImagePath= $(this).attr("ows_ImagePath");		
					TargetUrl= $(this).attr("ows_TargetUrl");		
					if (TargetUrl == undefined) TargetUrl = "#";
					
				//build the lists
				var myUL = "<div class='subsitecontent'><div class='subsitehead'><div>" + Headline + "</div></div><div class='subsitedisplay'><div>" + Details + "</div></div></div>";
				$("div[id=subsiteexcerpt]").append(myUL);
				$("div[id=subsitegallery]").append("<a href='" + TargetUrl + "'><img src=" + ImagePath + " alt='' /></a>");
				});
				//show it
				$("div[id=subsiteslider]").show();
			}
		}); 
		SubSiteFader();
				  
 	});




