$(document).ready(function() {
						 		   
		$("h1, h5 a").each(function() {
         var wordArray = $(this).text().split(" ");
         var finalTitle = "";
         for (i=0;i<=wordArray.length-1;i++) {
            finalTitle += wordArray[i];
            if (i == (wordArray.length-2)) {
                finalTitle += "&nbsp;";
            } else {
                finalTitle += " ";
            }
          }
          $(this).html(finalTitle);
});
						   
		$('div#progList> div').hide();  
        $('div#progList> h3').click(function() {
          $(this).next('div').slideToggle('fast')
          .siblings('div:visible').slideUp('fast');
        });
		
      $('div#progList> h3').hover(function() {
		 $(this).css({'background-image' : 'url(http://cdn.collegebound.net/myglobaleducation/images/arrow-accordian-hover.png)'});
  		}, function () {
    	var cssObj = {
      'background-image' : 'url(http://cdn.collegebound.net/myglobaleducation/images/arrow-accordian.png)' }
    $(this).css(cssObj);
      });

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});	
		} 
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul.nav li .sub").css({'opacity':'0'});
	$("ul.nav li").hoverIntent(config);
						   });

                var theInt = null;
                var $crosslink, $navthumb;
                var curclicked = 0;
                
                theInterval = function(cur){
                        clearInterval(theInt);
                        
                        if( typeof cur != 'undefined' )
                                curclicked = cur;
                        
                        $crosslink.removeClass("active-thumb");
                        $navthumb.eq(curclicked).parent().addClass("active-thumb");
                                $(".stripNav ul li a").eq(curclicked).trigger('click');
                        
                        theInt = setInterval(function() {
                                $crosslink.removeClass("active-thumb");
                                $navthumb.eq(curclicked).parent().addClass("active-thumb");
                                $(".stripNav ul li a").eq(curclicked).trigger('click');
                                curclicked++;
                                if( 6 == curclicked )
                                        curclicked = 0;
                                
                        }, 5000);
                };
                
                // DOM Ready
                $(function() {
                        
                        $("#hero").codaSlider();
                        
                        $navthumb = $(".nav-thumb");
                        $crosslink = $(".cross-link");
                        
                        $navthumb
                                .click(function() {
                                        var $this = $(this);
                                        theInterval($this.parent().attr('href').slice(1) - 1);
                                        return false;
                                });
                        
                        theInterval();
                });

