
Cufon.replace('.policytitle h1, .events h3, .pagetitle, .programs-sub h2, a.slider-button-demo, a.slider-button-program, #schoolheader a, #countyheader a, #policyheader a, .introcopy, ul.sf-menu li a.topnav  , #signin a, .cufon, .rmts-side a, .introcopy-landing' , {hover : true}); // Works without a selector engine
Cufon.replace('#introtext a' , {hover : true}); // Works without a selector engine
Cufon.replace('.t'); // Requires a selector engine for IE 6-7, see above

$(function() {
		
		lightboxCheck();
		initBinding();
		
		// Clone all portfolio items for Quicksand plugin
		var cache_list =$('ul.history').clone();
		
		// When clicked on a link in the portfolio menu
		$('ul.timeline-menu li a').click(function(e) {
		
		// Remove current old active class
		$('ul.timeline-menu').children('li').children('a').removeClass('active');
		
		// Set active class on clicked element
		$(this).addClass('active');
		
		// If all portfolio items have to be showed
		if($(this).attr('id') == 'all') {
			
			// Refresh Quicksand
			$('.history').quicksand( cache_list.find('li'), {
		
				  duration: 1000,
				  attribute: function(v) {
				  return $(v).find('img').attr('src');
              }

				}, function() {
				
					lightboxCheck(); // refresh lightbox script (binding)
					initBinding();
				
				});
				e.preventDefault();
		
		// If a particular catagorie has to be showed
		} else {
		
			$('.history').quicksand( cache_list.find('li.'+ $(this).attr('id') +''), {
				  duration: 500,
				  attribute: function(v) {
                return $(v).find('img').attr('src');
              }

				}, function() {
				
					lightboxCheck();
					initBinding();
				
				});
				e.preventDefault();
		}

		});
		
		function lightboxCheck() {
			
			// For each image
			$('span.img-polaroid').each(function() {
		
				// If the image has a class of 'zoom' and the previos element doesn't have a 'caption' class
				if($(this).next().attr('class') == 'zoom' && $(this).prev().attr('class') !== 'caption') {
					
					$(this).css('cursor', 'pointer')
					$(this).addClass('lightbox');
					$(this).parent().prepend('<span class="caption"></span>');
			
				}
		
			});
		
		}
	
		function initBinding() {
		
			// prettyPhoto plugin
			$("a[rel^='prettyPhoto']").prettyPhoto();
			
			$('span.img-polaroid').hover(function() {
			
				if($(this).prev().css('opacity') == '0') {
				
					$(this).prev().fadeTo('500', '0.6');
					
				}
		
			}, function() {
			
				$(this).prev().fadeTo('500', '0');
			
			});
			
			$('span.img-polaroid').click(function() {
				
				// When clicked on the span tag before the 'a' element, click on the anchor tag
				if($(this).next().attr('class') == 'zoom') {
				
					$(this).next().click();
				
				}

			});
			
		}
		
		$('div.slider').sliders({
	
			cycle : true, // true or false
			slideWidth : 980, // width per slide
			cycleInterval : 5000 // pause in milleseconds between animation
		
		});
	
		$('div.portfolio-slider').sliders({
	
			cycle : true, // true or false
			cycleInterval : 2000, // pause in milleseconds between animation
			arrowNavigationWrapper : 'div.portfolio-slider', // wrapper class
			slideWidth : 310, // width per slide
			projectSlider : true, // true or false
			sliderdots : false // true or false
		
		});
		
		// Get the position of the contact form
		var position = $('#contact').position(); 
		
		// When clicked on 'add comment' or 'reply' button
		$('a.add-comment').click(function(e) {
			
			// Don't go to the top
			e.preventDefault();
			
			// Animate screen to top of the contact form
			$('html, body').animate({scrollTop: position.top}, 300);
		
		});
		
		$('div.sidebar > div').each(function() {
		
			$(this).append('<span class="default-icon"></span>');
		
		});
		
			
});

$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h3.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});

});


//Drop down javascript

$(document).ready(function() {

	/* drop down for search */
	
	$("#drop").click(function() {
		if ($("#search_arrow").html("&#9660;")) {
			$("#search_arrow").html("&#9650;");
		} else {
			$("#search_arrow").html("&#9660;");
		}		
		$("#search_options").toggle();	
	});
	
	$("#search_options li").click(function() {
		$(".radio").removeClass("radio_selected");	
		$(".radio", this).addClass("radio_selected");
	});
	
	
	/* drop down for sort_options */
	
	$("#sort_drop").click(function() {
		if ($("#sort_arrow").html()) {
			$("#sort_arrow").html();
		} else {
			$("#sort_arrow").html();
		}
		$("#sort_options").toggle();	
	});
	
	$("#sort_options li").click(function() {
		$(".radio").removeClass("radio_selected");	
		$(".radio", this).addClass("radio_selected");	
	});
	
	
	
});


// List and Grid View

$(document).ready(function() {
													 
  $("#issue-wrapper").removeClass("list-view").addClass("grid-view");

  $("#grid_select").click(function() {
		$(".active").removeClass("active");
		$(this).addClass("active");
		$("#issue-wrapper").removeClass("list-view").addClass("grid-view");
	});

  $("#list_select").click(function() {
		$(".active").removeClass("active");
		$(this).addClass("active");
		$("#issue-wrapper").removeClass("grid-view").addClass("list-view");
	});

});

function charLimitAtWordBoundary( str, num ) {

   if (str == null) str = "";
   origchars = str.length;

   str = str.substr(0,num);
   str = str.substr(0,str.lastIndexOf(" "));

   if (str.length != origchars) str = str + "...";

   return str;

}

// Highlight current section

$(document).ready(function() {

  var urlparts = location.href.split("/");
  var section = urlparts[3];
  if (section == "phs") section = urlparts[4];
  $("ul.sf-menu li."+urlparts[3]).addClass("current");

  currentpage = urlparts[urlparts.length-1].replace(".","-");
  if (currentpage == "events-and-professional-development") $("body").removeClass();
  $("body").addClass(currentpage);
  
  if (currentpage == "issue-analysis") {
	$('#content-core .item .description').each( function() {	
		desc = $(this).html();
		$(this).html( charLimitAtWordBoundary( desc, 130 ) );
	});  
  }

});

