//jump menu
function jumpMenu(id, target) {
  var selectMenu = null;  
	if (document.getElementById) {
		selectMenu = document.getElementById(id);
	}
	if (selectMenu) { 
		eval(target + ".location='" + selectMenu.options[selectMenu.selectedIndex].value + "'");
	}
}

//load functions
$(function() {
	//attach click event to the "Find" button (to choose course products)
	$("#find").click(function() {
		jumpMenu('category','parent');										
	});
	
	//make the "Find" button (to choose course products) work on key down
	$("#category").keyup(function(e) {
		if(e.keyCode == 13) {
			jumpMenu('category','parent');
		}
	});

	//ajax call to get descriptions on landing pages
	$('.expandable').click(function() {
		if ($(this).parent().attr('class') == 'hidden') {
			//get the id and remove the underscore															
			var productId = $(this).parent().attr('id');
			productId = productId.replace('id', '');
			
			//build the url for the ajax call
			var loadUrl = '/ajax/loadDescription.php?productId=' + productId; 
			
			//add the P tag, make the ajax call and load the P tag with the description
			$(this).parent().find('p').toggle().html('<img src="http://eliquo.ca/common/images/common/ajax-loader.gif" />').load(loadUrl);
			
			//add the "Learn more..." text below the description
			var learnMsg = $(this).parent().find('a').attr('title');
			var learnMsgLink = $(this).parent().find('a').attr('href');
			$(this).parent().find('p').after('<p class="learn indent"><a href="' + learnMsgLink + '">' + learnMsg + '</a></p>');
			
			//change the class
			$(this).parent().attr('class', 'visible');
			$(this).attr('title', 'Masquer la description du cours');
		} else {
			//remove the P tag and it's contents
			$(this).parent().find('p').remove();
			$(this).parent().append('<p class="indent"></p>');
			$(this).parent().find('p').toggle();
			
			//change the class
			$(this).parent().attr('class', 'hidden');
			$(this).attr('title', 'Afficher la description du cours');
		}
	});


/*	//stuff to expand/collapse the course outline
	$(".courseOutline").before('<p><a id="view-btn" class="btnRounded" href="#"><span>Cliquer pour visualiser</span></a></p><br />');  
	$('#view-btn').click(function() {
		$('.courseOutline').toggle();
		if ($('#view-btn span').text() == 'Cliquer pour visualiser') {
			$('#view-btn span').text('Cliquer purs cache');
		} else {
			$('#view-btn span').text('Cliquer pour visualiser');
		}
		return false;
	});
*/	

}); 



