jQuery(document).ready(function ($) {
	
	$('#coursesortselect').change(function(){
		var sort = $('#sort').val();
		var filter = $('#filter').val();
		window.location = location.pathname + '?sort=' + $(this).val() + '&filter=' + filter; 
	});
	
	$('#deliveryselect').change(function(){
		var sort = $('#sort').val();
		var filter = $('#filter').val();
		window.location = location.pathname + '?sort=' + sort + '&filter=' + $(this).val();
	});
	
	$('.registerforcourse').click(function(e){
		e.preventDefault();
		window.open($(this).attr('href'),'mywindow','width=1000,height=700,scrollbars=yes');
	});
	
	$('#promotional').jcarousel({
		auto: 5,
		scroll: 1,
		wrap: 'last'
	});

	
	function urlEncodeCharacter(c) {
		return '%' + c.charCodeAt(0).toString(16);
	}
	
	function urlDecodeCharacter(str, c) {
		return String.fromCharCode(parseInt(c, 16));
	}
	
	function urlEncode( s )	{
	      return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /[!'()*~]/g, urlEncodeCharacter );
	}
	
	function urlDecode( s )	{
	      return decodeURIComponent(s.replace( /\+/g, '%20' )).replace( /\%([0-9a-f]{2})/g, urlDecodeCharacter);
	}
	// Menu Includes
	$('ul.sf-menu').superfish({
		dropShadows:   false
	});
	
	$('#submitcoursesearch').click(function(e){
		e.preventDefault();
		$searchString = urlEncode($('#searchvalue').val());
		window.location = "/course-search-results/?q=" + $searchString;
	});
	$('#topcoursesearch').click(function(e){
		e.preventDefault();
		$searchString = urlEncode($('#topsearchvalue').val());
		window.location = "/course-search-results/?q=" + $searchString + "&type=all";
	});
	
	// Clears the inputs if necessary
	$('#searchvalue').focus(function(){
		if ($(this).val() == 'Topic or Course Title') {
			$(this).val('');
			$(this).css('color', '#000000');
		}
	});
	
	// Put the default values back if necessary
	$('#searchvalue').blur(function(){
		if ($(this).val()=='') {
			$(this).val('Topic or Course Title');	
			$(this).css('color', '#cccccc');
		}
	});
	
	$(".hoverinfo").simpletip({
		fixed: true
	});
	
	$(".hoverinfo").hover(function(){
		// Access the API of a previously initatied simpletip
		var api = $(this).simpletip();
		// Perform a simple API call to update tooltip contents
		$newContent = $(this).attr('rel');
		api.update($newContent);
	});
	
	$(".locationInfo").simpletip({
		fixed: true,
		baseClass: 'addresshover'
	});
	$(".locationInfo").hover(function(){
		// Access the API of a previously initatied simpletip
		var api = $(this).simpletip();
		// Perform a simple API call to update tooltip contents
		$newContent = $(this).attr('rel');
		api.update($newContent);
	});
  $(".courseofferings tr:odd").css("background", "#ddddff");
  $(".courseofferings tr:even").css("background", "#eeeeff");
  
  // Parse the Breadcrumb Link
  bcSize = $('.bclink > a').size();  
	if (bcSize >= 2) {
		$x = $('.bclink').html();
		$strlen = $x.length;
		if (navigator.appName == 'Microsoft Internet Explorer') {
			$('.bclink').html('<a href="/" rel="nofollow">Home</a> ' + $x.substring(53) );
		} else {
			$('.bclink').html('<a href="/" rel="nofollow">Home</a> ' + $x.substring(55) );
		}
		
		$('.bclink a:eq(1)').remove();
	}
});
