$(document).ready(function() {

    // vertically align active nav
	if ($(".current_page_item").length){
	   var activeheight = $('li.current_page_item a span').height(); 
	   if (activeheight > 20) { $('li.current_page_item a span').addClass('twolines'); }
	}

	
	if ($(".current_page_parent").length){
	    var activeheight = $('li.current_page_parent a span').height();  
	    if (activeheight > 20) { $('li.current_page_parent a span').addClass('twolines'); }
	} 
	 
	

    //Featured News
    $('#list-featurednews') 
       .after('<div id="dots">') 
       .cycle({ 
		  fx:     'fade', 
		  timeout:3000,
          pause:   0,
		  pager:  '#dots' 
     });
	 
	 
	 //set slideshow1 to rotate or not
	 var timeoutsec = 0;
	 var fxcustom = 'none';
	  if ($(".slideshow1").length){ 
        if($('.slideshow1').is('.rotate')){var timeoutsec = 4000; }
		if($('.slideshow1').is('.fade')){var fxcustom = 'fade'; }
	 }
	 
	 
	 //Featured News
    $('.slideshow1') 
       .after('<div  class="dots">') 
       .cycle({ 
		  fx:     fxcustom, 
		  timeout: timeoutsec,
          pause:   0,
		  height: 'auto',
		  pager:  '.dots' ,
		  next:   '.next1', 
          prev:   '.prev1' ,
		  before:onBefore,
		  after: onAfter
     });
	 
	 $('.slideshow2').each(function(index) {
	    var timeoutsec = 0;
	    var classname = 'slideshow2-'+index;
		var next = 'next2-'+index;
		var prev = 'prev2-'+index;
		var classname1= '.'+classname;
		
		 $(this).addClass(classname);
		 if($(this).is('.rotate')){var timeoutsec = 4000; }
         $(classname1).parent().parent().find('.next2').addClass(next); 
		 $(classname1).parent().parent().find('.prev2').addClass(prev);

		 $('.'+classname) 
        .cycle({ 
		  fx:     'none', 
		  timeout:timeoutsec,
          pause:   0,
		  height: 'auto',
		  next:   '.'+next, 
          prev:   '.'+prev,
		  before:onBefore2
       });

	 });
	 
    //center dots
	 function onAfter(curr, next, opts, fwd) { 
	     var width = (opts.slideCount*15) ;
		 var widthFinal = 317 - (width/2 );
		 var widthControls = width +60;
		 $(this).parents().find('.dots').css("left",widthFinal);
		 $(this).parents().find('.controls').css("width",widthControls);
		 //$(this).parents().find('.next1').css("right", widthControls);
     }
	 
	 //set height
	 function onBefore2(curr, next, opts, fwd) { 
	     var width = (opts.slideCount*15) ;
		$('.next').css({ 'margin-left' : width});
         var index = opts.currSlide;
         var $ht = $(this).height();
		 var $wt = ($(this).width())+8;
		 var $wtpar = ($(this).width())-70;
		 $(this).parent().parent().parent().animate({width: $wt});
         $(this).parent().animate({height: $ht});
		 $(this).parents().find('.slideshow-controls p').animate({width: $wtpar});
		 $(this).parents().find('.slideshow-controls p em').html(this.alt);
     }
	 
	 //set height
	 function onBefore(curr, next, opts, fwd) {
	    var width = (opts.slideCount*15) ;
		 $('.next').css({ 'margin-left' : width});
         var index = opts.currSlide;
         var $ht = $(this).height();
         $(this).parent().animate({height: $ht});
		 $(this).parents().find('.slideshow-controls p em').html(this.alt);
     }

	
	//Sidebar nav
	$("ul#side-nav ul li a span").not("ul#side-nav li a.selected span").hover(function() {
			  $(this).stop().animate({paddingLeft: "12px"}, 400);
	}, function() {
			  $(this).stop().animate({paddingLeft: "0px"}, 200);
	});
	
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	$('.col').hover(function(){
	    $(this).addClass('active');
		$(".col-content", this).stop().animate({top:'-160px'},{queue:false,duration:300});
	}, function() {
	    $(this).removeClass('active');
		$(".col-content", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});
	
	$('.col-2').hover(function(){
	    $(".img-content").fadeOut(700);
		$(".img-cover").fadeIn(400);
	}, function() {
		$(".img-cover").fadeOut(700);
		$(".img-content").fadeIn(400);
	});
	
	
	//Signup Lightbox
	$(".link-signup").fancybox({
				'width'				: 400,
				'height'			: 400,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	
	
	// Cufon
	Cufon.set('fontFamily', 'Myriad Pro');
	Cufon.replace('#navigation');
	Cufon.replace('#promos h2');
	Cufon.replace('#breadcrumb a');
	
	Cufon.set('fontFamily', 'Gotham Rounded Book');
	Cufon.replace('#featured h3');
	Cufon.replace('blockquote cite a');
	
	Cufon.set('fontFamily', 'Gotham Rounded Light');
	Cufon.replace('#main-content h1');
	Cufon.replace('blockquote p em');
	Cufon.replace('blockquote cite span');

});
