jQuery(function($) {


	//portfolio box slides
	if($.fn.slides) $('#box-portfolio-slides').slides({
		effect:			'fade',
		fadeEasing:		'easeInOutBack',
		fadeSpeed:		1500,
		crossfade:		true
	});


	//placeholders
	$('[placeholder]').each(function(i, el) {
		$(el).placeHolder();
	});


	// Homepage Billboard Slider
	autoplay = 0;
	if($('#slides').attr('rel')) {
		autoplay = parseInt($('#slides').attr('rel'), 10) * 1000;
	}
	
	if($.fn.slides) $('#slides').slides({
		generatePagination: true,
		generateNextPrev:	true,
		preload:			true,
		preloadImage:		'loading.gif',
		play:				autoplay,
		pause:				2500,
		hoverPause:			true,
		effect:				'fade',
		fadeEasing:			'easeInOutBack',
		fadeSpeed:			1500,
		crossfade:			true,
		animationComplete:	function() {
			var index = $('#slides .slide:visible').index();
			var visible = $('.slide-info:visible');
			$('.slide-info').eq(index).show().fadeIn();
			visible.hide();
		}
	});
	$('.slide-info:first').fadeIn();

	// CSS
	$('.flickr_badge_image:nth-child(4n+1)').addClass('last');
	$('#main .post:not(.even, .odd):last').addClass('last');
	$('#box-portfolio #box-portfolio-slides .slide a:nth-child(3n)').addClass('last');
	$('.related-projects #box-portfolio-slides .slide a:nth-child(3n)').addClass('last');
	$('.image-gallery .one_third:nth-child(3n)').addClass('last');
	$('.grid #projects .project:nth-child(3n)').addClass('last');
	$('#sidebar-home .widget:nth-child(3n+0)').addClass('last');
	$('#sidebar-footer .widget:nth-child(3n+0)').addClass('last');
	$('.sub-menu li:first a').addClass('first');
	$('.sub-menu li:last a').addClass('last');


	// Bowser Detection
	if($.browser.mozilla) $('body').addClass('is-firefox');
	if($.browser.msie) {
		$('body').addClass('is-ie');
		if($.browser.version == 7) $('body').addClass('is-ie7');
		if($.browser.version == 8) $('body').addClass('is-ie8');
		if($.browser.version == 9) $('body').addClass('is-ie9');
	};


	// Tabs
	$('.tabs').each(function(i, tabs) {
		tabs = $(tabs);
		tabs.find('a').click(function() {
			panes = $(this).parent().parent().next().next();
			$(this).addClass('btn-small').parent().siblings().find('a').removeClass('btn-small').find('span').css('background', 'none');
			panes.find('.pane').hide().eq($(this).parent().index()).fadeIn();
			return false;
		}).eq(0).trigger('click');
		
	});


	//portfolio filter
	$('.portfolio-heading').rdy(function() {
		var $list = $('#projects');
		var $data = $list.clone();

		$( window ).hashchange( function() {
			category = getParameterByName( 'category', true );
			if( category ) {
				$('.buttons a.btn-small').removeClass('btn-small');
				$('.buttons a[href="#category=' + category + '"]').addClass('btn-small');

				var filtered_data = (category == 'all') ? $data.find('.project') : $data.find('.project.' + category);
				filtered_data.removeClass('last');
				filtered_data.filter('nth-child(3n)').addClass('last');
				$list.quicksand(filtered_data, {
					duration:		250,
					adjustHeight:	false
				});
			}
		} );

		$( window ).hashchange();
	});


	//single project slides
	$('.project-slides').rdy(function() {
		$(this).slides({
			generatePagination:	true,
			effect:				'fade',
			play:				10000,
			autoHeight:			true,
			fadeEasing:			'easeInOutBack'
		});

		$(this).find('.slides-controls-thumbs a').click(function() {
			var index = $(this).index();
			$('.project-slides .pagination li:eq(' + index + ') a').trigger('click');
			return false;
		});
	});


    // Drop-Down Menus
	$("ul.nav").superfish({
		delay:			200,
		animation:		{
			opacity:	'show',
			height:		'show'
		},
		speed:			'fast',
		autoArrows:		false
	});


});


jQuery.fn.rdy = function(func) {
	this.length && func.apply(this);
	return this;
};


function getParameterByName(name, hash) {
	var url = hash ? window.location.hash.replace('#', '?') : window.location.search;
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(url);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}


jQuery.fn.placeHolder = function(default_value) {
	var el = jQuery(this);
	default_value = default_value || el.attr('placeholder');
	
	if(default_value && default_value.length) {
		el.focus(function() {
			if(el.val() == el.data('default_value')) el.val('').removeClass('empty');
		});

		el.blur(function() {
			if(!el.val().length) el.val(el.data('default_value')).addClass('empty');
		});

		el.closest('form').submit(function() {
			if(el.val() == el.data('default_value')) el.val('');
		});

		el.data('default_value', default_value).attr('title', default_value).trigger('blur');
	}
	
	return this;
};



(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

