// JavaScript Document

jQuery(document).ready(function() { 
		
	/**
	 * Main navigation
	 */
	jQuery("div#navigation-primary li").each( function() {
											   
		var link = jQuery(this).find('a');
		
		// If this is the home page
		if (location.pathname == '/' && link.attr('href') == '/') {
			jQuery("div#navigation-primary li").removeClass("on");
			jQuery(this).addClass("on");
			
		// Check to see if this is a top level nav item
		} else if ((location.pathname.indexOf(link.attr('href')) > -1) && link.attr('href') != '/') {
			jQuery("div#navigation-primary li").removeClass("on");
			jQuery(this).addClass("on");
			
		// Is this a sub page (We're using the Breadcrumbs to work this out - is there a better way?)
		} else {
			/*jQuery("div#breadcrumbs a").each( function() {							
				if ((link.attr('href').indexOf(jQuery(this).attr('href')) > -1) && jQuery(this).attr('href') != '/') {
					jQuery("div#navigation li a").removeClass("on");
					link.addClass("on");
				}
			});*/
		}
	});
	
	// Add a 'last' class to the end of the navigation list
	jQuery('div#navigation-primary li').last().addClass('last');
	
	// Add a 'first' class to the start of the breadcrumbs list
	jQuery('div#breadcrumbs li').first().addClass('first');
	
	/**
	 * Home page twitter & news carousels
	 */
	jQuery("#twitter_carousel").jCarouselLite({
	    visible: 1,
		auto: 8000,
	    start: 0,
		speed: 600,
		btnNext: ".twitter_carousel_next",
        btnPrev: ".twitter_carousel_prev",
		vertical: false,
		circular: true
	});
	
	jQuery("#news_carousel").jCarouselLite({
	    visible: 1,
		auto: 8000,
	    start: 0,
		speed: 600,
		btnNext: ".news_carousel_next",
        btnPrev: ".news_carousel_prev",
		vertical: false,
		circular: true
	});
	
	/**
	 * Profile page linkedin recommendation carousel
	 */
	jQuery("#linkedin_carousel").jCarouselLite({
	    visible: 1,
		auto: false,
	    start: 0,
		speed: 600,
		btnNext: ".linkedin_carousel_next",
        btnPrev: ".linkedin_carousel_prev",
		vertical: false,
		circular: true
	});
	
	
	/**
	 * Form validation
	 */
	jQuery("#register_with_us_form").validate({
		rules: {
			email: "required",
			confirm_email: {
		      equalTo: "#email"
			}
		}
	});
	jQuery("#feedback_form").validate({
		rules: {
			email: "required",
			confirm_email: {
		      equalTo: "#email"
			}
		}
	});	
	
	
//	jQuery("#home_tabs").tabs();
});
