 var $jq = jQuery.noConflict();
 
 $jq(document).ready(function() { 
  //  setNavFirstLetter("#nav-main");
   // setNavFirstLetter("nav-utility");
    setSearch();  
  
   // setNav();
});

var carousel_round = 0;
function setSearch(){

    $jq('.search-button').click(function(){
        $jq('#searchform').submit();
    });
    
    
}
function setHomePanels(){
    
    
}
function setBackgroundSettings( ishome)
{
    if(ishome==true){
      
        if ($jq('#wpadminbar').length) {
            $jq('#home-slide').css({'top':'180px'});
        }
            carousel();
    }else{
        $jq('#wrap').addClass('shadow');
        $jq('#wrap').addClass('content-background');
        $jq('#logo').css({
            'margin-left':'17px'
        });
        $jq('body').css({'background-color':'#fff'});

    }
    
}
function carousel()
    {
       
        $jq(document).delegate('.carousel .next, .carousel .previous', 'click', function(event)
        {
            // prevent the default anchor action
            event.preventDefault();
		
            // get the current carousel
            var $carousel = $jq(this).parents('.carousel');
		
            // check if we're already in the middle of a movement
            if ($carousel.prop('moving'))
            {
                return true;
            }
		
            // if we actually clicked it, then stop any running timers
            if (event.clientX)
            {
                stop($carousel);
            }
		
            // localize the index, so we know where we are
            var index = $carousel.prop('index');
		
            // determine if we're going forward or backward
            var movingForward = $jq(this).hasClass('next');
		
            // grab all the slides
            var $slides = $carousel.find('.carousel-item');
		
            // grab the currently focused slide
            var $focus = $slides.eq(index);
		
            // figure out where're we going from here
            var nextObject = movingForward ? nextSlide($carousel, index) : previousSlide($carousel, index);
		
            // locaalize the next div to be shown
            var $next = nextObject.element;
		
            // localize the index of the next element to be shown
            var newIndex = nextObject.index;
		
            // determine where we should place the next element so it slides from the correct side
            var initialLeft = movingForward ? $jq(document.body).outerWidth() : -$next.outerWidth();
		
            // save the current zero position, everything will move to/from here
            var zeroPosition = $focus.offset().left;
		
            // determine where the focus is moving to
            var targetLeft = zeroPosition + (movingForward ? -$next.outerWidth() : $next.outerWidth());
		
            // we're comitted to moving now so set the flag to true so we don't duplicate animations
            $carousel.prop('moving', true);
		
            // reset all z-indexes to 1
            $slides.css('z-index', 1);
		
            // make the currently focused slide higher than all the rest
            $focus.css('z-index', 2);
		
            // setup the current slide so it can animate out
            $focus.css({
                "position": "absolute",
                "top": 0,
                "left": zeroPosition
            });
		
            // setup the next slide to slide in, moving it above the focused slide and off screen
            $next.css({
                "opacity": 0,
                "position": "absolute",
                "top": 0,
                "left": initialLeft,
                "z-index": 3
            });
		
            // animate the current slide out
            $focus.animate({
                "opacity": 0,
                "left": targetLeft
            }, 800);
		
            // set up what we're animating
            var animation = {
                "opacity": 1,
                "left": zeroPosition
            }
		
            // horrible ie fix
            if ($jq.browser.msie && parseInt($jq.browser.version) <= 8)
            {
                delete animation.opacity;
                $focus.get(0).style.removeAttribute('filter');
                $next.get(0).style.removeAttribute('filter');
            }
		
		
		
            // animate in the next slide, then upon completion reset everything. switch it back to
            // relative positioning, remove our animation flag and hide the previous element
            $next.show().animate(animation, 800, function()
            {
                $focus.hide();
                $jq(this).css({
                    "position": "relative",
                    "left": 0
                });
			
                // fix msie
                if ($jq.browser.msie && parseInt($jq.browser.version) <= 8)
                {
                    this.style.removeAttribute('filter');
                }
			
                $carousel.prop('moving', false);
            });
		
            // animate the height of our carousel, because things are abosulte the box model is shot
            $carousel.animate({
                //"min-height": $next.outerHeight()
                });
		
            // finally update our index to reflect the current view
            $carousel.prop('index', newIndex);
        });
	
        $jq(document).delegate('.carousel .pause', 'click', function(event)
        {
            // prevent the default anchor action
            event.preventDefault();
		
            // localize the carousel
            var $carousel = $jq(this).parents('.carousel');
		
            // get the current timer, if it exists
            var timer = $carousel.prop('timer');
		
            // no timer? start it
            if (!timer)
            {
                start($carousel);
            }
		
            // timer? stop it
            else
            {
                stop($carousel);
            }
        });
	
        // start a new timer, additionally update the play/pause button to the correct visual state
        function start($carousel)
        {
            timer = setInterval(function()
            {
                $carousel.find('.next').eq(0).trigger('click');
			
                //N.C.: added to stop carousel after one round.
                var index = $carousel.prop('index');
                if ( index==0 && carousel_round > 0 ) {
                    stop($carousel);
                }
                else if ( index==1 ) {
                    carousel_round++;
                }
			
            }, 6000);
		
            $carousel.prop('timer', timer);
            $carousel.find('.play.pause').removeClass('play');
        }
	
        // stop any existing timers, additionally update the play/pause button to the correct
        // visual state
        function stop($carousel)
        {
            clearInterval(timer);
		
            $carousel.prop('timer', false);
            $carousel.find('.pause').addClass('play');
		
            //N.C.: added to stop carousel after one round.
            carousel_round = 0;
        }
	
        function nextSlide($carousel, index)
        {
            var $slides = $carousel.find('.carousel-item');
		
            if (index+1 < $slides.size())
            {
                return {
                    "index":index+1, 
                    "element":$slides.eq(index+1)
                    };
            }
		
            return {
                "index":0, 
                "element":$slides.eq(0)
                };
        }
	
        function previousSlide($carousel, index)
        {
            var $slides = $carousel.find('.carousel-item');
		
            if (index-1 >= 0)
            {
                return {
                    "index":index-1, 
                    "element":$slides.eq(index-1)
                    };
            }
		
            return {
                "index":$slides.size()-1, 
                "element":$slides.eq(-1)
                };
        }
	
        // build the controls for inclusion into the page
        var $previousBtn = $jq('<a />', {
            "class": "previous", 
            "href": "#", 
            "text": "Previous"
        });
        var $playPauseBtn = $jq('<a />', {
            "class": "play pause", 
            "href": "#", 
            "text": "Play/Pause"
        });
        var $nextBtn = $jq('<a />', {
            "class": "next", 
            "href": "#", 
            "text": "Next"
        });
        var $controlsDiv = $jq('<div />', {
            "class": "carousel-controls"
        });
        $controlsDiv.append($previousBtn);
        $controlsDiv.append($playPauseBtn);
        $controlsDiv.append($nextBtn);
	
        // loop through each carousel and set some default properties/styles
        $jq('.carousel').each(function()
        {
            // localize the carousel to this function
            var $carousel = $jq(this);
		
            // set the positioning and a default height, becuase we're going to be taken out of the
            // flow once our animation starts
            $carousel.css({
                "position": "relative"
            //"min-height": $carousel.find('.carousel-item').eq(0).outerHeight() //N.C. commented out
            });
		
            // store the currently visible slide's index
            $carousel.prop('index', 0);
		
            // hide subsequent slides
            $carousel.find('.carousel-item:gt(0)').hide();
		
            // append in our controls
            $carousel.prepend($controlsDiv.clone(true));
		
            // add the previous/next images
            $carousel.find('.main-image').each(function(index)
            {
                // get the previous image
                var $prevImage = $jq(previousSlide($carousel, index).element).find('.main-image').clone();
			
                // remove the class
                $prevImage.removeClass('main-image');
			
                // create a link for the previous image
                var $previousAnchor = $jq('<a />', {
                    "href": "#",
                    "class": "prev-image",
                    "html": $prevImage
                });
                $previousAnchor.css('opacity', 0.2);
			
                // add in the previous image/anchor
                $jq(this).before($previousAnchor);
			
                // get the next image
                var $nextImage = $jq(nextSlide($carousel, index).element).find('.main-image').clone();
			
                // remove the class
                $nextImage.removeClass('main-image');
			
                // create a link for the previous image
                var $nextAnchor = $jq('<a />', {
                    "href": "#",
                    "class": "next-image",
                    "html": $nextImage
                });
                $nextAnchor.css('opacity', 0.2);
			
                // add in the next image/anchor
                $jq(this).after($nextAnchor);
            });
		
            // start the carousel by default
            start($carousel);
        });
    }
function fixSubPageTitle(){
    //fixes the  title placement for headers that go to 2 lines
    var h1_text =$jq('#page-header h1').text(); 
    h1_text_len = h1_text.length;
//  
if((h1_text_len > 20)&&(h1_text_len <25)){
    $jq('#page-header h1:first').css({"font-size":"42px"}).css({"padding":"60px 0 0 147px"});}
 else if((h1_text_len > 24)&&(h1_text_len <30)){
     $jq('#page-header h1:first').css({"font-size":"40x"}).css({"padding":"60px 0 0 30px"});}
 else if(h1_text_len > 29 &&(h1_text_len <47)){
     $jq('#page-header h1:first').css({"font-size":"36px"}).css({"padding":"60px 0 0 30px"});}
 else if(h1_text_len >46){
     $jq('#page-header h1:first').css({"font-size":"36px"}).css({"padding":"40px 0 0 30px"});}
    else{
        $jq('#page-header h1:first').css({"padding":"60px 0 0 147px"});}
    
}
function fixDivderLine(){
    //attaches the side-border class to tallest content
    var sbheight = $jq('#sidecontainer').height();
    var mheight =$jq('#maincontainer').height();     
    
    if(sbheight < mheight){
        $jq("#sidecontainer").css('height',mheight);
    }
    
}
function setNav(){
    //set target tags for off-site links in upper navigation
     $jq('#menu-donate a').attr('target', '_blank');
     $jq('#menu-new-member-professional a').attr('target', '_blank');
     $jq('#menu-new-member-student a').attr('target', '_blank');
     $jq('#menu-renew-membership a').attr('target', '_blank');
}
function goToUrl(url){
    
    window.location.href =url;
}
    

    



//$jq(document).ready(function ()
//{
//	var $filter = $jq('#filter-drop');
//	var $filterSpacer = $jq('<div />', {
//		"class": "filter-drop-spacer",
//		"height": $filter.outerHeight()
//	});
//	var $homeShield = $jq('.home .primary');
//	var $totalHeight = $jq('.carousel').outerHeight() + $jq('.header').outerHeight()
//
//
//	if ($filter.size())
//	{
//		$jq(window).scroll(function ()
//		{
//			if($jq(window).scrollTop() > $totalHeight ) {
//				
//				$homeShield.addClass("shieldfix");
//			} 
//			else if ($homeShield.hasClass('shieldfix')  && $jq(window).scrollTop() < $totalHeight)
//			{
//				$homeShield.removeClass("shieldfix");
//			}
//			
//			if (!$filter.hasClass('fix') && $jq(window).scrollTop() > $filter.offset().top)
//			{
//				$filter.css('width', $filter.width());
//				$filter.before($filterSpacer);
//				$filter.addClass("fix");
//			}
//			else if ($filter.hasClass('fix')  && $jq(window).scrollTop() < $filterSpacer.offset().top)
//			{
//				$filter.removeClass("fix");
//				$filterSpacer.remove();
//			}
//		});
//	}
//	
//});

