jQuery.noConflict();
jQuery(document).ready(function($){
    
    // if foreign link load in another window
    $('a').click(function(){
            var reg_expr = new RegExp("(http:\/\/teach.ucf.edu\/[.]*)|(mailto:[.]*)|(http:\/\/teach.cdws.testing\/[.]*)");
            if(!reg_expr.exec(this.href))
            {
                window.open(this.href);
                return false;
            }
    });
//Clears default value from input boxes on focus.
	$('input').focus(function(){
		if($(this).val() == 'Search UCF' || $(this).val() == 'Search TOL') {
			$(this).val('');
		}
	});

//Hides all drop downs by default.
	//Required to prevent IE6 from flashing drop downs when loading pages.
	$('#nav ul li ul').css({ visibility: 'visible' });
	$('#nav ul li ul').hide();
	
//Drop down behavior.	
	$('li#first').hoverIntent(showList, hideList);
	$('li#second').hoverIntent(showList, hideList);
	$('li#third').hoverIntent(showList, hideList);
	$('li#fourth').hoverIntent(showList, hideList);
    $('li#fifth').hoverIntent(showList, hideList);
	
	function showList()
	{
		$('#nav ul li ul:visible').hide();					 
		$('#nav ul li#' + $(this).attr('id') + ' ul').show();	
		$('li#' + $(this).attr('id') + ' ul:animated').stop().stop().animate({ opacity: 1}, 1);
	}
	
	function hideList()
	{
		$('li#' + $(this).attr('id') + ' ul').animate({ opacity: 1}, 800).animate({ opacity: 'hide' }, 'slow');
	}
    
    $.fn.clearForm = function() {
      return this.each(function() {
          var type = this.type, tag = this.tagName.toLowerCase();   
          if (tag == 'form')
            return $(':input',this).clearForm();
          if (type == 'text' || type == 'password')
            this.value = '';
          else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
          else if (tag == 'select')
            this.selectedIndex = -1;
          else if (tag == 'textarea')
          { 
            this.value = "";
          }
        });
      };


	
//Webcourses@UCF Course Section Request Form
	$('#option1, #option2').hide();
	$('#academic_course').click(function(){
		$('#option1').show();
		$('#option2').hide();
        $('#option2 input, #option2 select, #option2 checkbox, #option2 textarea').clearForm();
	});
	$('#academic_programs, #non_academic_courses').click(function(){
		$('#option2').show();
		$('#option1').hide();
        $('#option1 input, #option1 select, #option1 checkbox, #option1 textarea').clearForm();
	});
	
    
    //Adding multiple pieces to a form: evaluation_request_form, migration_request_form
    var current_addition = 1;
    var words = new Array("One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten");
    $("#add_course").click(function(){
            var output = next_course.replace("%%WORD%%",words[current_addition]);
            output     = output.replace(/%%NUMBER%%/g,++current_addition);
            $("fieldset#main_form").append(output);
            if(current_addition == 10) $("#add_course").hide();
            return false;
    });

});