$(document).ready(function() {

	//------------------------------------------------------------- GENERAL SELECTOR
	$("#cat_thumbs li:nth-child(3n)").addClass('end');
	$(".page_gallery li:nth-child(4n)").addClass('end');
	$('#menu li a:last').addClass('nav_end');
	$('#footer_nav li:last').addClass('end');
	$('#timeline li:last').addClass('timeline_end');
	
    $("span.required").hide();
    $("span.required").prev().append('<span class="required">*</span>');

	$('#cat_thumbs li a').hover(function(){
		$(this).find('img').animate({top:'-40px'},{queue:false,duration:300});	
		$(this).next('.portfolio_date').animate({opacity:1}, {queue:false,duration:300}
		);
	}, function(){
		$(this).find('img').animate({top:'0px'},{queue:false,duration:300});
		$(this).next('.portfolio_date').animate({opacity:.05}, {queue:false,duration:300});
	});

	
	//------------------------------------------------------------- INNER FADE
	$('#twitter_feed').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 8000,
		type: 'sequence',
		containerheight: '1em'
	});
	
					   
	//------------------------------------------------------------- DROP DOWN MENU
	$("ul.sub-menu").parent(); //Only shows drop down trigger when js is enabled
	$("ul#menu li a").hover(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.sub-menu").slideDown('fast').show(); //Drop down the subnav on click
	
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.sub-menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});
	
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	//------------------------------------------------------------- JQUERY INFINITE CAROUSEL
	$('#hero').infiniteCarousel({
		transitionSpeed : 500,
		displayTime: 6000,
		textholderHeight : .25,	
		displayProgressBar : 1,
		displayThumbnailBackground: 0
	});
	
	//------------------------------------------------------------- ANIMATED LOGO
	$("#logocog").frameAnimation({hoverMode:false, repeat:-1});

	//------------------------------------------------------------- HOVER FADE
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
			$span.stop().fadeTo(500, 1);
			}, function () {
			$span.stop().fadeTo(500, 0);
		});
	}); 
	
	//------------------------------------------------------------- INFIELD LABEL
	$("label").inFieldLabels();
	
	//------------------------------------------------------------- FANCYBOX MODAL POPUP
	$("a[rel=gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	//------------------------------------------------------------- NEW WINDOW
	$('a[rel="external"]').click(function(){ 
		this.target = "_blank";
	});
	
	//------------------------------------------------------------- BACK TO TOP BUTTON
	$('#back-to-top').click(function(){
		$('html, body').animate({scrollTop:0},300);return false;
	});
	
	//------------------------------------------------------------- BACK TO BOTTOM BUTTON	
	$(".nav_end").click(function(){
			$('html, body').animate({scrollTop: $(document).height()}, 'slow');
	});
});
