Cufon.replace('#sidebar h2, #logo h2,  #main-nav a,  #search h3,  #slider .slide .text b,  #slider .nav ul li a, #slider .slides-nav ul li a, .box-row h3', {
	fontFamily: 'Titillium'
});

Cufon.replace('.box h4 a,#content h2', {
	fontFamily: 'Aller'
});

$(function() {
	
	$('#main-nav ul li:last').addClass('last');

	$('.field').focus(function() {
        if(this.title==this.value) {
            this.value = '';
        }
    }).blur(function(){
        if(this.value=='') {
            this.value = this.title;
        }
    });
    
    $('.box').hover(function() {
    	$(this).addClass('box-hover');
    }, function() {
    	$(this).removeClass('box-hover');
    });
    
    $('.slides-nav a').hover(function(){
    	clearInterval();
    },function(){
    	dotimer();
    });
    
    var currentSlideID = 0;
	var slideID = 0;
	
	$('.slides-nav a').click(function(){
		
		slideID = this.id;
		slideID = slideID.split("-");
		slideID = slideID[1];
		
		moveWhere = slideID * 316;
		imgMoveWhere = slideID * 286;
		currentSlideID = slideID;
		
		$('.slides-nav a').removeClass("active");
		$(this).addClass("active");
		
		$('#slider-image').stop().animate({'top': '-'+imgMoveWhere},1100,'easeOutQuint');
		$('.text').stop().animate({'top': '-'+moveWhere},1000,'easeOutQuint');
	
	});
	
	function move_to_next(){
	
		slideID = parseInt(currentSlideID) + 1;
		if (slideID == 4) { slideID = 0; }
		moveWhere = slideID * 316;
		imgMoveWhere = slideID * 286;
		currentSlideID = slideID;
		
		$('.slides-nav a').removeClass("active");
		$('#nav-'+currentSlideID).addClass('active');
		
		$('#slider-image').stop().animate({'top': '-'+imgMoveWhere},1100,'easeOutQuint');
		$('.text').stop().animate({'top': '-'+moveWhere},1000,'easeOutQuint');
	}
	
	// START AUTO-ROTATE CODE
	var timer;
  	var donext = function (x){ move_to_next(); }
  
  	var dotimer = function (){
    	if(timer != null) {
      		clearInterval(timer);
    	}
  
    	timer = setInterval(function() {
      		donext();
    	}, 9000); // Change the time in between rotations here (in milliseconds)   
  	}
  
  	dotimer();
  	
  	$('.slider-nav-button').hover(function(){
  		clearInterval(timer);
  	},function(){
  		dotimer();
  	});
  	// END AUTO-ROTATE CODE
    
    /* Sidebar Subpages */
    $("li.sidebar_block ul li").each(function(){
	
		var childID = '';
		var grandchildrenPages = '';
		grandchildrenPages = $(this).find('ul');

		if ($(this).children('ul').size() > 0) {
			$(grandchildrenPages).hide();
			$(this).prepend('<span class="sidebar-arrow"></span>');
		}
		
		$('li.sidebar_block ul li ul li .sidebar-arrow').hide();
		$('li.current_page_item ul').show();
		$('li ul li ul li.current_page_item').parent('ul').parent('li').find('ul').show();
	
	});
	
	$("span.sidebar-arrow").click(function(){
		ulToShow = $(this).parent('li').find('ul');
		if ($(ulToShow).is(":visible")) {
			$(ulToShow).slideUp();
		} else {
			$('li.sidebar_block ul li ul').slideUp();
			$(ulToShow).slideDown('fast');
		}
	});
	/* END Sidebar Subpages */
	
	
	// Dropdown
	$('.dropdown').hide();
	
	$("a.dropdown-title").click(function(event){
		dropdownID = this.id;
		if (dropdownID == "solutions"){
			$("#industries-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
			$("#resources-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
		} else if (dropdownID == "industries"){
			$("#solutions-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
			$("#resources-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
		} else if (dropdownID == "resources"){
			$("#industries-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
			$("#solutions-dropdown").slideUp(300,"easeInOutExpo").parent().find('h4').removeClass('active');
		}
		if ($(this).parent().hasClass('active')){
			$("#"+dropdownID+"-dropdown").slideUp(300,"easeInOutExpo");
			$(this).parent().removeClass('active');
		} else {
			$("#"+dropdownID+"-dropdown").slideDown(300,"easeInOutExpo");
			$(this).parent().addClass('active');
		}
	});

})