      function dump(arr,level) {
      var dumped_text = "";
      if(!level) level = 0;
      //The padding given at the beginning of the line.
     var level_padding = "";
      for(var j=0;j<level+1;j++) level_padding += " ";
      if(typeof(arr) == 'object') { //Array/Hashes/Objects
      for(var item in arr) {
      var value = arr[item];
      if(typeof(value) == 'object') { //If it is an array,
      dumped_text += level_padding + "'" + item + "' ...\n";
      dumped_text += dump(value,level+1);
      } else {
      dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
      }
      }
      } else { //Stings/Chars/Numbers etc.
      dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
      }
      return dumped_text;
      };


/*

STINK DIGITAL JS OBJECT
GLOBAL SCRIPTS
WORK FILTER SCRIPTS
PAGER SCRIPTS

*/

///////////////////////////////////////////////////////
// STINK DIGITAL

/*
	FILTER
		setfilter // used to manage filters when clicked on work filters page
		togglefilter
		togglefilters
		setresultstotals
		flipcurrentsection
		appendbreadcrumbresults
		drawpaginator
		reconnectpaginate
		loadworkresults
		toggleresultgroups
		loadwork
	WORK
	FAQ
	NEXT PREVIOUS BUTTONS
	AJAX
	RESULTS
*/
	
	var records = new Array();


	//STINK DIGITAL OBJECT

	jQuery.SD = {
	
		options: {
			//options for this object only
		},
		

	//// FILTER

  		// Set filter when click button
  		setFilter : function(filter, action) {

  			// disable links for resultset and filters
  			$.SD.toggleResultGroups('fadeOut');

			//do nothing for greyed out options
  			if ($(filter).hasClass('unavailable')) {
  				return false;
  			}
  			var link = $(filter).find("a");
			//post the request
			$.ajax({
				type: "GET",
				url:  $(link).attr("href"),
				data:  { format: "json" },
				dataType: "json",
				success: function (data) {

					//fetch the data for the new 
					//filtered work results
					$.SD.loadWorkResults(data.workList);
					$(".rollover-box span").hide();

					//hide resultgroups to enable fadein
					$(".resultgroup").hide();

					//toggle the css class for the 
					//specific fitler
					$.SD.toggleFilter(filter);

					//toggle the rest of the filters 
					//to ensure they are active or not
					$.SD.toggleFilters(data.filters);

				},
				failure: function () {
				}, 
				error: function () {
  					$.SD.toggleResultGroups('fadeIn');
				}, 
				complete: function () {
  					$.SD.toggleResultGroups('fadeIn');
				}
			});
  		},
  		
  		//change the settings on an individual filter
  		toggleFilter : function (item) { 	
  			//make the css amendments to display
			$(item)
				.removeClass();
  		},
  		
  		//change the settings for the entire filters list
  		toggleFilters : function (list) {

	  		//set the page doc title
	  		var split = document.title.split(' : ');
			document.title = split[0]+' : '+ split[1] +' :';

			//toggle the dispay css for the filters list.
  			$.each(list, function (key, item) {
  				//remove classes, add state and change URL
  				$('#cats #c' + key).removeClass().addClass(item.state);
  				$('#cats #c' + key + ' a').attr({
  					href: '/'+item.url
  				});
  				//unbind click for inactive items
  				if (item.state == 'unavailable') {
  					$('#cats #c' + key + ', #cats #c' + key + ' a').unbind("",false);
  				} else {
  					$('#cats #c' + key + ' *').bind("", false);
  				}
  			});
  			//unbind unavailables
  			$('.unavailable').unbind("",false);2
  			//bind availables
  			$('.available, .active').bind("",false);
  			
  			// count the number of active categories
  			var numactive = 0;

			//run through the filters and assign the link title
			$("#categories-list li").each( function () {
				if ($(this).hasClass('unavailable')) {
					$(this).find('a').attr({
						title: 'Filter is not available.'
					});
				} else if ($(this).hasClass('available')) {
					$(this).find('a').attr({
						title: 'Add \''+ $.trim($(this).text()) +'\' filter to search results.'
					});
				} else if ($(this).hasClass('selected') || $(this).hasClass('active')) {
					//append the filter to the top of the page
					document.title +=  ' ' + $.trim($(this).text()) + ' :'; 
					numactive++;
					$(this).find('a').attr({
						title: 'Remove \''+ $.trim($(this).text()) +'\' filter from search results.'
					});
				}
			});
			//init the page title
			if (numactive == 0) {
				document.title +=  ' View All'; 
			}

  		},

		//set the values for the results totals on work/filter
  		setResultTotals : function () {
			//set the result values
			$("#resultset dd").html(' displaying <span id="visible">6</span> of <span id="total">6</span>.');
			//figure totals
			var total = $("#results .resultitem").size();
			var settotal = $("#results #set-0 > .resultitem").size();
			if (total == 0) {
				$("#resultset dd").html('Sorry, there are no matching items for this selection of filters.');
			} else if (total == 1 ) {
				$("#resultset #total").html(total);
				$("#resultset #visible").html(settotal);
				//set breadcrumb item
			} else {
				$("#resultset #total").html(total);
				$("#resultset #visible").html('1-'+settotal);
			}
  		}, 

		//switch a brewadcrum div for a link
		flipCurrentSection : function (url, title, text) {
			$('#currentSection').replaceWith('<a id="currentSection" href="'+url+'" title="'+title+'">'+text+'</a>');
		},

		//switch a breadcrumb div for a link
		appendBreadcrumbResults : function () {
			var total = $("#results .resultitem").size();
			var settotal = $("#results #set-0 > .resultitem").size();
			//set breadcrumb filter result items
			if ($("#currentResults").size()==1) {
				$("#currentResults").html('Results ('+ total +')');
			} else {
				$("#currentSection").after('<div id="currentResults">Results ('+ total +')</div>');	
			}		
		},
  		
  		//draw the paginator list
  		drawPaginator : function () {
  			if ($("#results > .resultgroup").size() > 1) {
  				var resultspage = true;
  			} else {
  				var resultspage = false;
  			}
  		
			//clear the menu
			$("ul.paginate").empty();
			// check to see if more than one page 
			if ($("#results > .resultgroup, #projectportfolio > .resultgroup").size() > 1) {
				//Generate the pagination 
				if (resultspage == true) {
					$("ul.paginate").append('<li id="previous-arrow"></li>');
					$("ul.paginate").append('<li id="previous">PREV</li>');
				}
				$("#results > div, #projectportfolio > div").each(function (index) {
					$("ul.paginate").append('<li id="item' + index + '" class="page">'+(index+1)+'</li>');
				});
				if (resultspage == true) {
					$("ul.paginate").append('<li id="next">NEXT</li>');
					$("ul.paginate").append('<li id="next-arrow"></li>');
				}
			}
			$.SD.reconnectPaginate();
  		}, 
  		
  		//reconnect the paginater links
  		reconnectPaginate: function () {

			//assign the scroller
			var results = $('#results, #projectportfolio');
			//check to see if the scrollTo plugin has been loaded
			if (typeof $(results).serialScroll == 'function') {

				$(results).serialScroll({
					items:'.resultgroup',
					duration: 500,
					axis:'X',
					easing: 'easeOutSine',
					step: 1, 
					next: '.paginate #next',
					previous: '.paginate #previous',
					lazy:true,
					cycle: false,
					navigation: 'li.page',
					onBefore:function( e, elem, $pane, $items, pos ) {
						$.SD.embedToggleState('projectportfolioitem'+(pos+1)+'', 'play');
						/*
							if (pos == 0) { $("#previous").fadeOut(); } else { $("#previous").fadeIn();  }
						*/
						$(".paginate li").toggleClass('scrolling');
						var startpoint = ((pos*6)+1);
						var endpoint = ((startpoint + $(elem).find('.resultitem').size())-1);
						$("#resultset #visible").html(startpoint + '-' + endpoint);
						$.SD.togglePaginator(pos);
					}, 
					onAfter:function( elem ) {
						$(".paginate li").toggleClass('scrolling');
					}
	
				});
			
				//reset slider to zero
				$(results).serialScroll().scrollTo(0);
				$(results).serialScroll().trigger('notify',0);

				//set up paginate
				if ($(".paginate .selected").size() == 0) {
					$(".paginate li#item0").addClass('selected');
				}
			
			}

  		},
  		
  		//change the select status for paginator buttons
  		togglePaginator: function (position) {
			$('li.page').removeClass('selected');
			var pos = $('li#item' + position + '');
			$(pos).addClass('selected');
  		},

  		// update the work results based on filters
  		loadWorkResults : function(list) {

  			$("#results").empty();

			var counter = 0;
			var setcounter = 0;

			$.each(list, function () {
				//assign this object to a var
				var project = this;
				var breadtitle = '';
				if (project.client !=null) {
					breadtitle = project.client + ' - '+ project.name;
				} else {
					breadtitle = project.name;
				}

				//add project details to results
	  			$("#results").append('<div id="'+ project.workID +'" class="resultitem"><div class="rollover-box"><div class="preview"><a href="/work/'+ project.url 
				+'" title="Work details for \''+ project.name +'\'"><img src="'+ globals.urlImagesPath +'/preview/'+ project.filename +'" alt="Preview thumbnail of \''+ breadtitle 
				+'\'" width=300 height=140 border=0 /> <span class="bgd"></span> <span class="text"> '+ breadtitle + 
				' </span><div class="overlay"></div></a></div></div></div>');

				//add new results group set
				if ($('#results > div.resultitem').size() == 6) {
					$('#results > div.resultitem').wrapAll('<div id="set-'+ setcounter +'" class="resultgroup"></div>');
					setcounter++;
				}

				//increment counter
				counter++;

			});

            // catch the last few stragglers
            if (counter%6 > 0 | counter%6 < 0) {
	            $('#results > div.resultitem').wrapAll('<div id="set-'+ setcounter +'" class="resultgroup"></div>');
	        }

			//Set totals
			$.SD.setResultTotals();
			$.SD.flipCurrentSection('/work','Stink Digital Work','Work');
			$.SD.appendBreadcrumbResults();
			
			//draw the pagination
			$.SD.drawPaginator();


  		},

  		// update the work results based on filters
  		toggleResultGroups : function(state) {
			if (state == 'fadeOut') {
				//hide and display loading
  				$(".resultgroup, ul.paginate").fadeOut("slow");
  				$("#resultset").fadeOut("slow");
  				$("#cats li").addClass('loadingjson');
	  			$("#results").append('<div id="loading">Loading new results ...</div>');
			} else if (state == 'fadeIn'){
  				$("#cats li").removeClass('loadingjson');
				// bring the suckers back to life.
	  			$(".resultgroup, ul.paginate").fadeIn("slow");
  				$("#resultset").fadeIn("slow");
			}
  		},


	//// WORK

  		// ajax in the content to the project page
  		updateWork : function(work) {
  			//set sections to loading
  			$.SD.loadPage('hide');
  			//post the request
  			$.ajax({
				type: "GET",
				url: work.href,
				data:  { format: "json" },
				dataType: "json",
				success: function (data) {
					
					if (undefined !== data.nextPrev)
					{
						//change the next and previous button content
						$.SD.setNextPrevious('next', data.nextPrev.next);
						
						if (undefined !== data.nextPrev.previous)
						{
							$.SD.setNextPrevious('previous', data.nextPrev.previous);
						}
					}

					//update the text on the page
					$.SD.updateWorkContent(data);
				},
				error: function () {
				},
				complete: function () {
  					$("#loader").remove();
					$.SD.loadPage('show');
				}
			});
  		},
  		
  		appendCredit : function(varname, title, data) {
			var content = '';
			if (eval('data.' + varname) != null) {
				if (eval('data.'+varname+'Url')) {
					content = '<a href="/work/'+varname+'/'+eval('data.'+varname+'Url')+'" title="View more work by '+eval('data.' + varname)+'">'+eval('data.' + varname)+'</a>';
				} else {
					content = eval('data.' + varname);
				}
				$(".credits-list").append('<dt>'+title+'</dt><dd id="'+varname+'">'+content+'</dd>');
			}
  		},
  		
  		// take the project details and insert into page
  		updateWorkContent : function(data) {
 			var details = data.workDetails;
 			var quicklinks = data.quicklinks;
 			var tweets = data.tweets;
 			//assign project title
				var projecttitle = '';
				if (details.client !=null) {
					projecttitle = details.client + ' - '+ details.name;
				} else {
					projecttitle = details.name;
				}

 			//set the trail
	  		$('#trail #selectedWork').html(projecttitle);

	  		//set the page doc title
	  		var split = document.title.split(' : ');
			document.title = split[0]+' : '+ split[1] +' : ' + projecttitle;

			//adjust the credits list
			$(".credits-list").empty();
			$.SD.appendCredit('client','Client',details);
			$.SD.appendCredit('director','Director',details);
			$.SD.appendCredit('agency','Agency',details);
			$.SD.appendCredit('createdDate','Release Date',details);

			//fix the description
			$("div#about-the-work").html(details.description);

	  		//#links-list
	  		var qlmsg = '<li>No related links.</li>';

			//change the list of relatedlinks
			if (typeof quicklinks == 'object') {
				if ($(quicklinks).size() > 0) {
					$("#relatedlinks").empty();
					$(quicklinks).each(function () {
						if (this.url.length > 0) {
							var target = '';
							var regex = 'stinkdigital';
							if (this.url.search(regex) == -1) {
								target = ' target="_blank"';
							}
							$("#relatedlinks").append('<li class="'+this.type.toLowerCase()+'"><span><a href="'+ this.url+'" title="Link to: '+this.name+'"'+target+'>'+this.text+'</a></span></li>');
						} else {
							$("#relatedlinks").append('<li class="'+this.type.toLowerCase()+'"><span>'+this.text+'</span></li>');
						}
					});
				} else {
					$("#relatedlinks").html(qlmsg);		
				}
			} else {
				$("#relatedlinks").html(qlmsg);
			}
			

			//Share Link
			$("#sociallinks #addthis").text("Bookmark or share '" + projecttitle + "'");
			$("#sociallinks #addthis").live('mouseover',function () {
				return addthis_open(this, '', globals.urlBasePath + 'work/' + details.url, projecttitle );
			});

			//change the list of visible tweets
			//for what people are saying ...
			if (typeof tweets == 'object') {
				if ($(tweets).size() > 1) {
					$("#twitterfeed").show();
					$("#tweets").empty();
					$(tweets).each(function () {
						var tweet = '<li class="utterance"><img src="' + this.image + '" border="0" alt="Twitter user icon" width="48" height="48" align="right" /> '+ this.content + ' - <small><em>from ' + this.author + '</em></small></li>';
						$("#tweets").append(tweet);
					});
					$("#tweets .utterance a").each(function () {
						// && eregi("http",$(this).text())
						if ($(this).text().length > 15) {
							$(this).text($(this).text().substr(0,15)+'...');
						}
					});
				} else {
					$("#twitterfeed").hide();
				}
			} else {
				$("#twitterfeed").hide();
			}

			//remove the SOTD link
			$('#fwasotdcredit').remove();

			//empty, generate and append the slides for the gallery
			$("#projectportfolio").empty().append($.SD.displayWorkContent(details));
			$.SD.updateEmbedSWF(details);
			//draw the pagination
			$.SD.drawPaginator();
  		},

		//create the slides
		displayWorkContent: function (details) {
			var assets = details.content;
			var slides = '';
			for(var i=0;i<assets.length;i++) {
				slides += '<div class="projectportfolioitem resultgroup">';
				slides += '<div id="projectportfolioitem'+(i+1)+'">';
				var asset = assets[i];
				var type = asset.type.toLowerCase();
				if (type == 'video' || type == 'beam' || type == 'simian') {
					slides += $.SD.generateQTObject(asset.filename, 'false') + '';
				} else if (type == 'image') {
					slides += '<img src="'+ globals.urlBasePath +'/images/detail/'+ asset.filename +'" alt="Portfolio image of \''+ details.name +'\'" border="0" />';
				} else if (type == 'text') {
					slides += asset.text;
				} else {
					slides += '<div class="error notype">Did you hear the bullet? I think someone was just shot!</div>';
				}
				slides += '</div></div>';
			}
			return slides;
		},

		generateQTObject: function (filename, autoplay) {
			var height = '398';
			var width = '640';
			var qtsrc = filename;
			var autoplay = 'true';
			var qtobject = '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"; width="'+width+'" height="'+height+'">'
				+ '<param name="src" value="/sample.mov"><param name="qtsrc" value="'+qtsrc+'"> <param name="autoplay" value="'+autoplay+'"> <param name="loop" value="false"> <param name="controller" value="true">'
				+ '<embed src="'+qtsrc+'" width="'+width+'" height="'+height+'" scale="ratio" autoplay="'+autoplay+'" pluginspage="http://www.apple.com/quicktime/download/" name="Quicktime Plugin" /></object> ';
			return qtobject;
		},
  		
  		// update the data attribute of the SWF in page for pager etc
  		updateEmbedSWF : function(details) {
			var assets = details.content;
			for(var i=0;i<assets.length;i++) {
				var asset = assets[i];
				var type = asset.type.toLowerCase();
				if (type == 'video' || $type == 'beam') {
					var flashvars = {
						hostServer: "www.beam.tv",
						container: "beamreel",
						container_id: "",
						filepwd: asset.beamID,
						width: "640",
						height: "360"
					};
					var params = {
						allowFullScreen: "true",
						quality: "high",
						wmode: "transparent",
						allowScriptAccess: "always",
  						bgcolor: "#000000"
					};
					var attributes = {
						name: "projectportfolioitem"+(i+1)+"",
						id: "projectportfolioitem"+(i+1)+""
					};
			    	swfobject.embedSWF(globals.urlVideoPlayer + "?ts=1234", "projectportfolioitem"+(i+1)+"", "680", "438", "9.0.0", false, flashvars, params, attributes); 

					var autostart = function () {
						$.SD.embedToggleState("projectportfolioitem1", "play");
					}

			    	if (i == 0) {
			    		setTimeout(autostart, 5000); 
			    	}
				}
				if ($type == 'simian') {
					var flashvars = {
						hostServer: asset.filename,
						width: "640",
						height: "360"
					};
					var params = {
						allowFullScreen: "true",
						quality: "high",
						wmode: "transparent",
						allowScriptAccess: "always",
  						bgcolor: "#000000"
					};
					var attributes = {
						name: "projectportfolioitem"+(i+1)+"",
						id: "projectportfolioitem"+(i+1)+""
					};
			    	swfobject.embedSWF(globals.urlVideoPlayer + "?ts=1234", "projectportfolioitem"+(i+1)+"", "680", "438", "9.0.0", false, flashvars, params, attributes); 

					var autostart = function () {
						$.SD.embedToggleState("projectportfolioitem1", "play");
					}

			    	if (i == 0) {
			    		setTimeout(autostart, 5000); 
			    	}					
				}
			}
  		},

		// toggle the embed to stop start and play, pause the shizzle
		embedToggleState : function (objectID, state) {
			$('object').each(function () {
				var stopObj = swfobject.getObjectById($(this).attr('id'));
				if (stopObj && stopObj.pause) {
					stopObj.pause();
				}
			});
			if ($('object#'+objectID).size() == 1) {
				var obj = swfobject.getObjectById(objectID);
				if (obj) {
					switch (state) {
						case 'play':
							obj.play();
						break;
						case 'pause':
							obj.pause();
						break;
						default:
							obj.stop();
						break;
					}
				}
			}
		},




	//// FAQ

  		// ajax in the content to the project page
  		updateQuestion : function(question) {
  			//set sections to loading
  			//$.SD.loadPage('hidetop');
  			//post the request
  			$.ajax({
				type: "GET",
				url: question.href,
				data:  { format: "json" },
				dataType: "json",
				success: function (data) {
					//split out the JSON objects accordingly
					var faq = data.selectedFaq;
					var next = data.nextPrevFaq.next;
					var prev = data.nextPrevFaq.previous;
					//load the content
					$.SD.loadFAQContent(faq, next, prev);
					//change the pages
			  		$.SD.setNextPrevious('next', next);
	  				$.SD.setNextPrevious('previous', prev);
				},
				failure: function () {
					//$.SD.loadPage('showtop');
				}, 
				complete: function () {
					setTimeout(function () {
						$(question).removeClass().addClass('active')
					},2000);
				}
			});
			
  		},
  		
  		// take the project details and insert into page
  		loadFAQContent : function(faq, next, prev) {

	  		//set the page doc title
	  		var split = document.title.split(' : ');
			document.title = split[0]+' : '+ split[1] +' : ' + faq.section +' : ' + faq.title  ;

  			//fade out the text

 			$('#faqitem').fadeOut(1000, function () {

				//hide these items having faded them out
				$(this).hide();
  			
				// assign the data into an array
				var details = {
					thisFaq: faq,
					nextFaq: next,
					prevFaq: prev
				};

				//load up image, map or whatever
  				$.SD.loadWorkContent(faq.assetType, details);


  				//update section details
  				$("h1#question").text(faq.title);
  				$("div#response").html(faq.text);
  			
				//check to see if attribution is null
  				if (faq.attribution != null) {
		  			$("p#attribution").text(faq.attribution);
		  		} else {
			  		$("p#attribution").text('');
		  		}
 				
				$(this).show();
  			
  			}).fadeIn();
  			// fade out the trail, inject the new section and then fade the item back in.
			$('#trail a#selectedFAQSection').fadeOut(function () {
				$(this).html(faq.section);
			}).fadeIn();

  		},
  		
  		loadGoogle: function () {

			if (typeof GMap2 == 'function') {

				$("#faqvisual #map").addClass('loaded');

				// Create our "tiny" marker icon
				var tinyIcon = new GIcon(G_DEFAULT_ICON);
				tinyIcon.image = globals.urlImagesPath +"/pages/faq/SDPIN.png";
				tinyIcon.shadow = globals.urlImagesPath +"/pages/faq/SDPINSHADOW.png";
				tinyIcon.iconSize = new GSize(39, 57);
				tinyIcon.shadowSize = new GSize(44, 31);
				tinyIcon.iconAnchor = new GPoint(15, 55); 


				//draw the map in the correct place
				var map = new GMap2(document.getElementById("map"), { size: new GSize(377, 261)});
				var point = new GLatLng(51.523898,-0.109677);

				map.setCenter(point, 15);
				map.addOverlay(new GMarker(new GLatLng(51.523898,-0.109677), {icon: tinyIcon}));

				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				
			}
	
  		},
  		
  		// update the work asset content asset
  		loadWorkContent : function(asset, details) {
			$('#faqvisual').removeClass().addClass(asset.strtolower);
  			switch (asset) {
  				case 'Image' :

					//hide the map
					$('#faqvisual #map').hide();

					// find the current image and remove item
		  			$("#faqImage").remove();
		  			
		  			//predefine variables
		  			var filenamePrefix = globals.urlImagesPath +'/faq/';

					//next faq details
					var thisFile = filenamePrefix + details.thisFaq.filename;
					var thisAlt = details.thisFaq.alt;

					//next faq details
					var nextFile = filenamePrefix + details.nextFaq.filename;
					var nextAlt = details.nextFaq.alt;

					//previous faq details
					var prevFile = filenamePrefix + details.prevFaq.filename;
					var prevAlt = details.prevFaq.alt; 

					//switcharoo - swap the images
					if (nextFile == $("#previousFaqImage").attr('src')) {
						$("#nextFaqImage").attr({ id : "faqImage" });
					} else if (prevFile == $("#previousFaqImage").attr('src')) {
						$("#previousFaqImage").attr({ id : "faqImage" });
					} else {
						$('#faqvisual').prepend('<img id="faqImage" class="faqImages" src="'+thisFile+'" alt="'+thisAlt+'" width="377" height="261" border="0" />');
					}
					$("#nextFaqImage, #previousFaqImage").remove();
					$('#faqvisual').prepend('<img id="nextFaqImage" class="faqImages" src="'+nextFile+'" alt="'+nextAlt+'" width="377" height="261" border="0" />');
					$('#faqvisual').prepend('<img id="previousFaqImage" class="faqImages" src="'+prevFile+'" alt="'+prevAlt+'" width="377" height="261" border="0" />');
					$("#faqImage").addClass('current');
					$('#faqvisual #faqImage').show();

  				break;
  				case 'Video' :
	  			break;	
  				case 'Text' :
	  			break;	
  				case 'Map' :
					loadScript();
					$('#faqvisual #faqImage').hide();
					$('#faqvisual #map').show();
					$.SD.loadGoogle();
	  			break;		
  			} 			
  		},


	//// NEXT PREVIOUS BUTTONS 

  		// turn page content into loading status bar
  		setNextPrevious : function(type, link) {

  			//asign this link item to var
			var item = '#pager a#' + type;
			
			//change the link text
			$(item + ' .question').html(link.title);

			//if there is an image
			if ($(item + ' > img').size() > 0) {

				//change the title and url for the link item
				$(item).attr({
					href: '/work/' + link.url,
					title: type + ' Project: ' + link.alt
				});

				//change the title and url for the link item
				$(item + ' > img').attr({
					src: globals.urlImagesPath +'/thumbnails/' + link.filename,
					alt: link.alt
				});
				
				//change project title text
				$(item + ' span.text').html(link.alt);

  			} else {

				//change the title and url for the link item
				$('#pager a#' + type).attr({
					href: '/faq/' + link.section + '/' + link.url + '',
					title: type + ' FAQ: ' + link.title
				});

  			}

  		},


	//// AJAX 

  		// turn page content into loading status bar
  		loadPage : function(action) {
  			if (action == 'show') {
	  			$(".loader").hide();
	  			$("#page .row > div").show().fadeIn();
	  		} else if (action == 'hide') {
	  			$("#page .row > div").fadeOut().hide();	  			
	  		} else if (action == 'showtop') {
	  			$(".loader").hide();
	  			$("#page .row:first-child > div").show();
	  		} else if (action == 'hidetop') {
	  			$("#page .row:first-child > div").hide();		  			
	  		} else if (action == 'loading') {
				$(".loader").fadeIn();
	  		}
	  		if (action == 'showtop' || action == 'show') {
		  		$("#loader").remove();
		  	}
	  		if (action == 'hidetop' || action == 'hide') {
		  		$("#page .row:first-child").append('<div id="loader" class"content-bgd"></div>');
		  	}
  		},
  		
  		// sets the address bar to the supplied URL
  		writeURL : function(url) {
  			//window.top.location.href = url;
  			//return false;
  		},


	//// RESULTS PAGER 

		//get the number of page links on paginator
		paginatorGetNumPages: function () {
			return $(".paginate li.page").size();
		},

  		// turn page content into loading status bar
  		paginatorLeafPages : function(eventItem) {
  				var recordSetNum = globals.resultSetNum;
  				var recordGroup = globals.searchResGroup;
				$(eventItem).siblings().removeClass('selected');
				if ($(eventItem).hasClass('page')) {
					recordGroup = $(eventItem).attr('id').replace('p','');
					$(eventItem).addClass('selected');
				} else {
					if ($(eventItem).attr('id') == 'next') {
						if (recordGroup < $.SD.paginatorGetNumPages()) {
							recordGroup++;
						} else {
							return true;
						}
					} else if ($(eventItem).attr('id') == 'previous') {
						if (recordGroup > 1) {
							recordGroup--;
						} else {
							return true;
						}
					}
					$(eventItem).siblings('#p'+recordGroup).addClass('selected');
				}
				var rowCounter = 0;
				var start = ((recordGroup-1)*recordSetNum);
				$.SD.resultSetStart = start;
				var end = (start+recordSetNum);
				
				var ajaxURL = window.top.location.href + '';
				if (records[recordGroup] != null) {
					$.SD.renderResults(records[recordGroup]);
				} else {
					//post the request
					$.ajax({
						type: "GET",
						url:  ajaxURL + '/page:' + recordGroup + '/itemsPerPage:' + recordSetNum,
						data:  { format: "json" },
						dataType: "json",
						success: function (data) {
							records[recordGroup] = data;
							$.SD.renderResults(data);
						},
						failure: function () {
						}, 
						error: function () {
						}, 
						complete: function () {
						}
					});
				}

				$('#resultsetStart').text(start+1);
				$('#resultsetEnd').text(end);

				$(".searchresultitem").each(function () {
				rowCounter++;

				globals.searchResGroup = recordGroup;
			});			
  		}, 
  		
  		renderResults: function (data) {
  			if (data.workResults != null) {
	  			$.SD.renderResultItem('work',data.workResults);
  			} else if (data.faqResults != null) {
  				$.SD.renderResultItem('faq',data.faqResults);
  			} else if (data.blogResults != null) {
  				$.SD.renderResultItem('blog',data.blogResults);
  			}
  			
  		},
  		
  		renderResultItem: function (type,results) {
			var resList = $('ul.searchresults');
			$(resList).empty();
			var rowCounter = $.SD.resultSetStart;
			$.each(results, function () {
				var item = this;

				//set URL
	  			switch (type) {
		  			case 'work':
		  				var itemURL = '/work/'+item.url;
		  			break;
		  			case 'faq':
		  				var itemURL = '/faq/'+ item.section +'/'+item.url;
  					break;
		  			case 'blog':
		  				var itemURL = item.post_url;
  					break;
  				}

				$(resList).append('<li id="result'+ rowCounter+'" class="searchresultitem '+ type +'"></li>');
				var currentResItem = $(resList).find('#result'+rowCounter);
				$(currentResItem).append('<a href="'+ itemURL +'" title="Search Result for \''+item.title+'\'"><div class="resitemsurround"></div></a>');
				var resItemContent = $(currentResItem).find('.resitemsurround');
				$(resItemContent).append('<div class="rowcount">'+ (rowCounter+1) +'<span class="slice">&#47;</span></div>');
	  			switch (type) {
		  			case 'work':
						$(resItemContent)
							.append('<div class="type">'+item.workType+'</div>')
							.append('<div class="resultthumb"></div>');
						if (item.thumbnail != null) {
							$(resItemContent)
								.find('.resultthumb')
								.append('<img src="'+globals.urlImagesPath+'/thumbnails/'+item.thumbnail+'" alt="Thumbnail for \''+item.title+'\'" border="0" />');
						}
		  			break;
		  			case 'faq':
						$(resItemContent).append('<div class="type">'+item.section+'</div>');
  					break;
		  			case 'blog':
						$(resItemContent).append('<div class="type">Blog</div>');
  					break;
  				}
  				$(resItemContent).append('<div class="info"><div class="title">'+item.title+'</div>'+item.text+'</div>');
				rowCounter++;
  			});
  		}


	};



///////////////////////////////////////////////////////
// UNLOAD

	$(document.body).unload(function() {

		if ($("#faq").size() == 1) {
			if (GBrowserIsCompatible()) {
				GUnload();
			}
		}

	});


///////////////////////////////////////////////////////
// MISC FUNCTIONS

    function loadScript() {
		var script = document.createElement("script");
   		script.type = "text/javascript";
		script.src = "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAASnX1OnLl3HcCx4XNXE0dshTvQBgHvzTlyUXpwqqRcKI_HgWnQxTW9KaurXzt1osVsDIJUfQtXI5sWQ&async=2&callback=loadGMap";
		document.body.appendChild(script);
	}

	function loadGMap() {
		$.SD.loadGoogle();
	}

