
;(function($) {

	$(function() {

		// open "external" links in a new window (standards compliant XHTML strict)
		$('a[rel=external]').click(function(evt) {
			window.open($(this).attr('href'));
			return false;
		});
		
		// active nav item
		$("#nav a").each(function() {
			setActiveNavItem($(this),/^nav-(.*)$/)
		});
	
		// clickable li
		$("ul.clickable_li li").each(function() {
			var link = $(this).find("a").attr("href")
	
			if ( link ) {
				$(this).addClass("pointer")
				$(this).bind('click', function(){window.location = link});
			}
		});
		
		// testimonials cycle
		$("#testimonials").each(function() {
			$(this).cycle({ 
				fx:				'fade',
				speed:		'fast', 
				timeout:	8000, 
				random:		1
			});
		});
		
		// jquery cycle image
		$("#banner-feature").each(function() {
			$(this).cycle({ 
				fx:     'scrollHorz',
				speed:  'fast',
				timeout: 14000,
				next:   '#next', 
				prev:   '#prev'
			});
		});


		
	});
	
//set the current active navigation item
//inputs - link - object we are checking
//inputs - pattern - the pattern we are checking for (e.g. /^nav-(.*)$/ id prefix followed by anything, it returns the anything
function setActiveNavItem(link,pattern) {
  if ( link.attr("id").length > 0 ) {
    if ( (link.attr("id").match(pattern) != null) ) {
      active_class = link.attr("id").match(pattern)[1]
      if ( $("body").hasClass(active_class) ) {
        link.addClass('active')
      }
    }
  }
}


})(jQuery);

