eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('a.4.D({M:d(c,3,4,b,k){g 7.u(d(){a.h.v(7,c,3,4,b,k)})},N:d(c,3,4){g 7.u(d(){a.h.v(7,c,3,4,1)})},O:d(3,4){g 7.u(d(){a.h.m(7,3,4)})}});a.D({h:{E:1,j:{},F:/^([0-9]+)\\s*(.*s)?$/,G:{\'P\':1,\'Q\':10,\'R\':S,\'s\':T,\'U\':V,\'W\':X,\'Y\':Z},H:d(n){5(n==11||n==q)g q;e r=7.F.12(a.13(n.14()));5(r[2]){e I=15(r[1],10);e J=7.G[r[2]]||1;g I*J}w{g n}},v:d(8,c,3,4,b,k){e x=0;5(a.16(3)){5(!b)b=4;4=3;3=c}c=a.h.H(c);5(17 c!=\'18\'||19(c)||c<=0)g;5(b&&b.1a!=1b){k=!!b;b=0}b=b||0;k=k||y;5(!8.$6)8.$6={};5(!8.$6[3])8.$6[3]={};4.$f=4.$f||7.E++;e z=d(){5(k&&7.A)g;7.A=1c;5((++x>b&&b!==0)||4.1d(8,x)===y)a.h.m(8,3,4);7.A=y};z.$f=4.$f;5(!8.$6[3][4.$f])8.$6[3][4.$f]=t.1e(z,c);5(!7.j[3])7.j[3]=[];7.j[3].1f(8)},m:d(8,3,4){e 6=8.$6,l;5(6){5(!3){o(3 p 6)7.m(8,3,4)}w 5(6[3]){5(4){5(4.$f){t.K(6[3][4.$f]);B 6[3][4.$f]}}w{o(e 4 p 6[3]){t.K(6[3][4]);B 6[3][4]}}o(l p 6[3])L;5(!l){l=q;B 6[3]}}o(l p 6)L;5(!l)8.$6=q}}}});5(a.1g.1h)a(t).1i("1j",d(){e j=a.h.j;o(e 3 p j){e C=j[3],i=C.1k;1l(--i)a.h.m(C[i],3)}});',62,84,'|||label|fn|if|timers|this|element||jQuery|times|interval|function|var|timerID|return|timer||global|belay|ret|remove|value|for|in|null|result||window|each|add|else|counter|false|handler|inProgress|delete|els|extend|guid|regex|powers|timeParse|num|mult|clearInterval|break|everyTime|oneTime|stopTime|ms|cs|ds|100|1000|das|10000|hs|100000|ks|1000000||undefined|exec|trim|toString|parseInt|isFunction|typeof|number|isNaN|constructor|Number|true|call|setInterval|push|browser|msie|one|unload|length|while'.split('|'),0,{}))

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

$.fn.getIndex = function(){ var $p=$(this).parent().children(); return $p.index(this); }
$.easing.easeInOutCubic = function (x, t, b, c, d) { return c*(t/=d)*t*t + b; }

var activeBall = 0; 
var ballCount = 0; 
var ballClicked = false;

$(function(){

  $.scrollTo( 0 );
  $(".totop").click(function(){	
  $.scrollTo( $('#pagewrap'), 500, {margin:true, easing: 'easeInOutCubic'});
  return false;
  });

  $("a.fancybutton").fancybox({
		'overlayShow'			: true,
		'overlayOpacity'		: 0.4,
		'overlayColor'			: '#000',
		'autoScale'				: false,
		'changeFade'            : 0,
		'titleShow'             : false,
		'margin'				: 20,
		'padding'				: 20,
		'transitionIn'			: 'none',
		'transitionOut'			: 'none',
		'hideOnContentClick'	: false,
		'width'					: 'auto',
		'height'				: 'auto',
		'autoDimensions'		: false,
		'scrolling'				: 'no'
		});

  activeBall = 0;
  ballCount = $(".portfolioitem").size() - 1;
  $(".portfoliowindow").stop().scrollTo($('.portfolioitem:eq(0)'), 0);
  
  $(".portfolioitem").each(function(i){
  		if(i == 0){ $(".balls").append("<li><a href='#' class='ball active'>Ball</a></li>"); }
  		else { 		$(".balls").append("<li><a href='#' class='ball'>Ball</a></li>"); 	     }
  		if(i == ballCount){ createTimer(); }
  });
   
  $(".balls > *").click(function(){
  		$('.portfoliowindow').stopTime('controlled');
  		activeBall = $(this).getIndex();
  		$(".balls .active").removeClass("active");
  		$(".balls a:eq("+activeBall+")").addClass("active");
  		$(".portfoliowindow").stop().scrollTo($('.portfolioitem:eq('+activeBall+')'), 500);
  		ballClicked = true;
  		return false;
  });
  
  function createTimer(){
			$('.portfoliowindow').everyTime(7000, 'controlled', function() {
				if(activeBall != ballCount) activeBall = activeBall+1; else activeBall = 0;
				$(".portfoliowindow").stop(true).scrollTo($('.portfolioitem:eq('+activeBall+')'), 500);
				$(".balls li > a").filter(".active").removeClass("active");
				$(".balls li > a").eq(activeBall).addClass("active");
			});
	}
  
  var twitterinitshow = 0;
  var twitterscroll = 4;
  
  $("#newscolumnleft .newspost").each(function(i){
  	if(i > twitterinitshow) $(this).find("p").toggle();
  	if(i > twitterscroll) $(this).hide();
  	$(this).find("h2").bind('click', function() { $(this).siblings("p").toggle(); return false; });
  });
  $("#newscolumnright .newspost").each(function(i){
  	if(i > twitterinitshow) $(this).find("p").toggle();
  	if(i > twitterscroll) $(this).hide();
  	$(this).find("h2").bind('click', function() { $(this).siblings("p").toggle(); return false; });
  });
  $(".morenews").click(function(){
  	var firstHiddenIndex = $(".newspost:hidden").filter(":first").getIndex()-1;
  	var twitterShowScope = firstHiddenIndex + twitterscroll;
  	$("#newscolumnleft .newspost").slice(firstHiddenIndex, twitterShowScope).fadeIn("fast");
  	$("#newscolumnright .newspost").slice(firstHiddenIndex, twitterShowScope).fadeIn("fast");
	$.scrollTo( $('.morenews'), 700, {margin:true, easing: 'easeInOutCubic'});
	if($('.newspost:last').is(':visible')) $(this).hide();
	return false;
  });

});
