jQuery.fn.gallery = function(s,slideshow,styling) {	
		var gallery = this;
		var img = [];
		var speed = 1000; if(s) speed = parseInt(s,10);
		var ssOption = '<li><a href="#" id="playstop" title="Play/Stop SlideShow">&nbsp;</a></li>';
		var take = 0;
		if(slideshow==undefined) {
			slideShowSpeed = speed*2.5;
		} else if(slideshow) {
			slideShowSpeed = slideshow;
		} else if (!slideshow) {
			ssOption = '';
			take = 1;
		}
		var galleryStructure = '<div id="img-gallery"><img style="display:none" /><ul>'+ssOption+'</ul><div id="img-description"></div></div>';
		var started = false;
		$(gallery).each(function(i){
			$(this).hide();
			img[i] = [this.src,this.alt,$(this).attr('alt')];
			this.onload = function(){
				$(this).remove();
			}
			gallery[gallery.length-1].onload = function(){
				$(this).remove();
				start();
				started = true;
			}
			setTimeout(function(){
				if(!started) start();
			},2000)
		})
		function start(){
			
			// EDITABLE:
			$('div#WebPartWPQ1').prepend(galleryStructure); // DESTINATION OF GALLERY (YOU CAN CHANGE THIS)
			// --------
			
			$(img).each(function(i){
				$('#img-gallery ul').append('<li><a href="#img' + (i + 1) + '">' + (i + 1) + '</a></li>');
			})
			changeImage(0);
			$('#img-gallery ul a:not(#playstop)').click(function(){
				var imgToLoad = $(this).attr('href');
				imgToLoad = imgToLoad.split('#');
				imgToLoad = parseInt(imgToLoad[1].substr(3)) - 1;
				changeImage(imgToLoad);
				if(window['ssr']) $('#img-gallery ul a#playstop').click();
				return false;
			})
			$('#img-gallery ul a#playstop').toggle(function(){
				$(this).toggleClass('stop');
				startSlideShow();
				return false;
			}, function(){
				$(this).toggleClass('stop');
				stopSlideShow();
				return false;
			})
			function changeImage(n, callback){
				$('#img-gallery #img-description').fadeOut(speed / 5);
				$('#img-gallery img').fadeOut(speed / 4, function(){
					var originalWidth = $('#img-gallery img').width();
					$('#img-gallery img').attr('src', img[n][0]).attr('alt', img[n][1]);
					var width = $('#img-gallery img').width();
					var height = $('#img-gallery img').height();
					if (width == originalWidth) { fadeInAll(); } else { animate(); }
					function animate(){
						$('#img-gallery ul').fadeOut(speed / 2, function(){
							$('#img-gallery').animate({
								width: width,
								height: height
							}, speed / 2, function(){
								fadeInAll(true)
							})
						})
					}
					function fadeInAll(fromAnimate){
						var localSpeed = speed;
						if (!fromAnimate) 
							localSpeed = speed / 2;
						$('#img-gallery #img-description').html('<p>' + img[n][2] + '</p>');
						$('#img-gallery #img-description').fadeIn();
						$('#img-gallery img').fadeIn(localSpeed / 2);
						$('#img-gallery ul').fadeIn(localSpeed / 2);
						$('#img-gallery ul a:eq(' + (n + 1 - take) + ')').addClass('active');
						if (callback) callback();
						if (styling) styling();
					}
				})
				$('#img-gallery ul a').removeClass('active');
				
				if (img[n][2] == undefined) {
					$('#img-gallery #img-description').hide();
				}
				else {
					$('#img-gallery #img-description').show();
				}
			}
			function startSlideShow(){
				var imgToLoad = $('#img-gallery ul a.active:eq(0)').attr('href');
				imgToLoad = imgToLoad.split('#');
				window['ssr'] = true;
				imgToLoad = parseInt(imgToLoad[1].substr(3));
				if (imgToLoad == gallery.length) {
					imgToLoad = 0;
				}
				window['galleryTimeout'] = setTimeout(function(){
					startSlideShow()
				}, slideShowSpeed)
				changeImage(imgToLoad, function(){
					eval(galleryTimeout);
				});
			}
			function stopSlideShow(){
				window['ssr'] = false;
				clearTimeout(eval(galleryTimeout));
			}
		}
}



//tables javascript
$(document).ready(function() { 


	$('table.sortable').each(function() { 
		var $table = $(this) 
		
		$('th', $table).each(function(column) { 
			if ($(this).is('.sort-alpha')) { 
				$(this).addClass('clickable').hover(function() { 
					$(this).addClass('hover') 
				}, function() { 
					$(this).removeClass('hover') 
				}).click(function() { 
					var rows = $table.find('tbody > tr').get() 
					rows.sort(function(a, b) { 
					var keyA = $(a).children('td').eq(column).text().toUpperCase() 
					var keyB = $(b).children('td').eq(column).text().toUpperCase() 
					if (keyA < keyB) return -1 
					if (keyA > keyB) return 1 
					return 0 
				}) 
				$.each(rows, function(index, row) { 
					$table.children('tbody').append(row) 
				}) 
				$table.trigger('stripe'); 
			}) 
		} 
	}) 
	}) 
	
	
	 //add index column with all content.   
 $(".filterable tr:has(td)").each(function(){   
 	var table = ('table.filterable');
   var t = $(this).text().toLowerCase(); //all row text   
   $("<td class='indexColumn'></td>")   
    .hide().text(t).appendTo(this);   
 });//each tr   
 $("#FilterTextBox").keyup(function(){   
   var s = $(this).val().toLowerCase().split(" ");   
   //show all rows.   
   $(".filterable tr:hidden").show();   
   
   $.each(s, function(){   
       $(".filterable tr:visible .indexColumn:not(:contains('" + this + "'))").parent().hide();   
			table.trigger('stripe');
   });//each   
   
 });//key up.   
	$(".viewAll").click(function() {
		$(".filterable tr:hidden").show();

	})
	
	
	//view only filter results
  $('table.filterable').each(function() {
    var $table = $(this);
    $table.find('th').each(function (column) {
      if ($(this).is('.filter-column')) {
        var $filters = $('<div class="filters"><h4>View offices by ' + $(this).text() + ':</h4></div>');
        var keywords = {};

        $table.find('tbody tr td').filter(':nth-child(' + (column + 1) + ')').each(function() {
          keywords[$(this).text()] = $(this).text();
        });


        $('<p class="filter">View all</p>').click(function() {
          $table.find('tbody tr').show().removeClass('filtered');
         $(this).addClass('active').siblings().removeClass('active');
         $table.trigger('stripe');
        }).addClass('clickable active').appendTo($filters);

        $.each(keywords, function (index, keyword) {
          $('<p class="filter"></p>').text(keyword).bind('click', {'keyword': keyword}, function(event) {
            $table.find('tbody tr').each(function() {
              if ($('td', this).filter(':nth-child(' + (column + 1) + ')').text() == event.data['keyword']) {
                $(this).show().removeClass('filtered');
								
              }
              else if ($('th',this).length == 0) {
                $(this).hide().addClass('filtered');
								
              }
            });

           $(this).addClass('active').siblings().removeClass('active');
          	$table.trigger('stripe');
          }).addClass('clickable').appendTo($filters);

        });
        $filters.insertBefore('div.showFilterButtons');
      }
    });
  });
	  });
$(document).ready(function() { 	
	$('table.striped').each(function() {
		$(this).bind('stripe', function() {
		var rowIndex = 0
		$('tbody tr:not(.filtered)', this).each(function(index) {
			if ($('th',this).length) {
				$(this).addClass('subhead')
				rowIndex = -1
			} else {
			if (rowIndex % 2 < 1) {
				$(this).removeClass('odd').addClass('even')
			}
			else {
				$(this).removeClass('even').addClass('odd')
			}
		}
		rowIndex++
		})
	})
	$(this).trigger('stripe')
	}) 
	
});






