var $j = jQuery.noConflict();

$j(document).ready(function() {
	/*var nHeight = $('#newsContent').height();
	var sHeight = $('#sidebar').height();
	var cHeight = $('#contentSidebarContainer').height();
	
	if(nHeight < sHeight){
		$('#newsContent').css({'height' : sHeight});
	}else if(sHeight < nHeight){
		$('#sidebar').height(nHeight);
	}*/
	
	$j('.thumbsContent li:nth-child(3n+1)').css({'border-left': 'none', 'padding-left' : '0'});	
	$j('.thumbsContent li:nth-child(3n)').css({'border-right': 'none'});
	$j('.thumbsContent li:last').css({'border-right': 'none'});
	$j('#newsContent .rumourThumbs li:last').css({'margin-bottom': '0'});

}); // when document ready function ends

$j(document).ready(function() {

	$j('.searchMe').val('Search MUSC');
		//attach function to input and make text grayed out on page load
		textReplacement($j('.searchMe').css("color", "#aaa"));

	// the function:
	function textReplacement(input){ //input focus text function
 	var originalvalue = input.val();
 	input.focus( function(){
  		if( $j.trim(input.val()) == originalvalue ){ input.val('').css("color", "#444"); }
 	});
 	input.blur( function(){
  		if( $j.trim(input.val()) == '' ){ input.val(originalvalue).css("color", "#aaa"); }
 	});
}
});


//Slider
	
$j(document).ready(function() {
	
	//Set Default State of each portfolio piece
	$j(".thumbsContent").show();
	
	//first image thumbnail set to .active
	$j(".thumbsContent li:first a").addClass("active");

	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $j(".featuredImage").width();
	var imageSum = $j(".featuredImage img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Current slide
	var currSlide;
	
	//Adjust the image reel to its new size
	$j(".featuredImage").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$j(".thumbsContent li a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$j(".featuredImage").animate({
			left: -image_reelPosition
		}, 500 );
		
		//slide the thumbnail after 3rd active thumb
		if(triggerID >= 3){
			$j(".thumbsContent").animate({
				left: -810
			}, 700);
		}
		else{
			$j(".thumbsContent").animate({
				left: 0
			}, 700);
		}
		currSlide = triggerID;
	};
	
	//Rotation + Timing Event
	rotateSwitch = function(){
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			
			$active = $j('.thumbsContent li a.active').parent().next().children();
			
			//alert($active.length);
			if ( $active.length === 0) { //If paging reaches the end...
			$active = $j('.thumbsContent li:first a'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
			
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$j(".featuredImage img").hover(function() {
	clearInterval(play); //Stop the rotation
	}, function() {
	rotateSwitch(); //Resume rotation
	});
	
	//On Click
	$j(".thumbsContent a").click(function() {
		$active = $j(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});
	
	//Next/Prev click
	$j(".nextBtn a").click(function(){
		if(currSlide < 3){
			$j(".thumbsContent").animate({
				left: -810
			}, 700);
			currSlide = 4;
		}
		return false;
	})
	
	$j(".prevBtn a").click(function(){
		if(currSlide >= 3){
			$j(".thumbsContent").animate({
				left: 0
			}, 700);
			currSlide = 1;
		}
		return false;
	})
});

$j(document).ready(function() {

	//On Hover Over
	function megaHoverOver(){
	    $j(this).find(".subnav").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	  }
	//On Hover Out
	function megaHoverOut(){
	  $j(this).find(".subnav").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
	      $j(this).hide();  //after fading, hide it
	  });
	}
	
	//Set custom configurations
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 200, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	$j("#nav .subnav").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$j("#nav li").hoverIntent(config); //Trigger Hover intent with custom configurations

});
