	/*#### Course div open/close ####*/
	
	function newSlide(element) {
	
		heading = 'unit_heading_' + element;
		content = 'unit_text_' + element;
		link = 'link_' + element;
		
		if(document.getElementById(content).style.display == 'inline') {
			
			document.getElementById(content).style.display = 'none';
			document.getElementById(link).innerHTML = '[Click here to continue reading]'; 
			
		} else {
			
			if(document.getElementById('content_divs')) {
				
				the_divs = document.getElementById('content_divs').innerHTML;
				the_divs = the_divs.split(',');
				
				for (var div in the_divs) {
					
					div_pieces = the_divs[div].split('_');
					div_ref = div_pieces[2];
					
					heading_closer = 'unit_heading_' + div_ref;
					content_closer = 'unit_text_' + div_ref;

					if(document.getElementById(heading_closer)) {

						document.getElementById(content_closer).style.display = 'none';
						document.getElementById(link).innerHTML = '[Click here to continue reading]'; 

					}
					
				}
				
			}
			
			document.getElementById(content).style.display = 'inline';
			document.getElementById(link).innerHTML = '[Click here to minimize]'; 
			
		}
	}


	//## TAB SWITCHING FUNCTION ##// 
	function tabSwitch(active, number, tab_prefix, content_prefix) {

		for (var i=1; i < number+1; i++) {
		  document.getElementById(content_prefix+i).style.display = 'none';
		  document.getElementById(tab_prefix+i).className = '';
		}
		document.getElementById(content_prefix+active).style.display = 'block';
		document.getElementById(tab_prefix+active).className = 'active';	

	}
		

	// IMAGE ROTATING TRANSITION EFFECT //
	
	function theRotator() {
		//Set the opacity of all images to 0
		$('div.rotator ul li').css({opacity: 0.0});
		
		//Get the first image and display it (gets set to full opacity)
		$('div.rotator ul li:first').css({opacity: 1.0});
			
		//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
		setInterval('rotate()',6000);
	}

	function rotate() {	
		//Get the first image
		var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

		//if ( current.length == 0 ) current = $('div.rotator ul li:first');

		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
		
		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);

		//Hide the current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
		
	};

	$(document).ready(function() {		
		//Load the slideshow
		theRotator();
	});	
	
	
	function theCustomRotator() {
		//Set the opacity of all images to 0
		$('div.custom_rotator ul li').css({opacity: 0.0});
		
		//Get the first image and display it (gets set to full opacity)
		$('div.custom_rotator ul li:first').css({opacity: 1.0});
			
		//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
		setInterval('customRotate()',6000);
	}

	function customRotate() {	
		//Get the first image
		var current = ($('div.custom_rotator ul li.show')?  $('div.custom_rotator ul li.show') : $('div.custom_rotator ul li:first'));

		//if ( current.length == 0 ) current = $('div.rotator ul li:first');

		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.custom_rotator ul li:first') :current.next()) : $('div.custom_rotator ul li:first'));
		
		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);

		//Hide the current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
		
	};

	$(document).ready(function() {		
		//Load the slideshow
		theCustomRotator();
	});
	

	// WATERMARK IN THE SEARCH BOX //
	
	(function($) {
		var map=new Array();
		$.Watermark = {
			ShowAll:function(){
				for (var i=0;i<map.length;i++){
					if(map[i].obj.val()==""){
						map[i].obj.val(map[i].text);					
						map[i].obj.css("color",map[i].WatermarkColor);
					}else{
						map[i].obj.css("color",map[i].DefaultColor);
					}
				}
			},
			HideAll:function(){
				for (var i=0;i<map.length;i++){
					if(map[i].obj.val()==map[i].text)
						map[i].obj.val("");					
				}
			}
		}
		
		$.fn.Watermark = function(text,color) {
			if(!color)
				color="#aaa";
			return this.each(
				function(){		
					var input=$(this);
					var defaultColor=input.css("color");
					map[map.length]={text:text,obj:input,DefaultColor:defaultColor,WatermarkColor:color};
					function clearMessage(){
						if(input.val()==text)
							input.val("");
						input.css("color",defaultColor);
					}

					function insertMessage(){
						if(input.val().length==0 || input.val()==text){
							input.val(text);
							input.css("color",color);	
						}else
							input.css("color",defaultColor);				
					}

					input.focus(clearMessage);
					input.blur(insertMessage);								
					input.change(insertMessage);
					
					insertMessage();
				}
			);
		};
	})(jQuery);
	
	
	// BANNER SLIDER - HOME PAGE //
	
		/*#### IMAGE BANNER SLIDER ####*/
	function bannerSlider(){
	//Configuration

		var retour = true;
		var transitionDelay = 1000;
		var displayPlayPause = true;
		var autoStart = true;
		var autoDelay = 9000;

		var icons = new Array();
			icons['play'] = '/custom_home/play_slider.png';
			icons['pause'] = '/custom_home/pause_slider.png';	

		var currentPosition = 0;
		var slideWidth = 838;
		var slides = $('.slide');
		var numberOfSlides = slides.length;
		var interval;
		var lectureEnCours = false;

		// Remove scrollbar in JS
		$('#slidesContainer').css('overflow', 'hidden');

		// Wrap all .slides with #slideInner div
		slides
			.wrapAll('<div id="slideInner"></div>')
			// Float left to display horizontally, readjust .slides width
			.css({
			'float' : 'left',
			'width' : slideWidth
		});

		// Set #slideInner width equal to total width of all slides
		$('#slideInner').css('width', slideWidth * numberOfSlides);

		// Insert controls in the DOM
		$('#slideshow')
			.prepend('<div class="custom_control" id="leftControl"><div class="arrow_icon_left">Left</div></div>')
			.append('<div class="custom_control" id="rightControl"><div class="arrow_icon_right">Right</div></div>');

		// Hide left arrow control on first load
		manageControls(currentPosition);

		// Create event listeners for .controls clicks
		$('.custom_control')
			
		.bind('click', function(){

			// Determine new position
			currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;

			if(currentPosition == numberOfSlides && retour == false ){
				
				currentPosition--;
				pause();
				
			}

			// Hide / show controls
			manageControls(currentPosition);
			
			// Move slideInner using margin-left
			$('#slideInner').animate({
				'marginLeft' : slideWidth*(-currentPosition)
			},transitionDelay);
			
			// custm to clear interval on the click then reset interval back to defined
			clearInterval(interval);
			interval = setInterval(next, autoDelay );
			
		});

		
		// manageControls: Hides and Shows controls depending on currentPosition
		function manageControls(position){
			// Hide left arrow if position is first slide
			if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
				
			// Hide right arrow if position is last slide
			if(position==numberOfSlides-1 && retour == true){
			
				$('#rightControl').hide();
				
			} else {
			
				$('#rightControl').show();
				
			}
			
			if(position == numberOfSlides && retour == true){
				currentPosition = 0;
				$('#leftControl').hide();
			}

		}
		
		
		function next(){
		
			$('#rightControl').click();
		
		}
		
		function start() {
		
			lectureEnCours = true;
			interval = setInterval(next, autoDelay );
			
		}
		
		function pause() {
		
			lectureEnCours = false;
			clearInterval(interval);
		
		}

		//Auto Scroll Function
		if(autoStart == true){
		start();
		}
		
		if(displayPlayPause == true){
		
			//$('#slidesContainer').prepend('<div class="auto_start"><img id="navSlide" src="" alt="Play Pause Slider" /></div>');
			
			if(autoStart == true){
			
				$('#navSlide').attr('src',icons['pause']);
			
			}else{
			
				$('#nav').attr('src',icons['play']);	
			
			}
			
			$('#navSlide').bind('click', function(){
			
				if(lectureEnCours == true){
				
				$(this).attr('src',icons['play']);
					
					pause();
				
				}else{
				
					$(this).attr('src',icons['pause']);
					start();
				
				}
			
			});
		
		}

	};
