/**
	To make your life easier, all the scripts that are loaded once the DOM has fully loaded have been written here.
	These scripts are linked to the Minima Theme @ ThemeForest.net by Christopher 'crozer' Honninger
**/





$(document).ready(function() { // Everything within here will be loaded as soon as the document is ready
	
	/** Image FadeIn-On-Hover effect **/
	$('img, .blogpost-comments a, .slider .comments a')
	.not('.slider img, #nivoslider img, .kwicks img, .flickr img, .gravatar img, .portfolio-content img, #comments .gravatar img, ul.contact-images img, body.crew img') /** These WON'T be affected **/
	.hover(function() {
		$(this).stop().animate({ opacity: .75 }, 200);
	}, function() {
		$(this).stop().animate({ opacity: 1 }, 200);
	});
	
	/** Image FadeOut-On-Hover effect **/
	function minimaFadeOut() {
		$('div.image-caption').css('opacity', 0);
		$('.portfolio-content img').not('body.project .project a.project-imagelink img').css('opacity', .9);
		$('.project a.project-imagelink:not(body.project .project a.project-imagelink)').hover(function() {
			$(this).find('img').stop().animate({'opacity': 1}, 200);
			$(this).find('img').prev().stop().animate({'opacity': .75}, 200);
		}, function() {
			$(this).find('img').stop().animate({'opacity': .9}, 200);
			$(this).find('img').prev().stop().animate({'opacity': 0}, 200);
		});
	}
	minimaFadeOut();
	
	/** PrettyPhoto Plugin **/
	$("a[rel^='prettyPhoto']").prettyPhoto({
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: true, /* Resize the photos bigger than viewport. true/false */
		theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	});
	$("a[rel^='prettyPhotoFull']").prettyPhoto({
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: false, /* Resize the photos bigger than viewport. true/false */
		default_width: 9000,
		default_height: 9000,
		theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	});
	
	
	/** Fake Like effects **/
	$('li.favs span').one('click', function() {
		var favEd = $(this).clone().addClass('faved');
		$(this).stop().fadeOut();
		setTimeout(function() {
			favEd.appendTo('li.favs').text('447').css('opacity', 0).animate({
				'opacity': 1
			}, 100);
		}, 400);
	});
	
 	/** QuickSand Start-up Script **/
	var $data = $(".portfolio-content").clone();
	$('.portfolio-filter li').click(function(e) {
		$(".filter li").removeClass("active");	
		var filterClass=$(this).attr('class').split(' ').slice(-1)[0];
		
		if (filterClass == 'all-projects') {
			var $filteredData = $data.find('.project');
		} else {
			var $filteredData = $data.find('.project[data-type=' + filterClass + ']');
		}
		$(".portfolio-content").quicksand($filteredData, {
			duration: 800,
			easing: 'swing'
		}, function(){ 
			$("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square' }); 
			minimaFadeOut();
			projectQuicksandFix();
		});
		$(this).addClass("active"); 			
		return false;
	});
	
	/**  =========
	All sort of fixes (things that have to be cross-browser compatible)
	=========  **/
	function projectQuicksandFix() {
		$('.two-columns div.project:nth-child(2n+2)').addClass('lastProject');
		$('.three-columns div.project:nth-child(3n+3)').addClass('lastProject');
		$('.category div.project:nth-child(3n+3)').addClass('lastProject');
		$('.four-columns div.project:nth-child(4n+4)').addClass('lastProject');

	}
	projectQuicksandFix();
	/** Widget Testimonial End Quotes **/
	$('div.testimonial h3, div.testimonial-widget h6').append('<span class="endQuotes"></span>');
		var endQuotesWidth = $('.endQuotes').width() + 3;
		$('div.testimonial-widget h6 cufon.endQuotes').css('background-position', endQuotesWidth+'px 8px');
	
	/** Blog fade-in Caption when hovering over entry image **/
	$('.blogpost .blogentry a:has(img)').hover(function() {
		$(this).next('.caption').animate({'color': '#7f7f7f'}, 400);
	}, function() {
		$(this).next('.caption').animate({'color': '#999'}, 400);
	});
	
	/** Blog entry images' styling **/
	$('.blogpost .blogentry a:not(.main-image)').find('img').css({
		'margin-top': '10px',
		'float': 'left'
	});
	
	$('div.image-list ul li:last-child').addClass('lastClient');
	$('body.faqs div.toggle-container:last-child').addClass('lastFaq');
	$('div.sidebar .widget:has(p.list-widget-description)').find('ul').css('margin', '-8px 0 0');
	$('.comments-section ul:last-child').addClass('lastBlogentryComment');
	$('div.about h3').next().addClass('firstAbout');
	$('body.blogpost .blogentry h3.title, body.blogpost .blogentry h1.title, body.blogpost .blogentry h2.title, body.blogpost .blogentry h4.title, body.blogpost .blogentry h5.title, body.blogpost .blogentry h6.title').not('.entry-title').addClass('entrycontentTitle');
	$('body.crew ul.crew-thumbs li:nth-child(3n+1)').addClass('firstCrew');
	
	/** Shortcode Boxes hover effects **/
	$('div.infobox').hover(function() {
		$(this).stop().animate({'background-color': '#ebf8ff'}, 400);
	}, function() {
		$(this).stop().animate({'background-color': '#fff'}, 400);
	});
	$('div.alertbox').hover(function() {
		$(this).stop().animate({'background-color': '#ffeeeb'}, 400);
	}, function() {
		$(this).stop().animate({'background-color': '#fff'}, 400);
	});
	$('div.notebox').hover(function() {
		$(this).stop().animate({'background-color': '#fff6cb'}, 400);
	}, function() {
		$(this).stop().animate({'background-color': '#fff'}, 400);
	});
	
	/** FAQs title/toggle effects **/
	$('body.faqs div.toggle-container').hide();
	$('body.faqs div.content h3.title a:first').stop().animate({'color': '#56a8d8'}, 400);
	$('body.faqs div.toggle-container:first').show().animate({'opacity': 1}, 800);
	
	$('body.faqs div.content h3.title a').click(function() {
		$('body.faqs div.content h3.title a').stop().animate({'color': '#777'}, 400);
		$(this).stop().animate({'color': '#56a8d8'}, 400);
		$('body.faqs div.toggle-container').stop().hide().animate({'opacity': 0}, 400);
		
		var faqContainer = $(this).attr('href');
		$(faqContainer).show().stop().animate({'opacity': 1}, 400);
		return false;
	});
	
	/** Contact Form styles **/
	$('input#submit').hover(function() {
		$(this).animate({'color': '#56a8d8'}, 200);
	}, function() {
		$(this).animate({'color': '#555'}, 200);
	});
	
	/** Placeholder cross-browser fix **/
	function supports_input_placeholder() {
		var i = document.createElement('input');
		return 'placeholder' in i;
	}
	
	if ( supports_input_placeholder() == false ) {
	
		$("input").each(function() {
			if ($(this).val() == "" && $(this).attr("placeholder") != "") {
				$(this).val($(this).attr("placeholder"));
				$(this).focus(function() {
					if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
				});
				$(this).blur(function() {
					if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
				});
			}
		});	
	}

}); // End of DOM Ready function

$(window).load(function() { // Everything within here will be loaded once the window has loaded
						
	/** Greyscale-To-Color effect **/
	$('ul.social li, div.image-list li, ul.member-social li').each(function() {
	var thumbOver = $(this).find('img').attr('src');
	var imgDimension = $(this).find('img').height() /2;
	var linkHeight = imgDimension;
	var linkWidth = $(this).find('img').width();
	$(this).find('a').css({'height' : linkHeight, 'width' : linkWidth});
		$(this).hover(function() { // on hover...
			$(this).find('a').css({'background' : 'url(' + thumbOver + ') no-repeat left -'+imgDimension+'px'})
			$(this).find('span').stop().fadeTo('normal', 0 , function() {
				$(this).hide();
			});
		}, function() { // on hover out...
			$(this).find('span').stop().fadeTo('normal', 1).show();
		});
	});
	
	/** The Crew template functionality **/
	$('.crew-thumbs > li').hover(function() {
		$(this).stop().animate({'opacity': 1}, 200);
		$(this).addClass('hovered', 200);
	}, function() {
		$(this).stop().animate({'opacity': .9}, 200);
		$(this).removeClass('hovered', 200);
	});
	
	$('div.crew-members > div').hide();
	$('ul.crew-thumbs > li:first').addClass('activated');
	$('div.crew-members > div:first').show().animate({'opacity': 1}, 800);
	
	$('.crew-thumbs > li').click(function() {
		$('ul.crew-thumbs > li').removeClass('activated');
		$(this).addClass('activated');
		$('div.crew-members > div').stop().hide().animate({'opacity': 0}, 400);
		
		var crewMember = $(this).find('a').attr('href');
		$(crewMember).show().stop().animate({'opacity': 1}, 400);
		return false;
	});
	
	/** Project Hover effect **/
	$('body.project a.project-imagelink').each(function() {
		/** Calculate a few things.. **/
		var projHalfHeight = $(this).height() /2;
		var overlayTopMargin = projHalfHeight -170;
		$(this).prepend('<span class="projectOverlay"></span>');
		$('.projectOverlay', this).css('top', overlayTopMargin+'px');
		/** Ready ;-) */
		$('body.project a.project-imagelink').hover(function() {
			$(this).find('img').stop().animate({ opacity: .35 }, 200);
			$(this).find('.projectOverlay').stop().animate({ opacity: 1 }, 200);
		}, function() {
			$(this).find('img').stop().animate({ opacity: 1 }, 200);
			$(this).find('.projectOverlay').stop().animate({ opacity: 0 }, 200);
		});
	});
						
	/** Truncate Text **/
    $('.tweet_text p').jTruncate({
        length: 200,
        minTrail: 0,
        moreText: '&hellip;'
	});
    $('.recent-posts p').jTruncate({
        length: 100,
        minTrail: 0,
        moreText: '&hellip;' 
	});	
    $('.sidebar p.comment').jTruncate({
        length: 55,
        minTrail: 0,
        moreText: '&hellip;' 
	});	
    $('.portfolio div.image-caption p').jTruncate({
        length: 10,
        minTrail: 0,
        moreText: '&hellip;' 
	});
    $('.minimaSlider p').jTruncate({
        length: 75,
        minTrail: 0,
        moreText: '[&hellip;]' 
	});	
	
	$('#nivoslider').nivoSlider({
        effect:'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 800, // Slide transition speed
        pauseTime: 6000, // How long each slide will show
        directionNav:false, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:false, // 1,2,3... navigation
		afterLoad: function(){ // Triggers when slider has loaded
			$('#nivoslider').animate({'opacity':1});
		}
    });

	$('a.nivo-imageLink').each(function() {
		$(this).prepend('<div class="nivoOverlay"></div>');
		$('div.nivoOverlay').css('opacity',0);
		
		$('div.nivoOverlay').hover(function() {
			$(this).stop().animate({'opacity': .2});
		}, function() {
			$(this).stop().animate({'opacity': 0});
		});
	});
	
	$('.kwicks').kwicks({
		max : 798,
		min: 38,
		duration: 600
	});

}); // End of Window Load function

