/*
$(document).scroll(function(e){ 
  el = $('#menu'); 
  if ($(this).scrollTop() > 1200 && el.css('position') != 'fixed'){ 
    $(el).css({'position': 'fixed', 'top': '80px'}).stop(true,true).animate({opacity: .7}); 
  } 
  if ($(this).scrollTop() < 1200 && el.css('position') != 'absolute'){ 
    $(el).css({'position': 'absolute', 'top': '1280px'}).stop(true,true).animate({opacity: 1}); 
  } 
});
$(document).scroll(function(e){ 
  el = $('#menulogo'); 
  if ($(this).scrollTop() > 1200 && el.css('position') != 'fixed'){ 
    $(el).css({'position': 'fixed', 'top': '35px'}).stop(true,true).animate({opacity: .7}); 
  } 
  if ($(this).scrollTop() < 1200 && el.css('position') != 'absolute'){ 
    $(el).css({'position': 'absolute', 'top': '1235px'}).stop(true,true).animate({opacity: 1}); 
  } 
});
$(document).scroll(function(e){ 
  el = $('.blinder'); 
  if ($(this).scrollTop() > 1200 && el.css('position') != 'fixed'){ 
    $(el).css({'position': 'fixed', 'top': '0px'})
  } 
  if ($(this).scrollTop() < 1200 && el.css('position') != 'absolute'){ 
    $(el).css({'position': 'absolute', 'top': '1200px'}); 
  } 
});

$(document).scroll(function(e) {
    var sw = $('.menuhoverright'),
        pg = $('#projectsgridwrapper'),
        diff = pg[0].offsetTop - window.pageYOffset + 1205;

	if(diff < 200) { sw.stop(true,true).animate({opacity: 1}).addClass('activegrid'); }
	else { sw.stop(true,true).animate({opacity: 0}).removeClass('activegrid'); }

});

*/




$(document).ready(function(){
	
$('.infoleft ul li a').click(function() {
var li_index = $(this).parents('.infoleft ul').children('li').index($(this).parent('li'));

    $(this).closest('.project')
        .find('.gallery li')
        .fadeOut();
    $(this).closest('.project')
        .find('.gallery li:eq('+li_index+')')
        .fadeIn();
});


var activeOpacity   = 1.0,
    inactiveOpacity = 0.3,
    fadeTime = 100,
    clickedClass = 'selected',
    $thumbs = $('.infoleft ul li');

$thumbs.not(':first-child')
    .fadeTo(1, inactiveOpacity)
    .end()
    .filter(':first-child')
    .addClass(clickedClass);

    $thumbs.hover(
      function(){ $(this).fadeTo(fadeTime, activeOpacity); },
      function(){
        if(!$(this).hasClass(clickedClass)) {
            $(this).fadeTo(fadeTime, inactiveOpacity);
        }
    });

    $thumbs.click(function() {
     var clicked = $(this), previous;
     if (!clicked.hasClass(clickedClass)) {
         previous = clicked.closest('ul').find('.' + clickedClass);
         previous.removeClass(clickedClass).fadeTo(fadeTime, inactiveOpacity);
         clicked.addClass(clickedClass).fadeTo(fadeTime, activeOpacity);
     }
});
$('ul.gallery li').click(function() {
    var nextLi = $(this).fadeOut().next().fadeIn();

    if (nextLi.length === 0)
        nextLi = $(this).siblings(':first-child').fadeIn();
       
    var nextThumb = nextLi.closest('.project')
    .find('.infoleft li:eq(' + nextLi.index() + ')');

    nextThumb.addClass(clickedClass).fadeTo(1, activeOpacity)
        .siblings()
        .fadeTo(1, inactiveOpacity)
        .removeClass(clickedClass);
});
$('.gallerynext').click(function() {
	var nextLi = $(this).siblings('.gallery').find('li:visible:first').fadeOut().next().fadeIn();

    if (nextLi.length === 0)
        nextLi = $(this).siblings('.gallery').children(':first-child').fadeIn();
       
    var nextThumb = nextLi.closest('.project')
    .find('.infoleft li:eq(' + nextLi.index() + ')');

    nextThumb.addClass(clickedClass).fadeTo(1, activeOpacity)
        .siblings()
        .fadeTo(1, inactiveOpacity)
        .removeClass(clickedClass);
});
$('.galleryprev').click(function() {
	var prevLi = $(this).siblings('.gallery').find('li:visible:first').fadeOut().prev().fadeIn();

    if (prevLi.length === 0)
        prevLi = $(this).siblings('.gallery').children(':last-child').fadeIn();
       
    var prevThumb = prevLi.closest('.project')
    .find('.infoleft li:eq(' + prevLi.index() + ')');

    prevThumb.addClass(clickedClass).fadeTo(1, activeOpacity)
        .siblings()
        .fadeTo(1, inactiveOpacity)
        .removeClass(clickedClass);
});
$('.gallery li,.gallerynext').hover(function() {
  $('.caption', this).stop(true, true).fadeIn();
  $('.gallerynext').css('background-position','-21px 0').stop(true,true).animate({opacity: 1}, 400);
}, function() {
  $('.caption', this).fadeOut();
  $('.gallerynext').css('background-position','0').stop(true,true).animate({opacity: .6}, 400);;
});
$('.galleryprev').hover(function() {
  $('.galleryprev').css('background-position','-21px 0').stop(true,true).animate({opacity: 1}, 400);
}, function() {
  $('.galleryprev').css('background-position','0').stop(true,true).animate({opacity: .6}, 400);;
});
$('.next,.prev').hover(function() {
  $(this).css('background-position','-45px 0').stop(true,true).animate({opacity: 1}, 400);
}, function() {
  $(this).css('background-position','0').stop(true,true).animate({opacity: .6}, 400);;
});


$('.next').click(function() {
	if ($('.current').parent().next().length == 0) {
		window.location.hash = $('.current').parent().parent().children(':last').children('a:first').attr('href');
	} else {
		window.location.hash = $('.current').parent().next().children('a:first').attr('href');
		$('.'+window.location.hash.substring(1)).animate({opacity: 0},0).delay(200).animate({opacity: 1},1000);
		$('#projectswrapper').animate({height: $('.'+window.location.hash.substring(1)).height() + 50});
	}
})
$('.prev').click(function() {
	if ($('.current').parent().prev().length == 0) {
		window.location.hash = $('.current').parent().parent().children(':first').children('a:first').attr('href');
	} else {
		window.location.hash = $('.current').parent().prev().children('a:first').attr('href');
		$('.'+window.location.hash.substring(1)).animate({opacity: 0},0).delay(200).animate({opacity: 1},1000);
		$('#projectswrapper').animate({height: $('.'+window.location.hash.substring(1)).height() + 50});
	}
})

$('#projectsgrid ul li a').hover(function() {
	$(this).stop(true,true).animate({opacity: 1, backgroundColor: '#31152b'});
},
	function() {
	$(this).stop(true,true).animate({opacity: .6, backgroundColor: '#733349'});
})
$('.contact li').hover(function() {
	$(this).stop(true,true).animate({backgroundColor: '#31152b'});
},
	function() {
	$(this).stop(true,true).animate({backgroundColor: '#733349'});
})

$('.splashinformation').click(function() {
	$('#projectswrapper').animate({opacity:0}, 800, function() {
		$(this).css('height','0');
		});
	$('#splashwrapper').slideUp(800);
	$('#contentwrapper').show();
	$('#information').fadeIn(800);
	$('.information').siblings('div').addClass('activegrid');
	$('.information').siblings('div').stop(true,true).animate({opacity:0},0).animate({opacity: 1},600);
	$(document).scrollTo('0', 1000, {easing:'easeInOutCubic'} );
	window.location.hash = 'enjoyslongwalksonthebeach';
});
$('.splashselectedwork').click(function() {
	$('#information').hide();
	$('#projectswrapper').css('height','0');
	$('#splashwrapper').slideUp(800);
	$('#contentwrapper').show();
	setTimeout(function(){ $(document).stop(true,true).scrollTo(140, 500, {easing:'easeInOutCubic', axis:'y'} ),800});
});
$('.logo').click(function() {
	$('#splashwrapper').slideDown(800);
	$('#contentwrapper').fadeOut(800);
	$('#information').fadeOut(800);
	$('.information').siblings('div').stop(true,true).animate({opacity: 0}).removeClass('activegrid')
	setTimeout(function(){ $(document).stop(true,true).scrollTo(0, 500, {easing:'easeInOutCubic', axis:'y'} ),800});
});

$('#menu a').hover(function() {
	if($(this).siblings('div').hasClass('activegrid')) { return false; }
	else {$(this).siblings('div').stop(true,true).animate({opacity:0},0).animate({opacity: 1},600)}},
	function() {
		if($(this).siblings('div').hasClass('activegrid')) { return false; }
		else { $(this).siblings('div').stop(true,true).animate({opacity: 0}); }
});

$('.information').click(function() {
	$('#projectswrapper').animate({opacity:0}, 800, function() {
		$(this).css('height','0');
		});
	$('#information').delay(800).fadeIn(800);
	$('.information').siblings('div').addClass('activegrid');
	$('.selectedwork').siblings('div').stop(true,true).animate({opacity: 0}).removeClass('activegrid')
	window.location.hash = 'enjoyslongwalksonthebeach'
});
$('.selectedwork').click(function() {
	$(document).stop(true,true).scrollTo('#projectsgrid', 1000, {easing:'easeInOutCubic', axis:'y', offset:-88} );
});

setTimeout(function(){
if ($('#projectswrapper').css('opacity') == 0) {
	$('.current').removeClass('current');
} else {
	if ($('.current').parent().next().length == 0) {
		$('.next').fadeOut(800);
	}
	if ($('.current').parent().prev().length == 0) {
		$('.prev').fadeOut(800)
	}
}
},800);

if (document.location.hash === "") {
	$('html, body').stop().animate({scrollTop:0}, 1000, 'easeInOutCubic');
}
else if (document.location.hash === "#enjoyslongwalksonthebeach") {
	$('#splashwrapper').slideUp(800);
	$('#contentwrapper').show();
	$('#information').fadeIn(800);
	$('.information').siblings('div').addClass('activegrid');
	$('.information').siblings('div').stop(true,true).animate({opacity:0},0).animate({opacity: 1},600);
	$(document).scrollTo('0', 1000, {easing:'easeInOutCubic'} );
}
 else {
	$('#splashwrapper').hide();
	$('#contentwrapper').fadeIn();
	$('#projectswrapper').stop().animate({opacity:1}).css('height','800px');}
	


$('.emailconvert').mailto();
$('.phonenumber').append('252.220.2252');

});



jQuery.fn.mailto = function() {
	return this.each(function(){
		var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
		$(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
	});
};


/*
	Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
	(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
(function(w){var E=w(window),u,f,F=-1,n,x,D,v,y,L,r,m=!window.XMLHttpRequest,s=[],l=document.documentElement,k={},t=new Image(),J=new Image(),H,a,g,p,I,d,G,c,A,K;w(function(){w("body").append(w([H=w('<div id="lbOverlay" />')[0],a=w('<div id="lbCenter" />')[0],G=w('<div id="lbBottomContainer" />')[0]]).css("display","none"));g=w('<div id="lbImage" />').appendTo(a).append(p=w('<div style="position: relative;" />').append([I=w('<a id="lbPrevLink" href="#" />').click(B)[0],d=w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0];c=w('<div id="lbBottom" />').appendTo(G).append([w('<a id="lbCloseLink" href="#" />').add(H).click(C)[0],A=w('<div id="lbCaption" />')[0],K=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0]});w.slimbox=function(O,N,M){u=w.extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},M);if(typeof O=="string"){O=[[O,N]];N=0}y=E.scrollTop()+(E.height()/2);L=u.initialWidth;r=u.initialHeight;w(a).css({top:Math.max(0,y-(r/2)),width:L,height:r,marginLeft:-L/2}).show();v=m||(H.currentStyle&&(H.currentStyle.position!="fixed"));if(v){H.style.position="absolute"}w(H).css("opacity",u.overlayOpacity).fadeIn(u.overlayFadeDuration);z();j(1);f=O;u.loop=u.loop&&(f.length>1);return b(N)};w.fn.slimbox=function(M,P,O){P=P||function(Q){return[Q.href,Q.title]};O=O||function(){return true};var N=this;return N.unbind("click").click(function(){var S=this,U=0,T,Q=0,R;T=w.grep(N,function(W,V){return O.call(S,W,V)});for(R=T.length;Q<R;++Q){if(T[Q]==S){U=Q}T[Q]=P(T[Q],Q)}return w.slimbox(T,U,M)})};function z(){var N=E.scrollLeft(),M=E.width();w([a,G]).css("left",N+(M/2));if(v){w(H).css({left:N,top:E.scrollTop(),width:M,height:E.height()})}}function j(M){if(M){w("object").add(m?"select":"embed").each(function(O,P){s[O]=[P,P.style.visibility];P.style.visibility="hidden"})}else{w.each(s,function(O,P){P[0].style.visibility=P[1]});s=[]}var N=M?"bind":"unbind";E[N]("scroll resize",z);w(document)[N]("keydown",o)}function o(O){var N=O.keyCode,M=w.inArray;return(M(N,u.closeKeys)>=0)?C():(M(N,u.nextKeys)>=0)?e():(M(N,u.previousKeys)>=0)?B():false}function B(){return b(x)}function e(){return b(D)}function b(M){if(M>=0){F=M;n=f[F][0];x=(F||(u.loop?f.length:0))-1;D=((F+1)%f.length)||(u.loop?0:-1);q();a.className="lbLoading";k=new Image();k.onload=i;k.src=n}return false}function i(){a.className="";w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});w(p).width(k.width);w([p,I,d]).height(k.height);w(A).html(f[F][1]||"");w(K).html((((f.length>1)&&u.counterText)||"").replace(/{x}/,F+1).replace(/{y}/,f.length));if(x>=0){t.src=f[x][0]}if(D>=0){J.src=f[D][0]}L=g.offsetWidth;r=g.offsetHeight;var M=Math.max(0,y-(r/2));if(a.offsetHeight!=r){w(a).animate({height:r,top:M},u.resizeDuration,u.resizeEasing)}if(a.offsetWidth!=L){w(a).animate({width:L,marginLeft:-L/2},u.resizeDuration,u.resizeEasing)}w(a).queue(function(){w(G).css({width:L,top:M+r,marginLeft:-L/2,visibility:"hidden",display:""});w(g).css({display:"none",visibility:"",opacity:""}).fadeIn(u.imageFadeDuration,h)})}function h(){if(x>=0){w(I).show()}if(D>=0){w(d).show()}w(c).css("marginTop",-c.offsetHeight).animate({marginTop:0},u.captionAnimationDuration);G.style.visibility=""}function q(){k.onload=null;k.src=t.src=J.src=n;w([a,g,c]).stop(true);w([I,d,g,G]).hide()}function C(){if(F>=0){q();F=x=D=-1;w(a).hide();w(H).stop().fadeOut(u.overlayFadeDuration,j)}return false}})(jQuery);

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}

(function(d){d.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(f,e){d.fx.step[e]=function(g){if(!g.colorInit){g.start=c(g.elem,e);g.end=b(g.end);g.colorInit=true}g.elem.style[e]="rgb("+[Math.max(Math.min(parseInt((g.pos*(g.end[0]-g.start[0]))+g.start[0]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[1]-g.start[1]))+g.start[1]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[2]-g.start[2]))+g.start[2]),255),0)].join(",")+")"}});function b(f){var e;if(f&&f.constructor==Array&&f.length==3){return f}if(e=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(f)){return[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]}if(e=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(f)){return[parseFloat(e[1])*2.55,parseFloat(e[2])*2.55,parseFloat(e[3])*2.55]}if(e=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(f)){return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}if(e=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(f)){return[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)]}if(e=/rgba\(0, 0, 0, 0\)/.exec(f)){return a.transparent}return a[d.trim(f).toLowerCase()]}function c(g,e){var f;do{f=d.curCSS(g,e);if(f!=""&&f!="transparent"||d.nodeName(g,"body")){break}e="backgroundColor"}while(g=g.parentNode);return b(f)}var a={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]}})(jQuery);
