﻿jQuery(function() {
		
	// code writes out content for the accordian image viewer
	var currentURL = location.pathname;	
	var currentLanguage = currentURL.substring(1, 3).toLowerCase(); // this needs to be parsed from the url 
	var accordianDiv = $("div#accordion-1 dl"); // div that will hold the accordian

	$().SPServices({
    operation: "GetListItems",
    async: false,
    webURL: "/",
    listName: "AccordianImageViewer",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Image' />" +
    				"<FieldRef Name='AltText' /><FieldRef Name='Link' />" + 
    				"<FieldRef Name='SiteLanguage' /></ViewFields>",
	    completefunc: function (xData, Status) {
			$(xData.responseXML).find("[nodeName='z:row']").each(function() { 
				// only display items from the current language
				if ($(this).attr("ows_SiteLanguage").toLowerCase() == currentLanguage)
				{
					accordianDiv.append("<dt>" + $(this).attr("ows_Title") + "</dt><dd>" +
						"<a href='" + $(this).attr("ows_Link") + "'><img src='" + $(this).attr("ows_Image").replace(", ", "") +
						"' alt='" + $(this).attr("ows_AltText") + "' border='0' /></a></dd>")
				}
				
			});	// end - $(xData.responseXML).find("[nodeName='z:row']").each	
		} // end - completefunc: function
	 }); // end - SPServices
	
	$("div#accordion-1 dl dt").last().addClass("active");
	
	if ($('#accordion-1').find("dd").size() > 0)
	{
		$('#accordion-1').easyAccordion({ 
			autoStart: true, 
			slideInterval: 5000,
			slideNum: false
		});
	}
	
});

