// JavaScript Document
$(document).ready(function() {

$.localScroll({
	duration: 700,
	easing: 'easeInOutExpo'
	//hash: true
});



/****************************** 
 * Home page slideshow        *
 *                            *
 ******************************
/                            */
	$('#prev').click(function() {
		clearTimeout($slideshowTimer);
		prevImage();
		$slideshowTimer = setTimeout ( "autoplay()", 4000 );
	});
	$('#next').click(function() {
		clearTimeout($slideshowTimer);
		nextImage();
		$slideshowTimer = setTimeout ( "autoplay()", 4000 );
	});
	
	$("#featured-nav-holder a").removeAttr("href");
	$("#featured-nav-holder a").click(function () { 
		clearTimeout($slideshowTimer);
		$slideshowTimer = setTimeout ( "autoplay()", 4000 );

		if (currentImage != $(this).attr('rel')){
			loadImage($(this).attr('rel'));
		}
    });
	$('#photo-button').mouseenter(function() {
		$('#photo-button-layer').stop(true, true).fadeIn();
	});
	$('#photo-button').mouseleave(function() {
		$('#photo-button-layer').stop(true, true).fadeOut();
	});
	$('#work-filters a').click(filterClicked);

	
/****************************** 
 * Project page               *
 *                            *
 ******************************
/                            */
	
	$('#list-btn').mouseenter(function() {
		$('#scroll-list').stop().animate({
			opacity: 1,
			marginRight: '0',
		}, 250);
	});
	
	$('#scrollbar').mouseleave(function() {
		$('#scroll-list').stop().animate({
			opacity: 1,
			marginRight: '-150',
			easing: 'easeOutExpo'
		}, 250);
	});
	
	$('#scroll-list a').mouseenter( function(){
		$(this).addClass('highscroll');
		//Cufon.replace('#scroll-list a', { fontFamily: 'ConduitITCStd Black', hover:{color: '#333'}});
	});
	$('#scroll-list a').mouseleave( function(){
		$(this).removeClass('highscroll');
		//Cufon.replace('#scroll-list a', { fontFamily: 'ConduitITCStd Black', hover:{color: '#333'}});
	});
	
	

}); //$(document).ready(function() {

function autoplay(){
	$slideshowTimer = setTimeout ( "autoplay()", 4000 );
	nextImage();
}


function filterClicked(e){
	var $ref	= $(e.target);
	if(!$ref.data('filter')) $ref = $ref.parent();
	if(!$ref.hasClass('active')){
		$('#work-filters .active').removeClass('active');
		
		if(!$ref.hasClass('active')){
			$ref.addClass('active');
			var $filter = $($ref).data('filter');
			//$('#work-thumbnails').animate({opacity:0},400,"linear",filterBy($filter));
			//$('#work-thumbnails').fadeOut(400,"linear",filterBy($filter));
			 $('#work-thumbnails').fadeOut(300,function() {
				// Animation complete.
				filterBy($filter)
			  });
		}else{
			$ref.removeClass('active');
		}
	}
}

/*function filterBy($filter){
	var $projectItems = $('.project-item');
	$projectItems.stop()
	if($filter == 'all'){
		$projectItems.show(300);
	}else{
		for(i=0; i < $projectItems.length; i++){
			if($($projectItems[i]).data('services')){
				var services = $($projectItems[i]).data('services');
				if(services.indexOf($filter) > -1){
					$($projectItems[i]).show(300);
				}else{
					$($projectItems[i]).hide(300);
				}
			}else{
				$($projectItems[i]).hide(300);
			}
		}
	}
}*/

function filterBy($filter){
	var $projectItems = $('.project-item');
	$projectItems.css('display','none');
	$('#work-thumbnails').fadeIn(0);
	if($filter == 'all'){
		itemNumber = 0;
		for(i=0; i < $projectItems.length; i++){
			$($projectItems[i]).delay((itemNumber*100)).fadeIn(300);
			itemNumber++;
		}
	}else{
		itemNumber = 0;
		for(i=0; i < $projectItems.length; i++){
			if($($projectItems[i]).data('services')){
				var services = $($projectItems[i]).data('services');
				if(services.indexOf($filter) > -1){
					//$($projectItems[i]).css('display','block');
					$($projectItems[i]).delay((itemNumber*100)).fadeIn(300);
					itemNumber++;
				}else{
					$($projectItems[i]).css('display','none');
				}
			}else{
				$($projectItems[i]).css('display','none');
			}
		}
	}
}

/****************************** 
 * Project page               *
 *                            *
 ******************************
/                            */
function scrollto($target){
	if($target == 'next'){
		if(current_service+1 >= services.length){
			scrollto(0);
		}else{
			scrollto(current_service+1);
		}
	} else if($target == 'previous'){
		if(current_service <= 0){
			scrollto(services.length-1);
		}else{
			scrollto(current_service-=1);
		}
	} else {
		$('html').stop();
		$.scrollTo( '#'+services[$target], 700, {easing:'easeInOutExpo'} );

		$('#scroll-list a').removeClass('curscroll');
		$('#service_'+$target).addClass('curscroll');
		//Cufon.replace('#scroll-list a', { fontFamily: 'ConduitITCStd Black', hover:{color: '#333'}});

		current_service = $target;
	}
}

/****************************** 
 * Login Box                  *
 *                            *
 ******************************
/                            */

   function slideDownLogin(){
		$("#client_login").animate({top: 0}, 300, "easeInOutQuad");
		$("#client_open").fadeOut('fast');
   }
   function slideUpLogin(){
		$("#client_login").animate({top: -129}, 300, "easeInOutQuad", function(){
			$("#client_open").fadeIn('fast');
		});
   }

/****************************** 
 * Home page slideshow        *
 *                            *
 ******************************
/                            */
	function loadImage (image) {
		// Change button highlight
		$('#featured-nav-holder .selected').removeClass('selected');
		$('#photo-btn-'+image).addClass('selected');
		
		// Hide image and video and add loading class
		$('#photo-holder').fadeIn();
		//$('#photo1').addClass('loading');
		//$('#photo1').html('');
		//alert(parseFloat(image)+1);
		
		// Replace the project name
		$("#featured-name").html(photos[image][1]);
		//Cufon.replace('h2', { fontFamily: 'ConduitITCStd Black' });
		
		//Replace the image link
		//$("#featured-name").html(photos[image][2]);
		if($("#photo-button").length > -1) $("#photo-button").attr("href", photos[image][2])
		
		// Load the image here
		var img = new Image();
		$(img).load(function () {
			$theimage = this;
			$('#photo1').hide();
			$('#photo1').html(this);
			$('#photo1').fadeIn(0);
			$('#photo2').fadeOut('slow',function(){
				$('#photo2').html($theimage);
				$('#photo2').fadeIn(0);
			});
		}).error(function () {
			$('#photo1').removeClass('loading').html('Sorry! This image can not be loaded...');
			$('#photo2').fadeOut();
		}).attr('src', photos[image][0]);
		
		// set a new currentImage value
		currentImage = image;
		
		// check if the next button should be displayed
		if(currentImage == (photos.length - 1)){
			//$('#next').hide();
		}else{
			//$('#next').show();
		}
	}
	
	function nextImage() {
		if(currentImage+1 < (_photoCount)){
			currentImage++;
			loadImage(currentImage);
		}else{
			currentImage = 0;
			loadImage(currentImage);
		}
	}
	function prevImage() {	
		if(currentImage != 0){
			currentImage--;
			loadImage(currentImage);
		}else{
			currentImage = _photoCount-1;
			loadImage(currentImage);
		}
	}	
	
	
	
	
	
	
	
/***
 * Twitter JS v1.13.3
 * http://code.google.com/p/twitterjs/
 * Copyright (c) 2009 Remy Sharp / MIT License
 * $Date$
 */
 /*
  MIT (MIT-LICENSE.txt)
 */
 typeof renderTwitters!="function"&&function(){function v(a){var c;for(c in a.user)a["user_"+c]=a.user[c];a.time=s(a.created_at);return a}function w(a){t?a.call():u.push(a)}function q(){t=true;for(var a;a=u.shift();)a.call()}function x(){if(document.addEventListener&&!r.webkit)document.addEventListener("DOMContentLoaded",q,false);else if(r.msie){document.write("<script id=__ie_init defer=true src=//:><\/script>");var a=document.getElementById("__ie_init");if(a)a.onreadystatechange=function(){if(this.readyState==
 "complete"){this.parentNode.removeChild(this);q.call()}};a=null}else if(r.webkit)var c=setInterval(function(){if(document.readyState=="loaded"||document.readyState=="complete"){clearInterval(c);c=null;q.call()}},10)}function s(a){function c(d){var h=d.getHours();d=d.getMinutes()+"";var f="AM";if(h==0)h=12;else if(h==12)f="PM";else if(h>12){h-=12;f="PM"}if(d.length==1)d="0"+d;return h+":"+d+" "+f}function g(d){d.toDateString().split(/ /);var h=y[d.getMonth()],f=d.getDate()+"",i=parseInt(f);d=d.getFullYear();
 var n=(new Date).getFullYear(),l="th";if(i%10==1&&f.substr(0,1)!="1")l="st";else if(i%10==2&&f.substr(0,1)!="1")l="nd";else if(i%10==3&&f.substr(0,1)!="1")l="rd";if(f.substr(0,1)=="0")f=f.substr(1);return h+" "+f+l+(n!=d?", "+d:"")}var b=a.split(" "),e=Date.parse(b[1]+" "+b[2]+", "+b[5]+" "+b[3]);b=new Date(e);var j=arguments.length>1?arguments[1]:new Date;e=parseInt((j.getTime()-e)/1E3);var m="";e+=j.getTimezoneOffset()*60;return m=e<5?"less than 5 seconds ago":e<30?"half a minute ago":e<60?"less than a minute ago":
 e<120?"1 minute ago":e<2700?parseInt(e/60).toString()+" minutes ago":e<10800?"about 1 hour ago":e<86400?"about "+parseInt(e/3600).toString()+" hours ago":e<172800?c(b)+" yesterday":c(b)+" "+g(b)}var r=function(){var a=navigator.userAgent.toLowerCase();return{webkit:/(webkit|khtml)/.test(a),opera:/opera/.test(a),msie:/msie/.test(a)&&!/opera/.test(a),mozilla:/mozilla/.test(a)&&!/(compatible|webkit)/.test(a)}}(),o=0,u=[],t=false,y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
 window.ify=function(){return{link:function(a){return a.replace(/[a-z]+:\/\/[a-z0-9-_]+\.[a-z0-9-_:~%&\?#\/.=]+[^:\.,\)\s*$]/ig,function(c){return'<a href="'+c+'">'+(c.length>25?c.substr(0,24)+"...":c)+"</a>"})},at:function(a){return a.replace(/(^|[^\w]+)\@([a-zA-Z0-9_]{1,15}(\/[a-zA-Z0-9-_]+)*)/g,function(c,g,b){return g+'@<a href="http://twitter.com/'+b+'">'+b+"</a>"})},hash:function(a){return a.replace(/(^|[^&\w'"]+)\#([a-zA-Z0-9_]+)/g,function(c,g,b){return g+'#<a href="http://search.twitter.com/search?q=%23'+
 b+'">'+b+"</a>"})},clean:function(a){return this.hash(this.at(this.link(a)))}}}();window.renderTwitters=function(a,c){function g(k){return document.createElement(k)}function b(k){return document.createTextNode(k)}var e=document.getElementById(c.twitterTarget),j=null,m=g("ul"),d,h,f,i,n=a.length>c.count?c.count:a.length;for(i=0;i<n&&a[i];i++){j=v(a[i]);if(c.ignoreReplies&&a[i].text.substr(0,1)=="@")n++;else{d=g("li");if(c.template)d.innerHTML=c.template.replace(/%([a-z_\-\.]*)%/ig,function(k,p){k=
 j[p]+""||"";if(p=="text"&&c.enableLinks)k=ify.clean(k);return k});else{h=g("span");h.className="twitterStatus";f=g("span");f.className="twitterTime";h.innerHTML=a[i].text;if(c.enableLinks==true)h.innerHTML=ify.clean(h.innerHTML);f.innerHTML=s(a[i].created_at);if(c.prefix){var l=g("span");l.className="twitterPrefix";l.innerHTML=c.prefix.replace(/%(.*?)%/g,function(k,p){return a[i].user[p]});d.appendChild(l);d.appendChild(b(" "))}d.appendChild(h);d.appendChild(b(" "));d.appendChild(f)}if(c.newwindow)d.innerHTML=
 d.innerHTML.replace(/<a href/gi,'<a target="_blank" href');m.appendChild(d)}}if(c.clearContents)for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(m);typeof c.callback=="function"&&c.callback()};window.getTwitters=function(a,c,g,b){o++;if(typeof c=="object"){b=c;c=b.id;g=b.count}g||(g=1);if(b)b.count=g;else b={};if(!b.timeout&&typeof b.onTimeout=="function")b.timeout=10;if(typeof b.clearContents=="undefined")b.clearContents=true;if(b.withFriends)b.withFriends=false;b.twitterTarget=a;if(typeof b.enableLinks==
 "undefined")b.enableLinks=true;window["twitterCallback"+o]=function(e){b.timeout&&clearTimeout(window["twitterTimeout"+o]);renderTwitters(e,b)};w(function(e,j){return function(){if(document.getElementById(e.twitterTarget)){var m="http://www.twitter.com/statuses/"+(e.withFriends?"friends_timeline":"user_timeline")+"/"+c+".json?callback=twitterCallback"+j+"&count=20&cb="+Math.random();if(e.timeout)window["twitterTimeout"+j]=setTimeout(function(){if(e.onTimeoutCancel)window["twitterCallback"+j]=function(){};
 e.onTimeout.call(document.getElementById(e.twitterTarget))},e.timeout*1E3);var d=document.createElement("script");d.setAttribute("src",m);document.getElementsByTagName("head")[0].appendChild(d)}}}(b,o))};x()}();
 
