var $j = jQuery.noConflict();

$j(function(){
	// Accessibility
	$j('#respond').hide();

	// Push menu up when scrolling down the page
	$j(window).scroll(function(){ 
		if($j(window).scrollTop() <= 100){
			if ($j("#outerheader").css('top') != 0) $j("#outerheader").animate({top: 0}, 0);	
		}
		else
		{
			if ($j("#outerheader").css('top') != -47) $j("#outerheader").animate({top: -47}, 0); 
		}	
	});
	
	// Bring menu down when hovering over a logo in the header
	$j("#logo").mouseover(function() {
    	$j("#outerheader").animate({top: 0}, 200, function() {});
  	}).mouseout(function(){
    	//$j("#outerheader").animate({top: -47}, 200, function() {});
  	});
	
	// Back to top link
	$j(".backtotop").click(function() {
		$j.scrollTo('#wrapper',800);
		return false;
    });
	
	// Slideshow for divisional pages
	$j('#rotator').cycle({
		fx: 'scrollLeft',
		pause: true,
		timeout: 5000,
		pager: '#slideshownav'
	});
	
	// Menu Animations
	var $el, leftPos, newWidth, $mainNav2 = $j("#menu"), $mainNav3 = $j("#submenu ul.show"); 

    $mainNav2.append("<li id='magic-line2'></li>");
	$mainNav3.append("<li id='magic-line3'></li>");
    
	var $magicLineTwo = $j("#magic-line2"),$magicLineThree = $j("#magic-line3");
    var $clr = $j("#menu .current a").attr("rel");
	
    $magicLineTwo
        .width($j("#menu li.current").width())
        .height($mainNav2.height())
        .css("left", $j("#menu .current a").position().left)
        .data("origLeft", $j("#menu .current a").position().left)
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", $j("#menu .current a").attr("rel"));
       
	$magicLineThree
        .width($j("#submenu ul.show li.current").width())
        .css("left", $j("#submenu ul.show .current a").position().left)
        .data("origLeft", $j("#submenu ul.show .current a").position().left)
        .data("origWidth", $magicLineThree.width());
                   
    $j("#menu li").find("a").hover(function() {
        $el = $j(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        $magicLineTwo.stop().animate({
            left: leftPos,
            width: newWidth
        }
		);
		$el.css('color',$clr);
    }, function() {
        $magicLineTwo.stop().animate({
            left: $magicLineTwo.data("origLeft"),
            width: $magicLineTwo.data("origWidth"),
            Color: $magicLineTwo.data("origColor")
        });   
		$el.css('color','white'); 
    });
	
	$j("#submenu ul.show li").find("a").hover(function() {
		$el = $j(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        $magicLineThree.stop().animate({
            left: leftPos,
            width: newWidth
        }
		);
    }, function() {
        $magicLineThree.stop().animate({
            left: $magicLineThree.data("origLeft"),
            width: $magicLineThree.data("origWidth")
        });   
    });
	        
    $j("#individualproject li").hover(function() {
       	$j(this).find('span').show();
    },
	function() {
			$j(this).find('span').hide();
	}
	);
	
	// Scroll down page when user wants to comment
	$j('#postinfo .comments').click(
		function(){
			$j.scrollTo('#comments',750);	
		}
	);
	
	// Open up comments box
	$j(".comment-reply-link,a.reply").click(
		function (event) {
			event.preventDefault();
			$j('#respond').toggle('fast');
			$j(this).hide();
	});
	
	// Close down comments box
	$j("#cancel-comment-reply-link").click(
		function (event) {
			event.preventDefault();
			$j('#respond').toggle('fast');
			$j(this).hide();
			$j('.comment-reply-link,.reply').show();
	});
	
	//console.log(document.referrer.toLowerCase());
});



