/* ---------------------------- */

/* 
 * theanthropologist.net
 * 
 * Ian Coyle
 * www.iancoyle.com
 *
 * 
 *
 */
    
   
jQuery(
  
  function ($) {

    /* CREATE SITE */
      
    if (!$('body').hasClass('non-compliant'))
      new net.theanthropologist.Index();
      

  } 
  
);


/* ---------------------------- */

/* net.theanthropologist */


var net = 
{
  
  theanthropologist: {
  
  
    Index: function() {
    
      var $body     = $('body'),
          $wrapper  = $('div#wrapper'),
          _location = new Array(),
          _section  = 'Home',
          _segments = new Array(),
          _widescreen_offset = 24;
      
      
      
      /* ---------------------------- */

      /* INIT */
      
      
      /* INIT AJAX */
    
      $.ajaxSetup({
        cache:     false,
        dataType:  'html',
        global:    false,
        timeout:   5000
        
      });
      
      
      
      /* INIT SITE */
      
      new AdaptiveLayout();
      
      new AddressManager();
      
      new ContentManager();
      
      new Navigation();
      
      new Masthead();
      
      new SubNavigation();
      
      new Tag();
      
     // new Typewriter();
      
      new AuxNav();
      
      
      
      
      
      
      
      /* ---------------------------- */

      /* AdaptiveLayout */
      
      function AdaptiveLayout() {
      
        if ($(window).width() > 1100) {
        
            $body.addClass('wide-screen-offset');
        
        } 
        
      
      }
      
      /* ---------------------------- */

      /* AUXNAV */
      
      function AuxNav() {
      
        $('a#signup-nav').blanklink()
      
      }
      
      
      /* ---------------------------- */

      /* TAG */
      
      function Tag() {
      
        var $self = $('a#tag-anthropologie')
        
        $self.attr('target','_blank')
        
        
        $self
        .bind('mouseenter',on_mouse_enter)
        .bind('mouseleave',on_mouse_leave)
        
        
        function on_mouse_enter(e) {
        
          $self.stop().animate({right:-20},750,'easeOutBack')
        
        }
        
        function on_mouse_leave(e) {
        
          $self.stop().animate({right:-150},750,'easeOutQuart')
          
        }

      
      }//Tag
      
      
      /* ---------------------------- */

      /* MASTHEAD */
      
      function Masthead() {
      
        var $self  = $('div#masthead'),
            $nav   = $('div#nav'),
            $navs  = $('.artist'),
			$subnav = $('div#subnav');
            status = 0,
            $icon  = $('<div/>');
            
        
      
        
//        $(window).bind('mousemove',on_mouse_move) -- removed to prevent going up a lvl when rolling over masthead
        
        $icon
        .addClass('arrow-icon')
        .appendTo($self)
        .css({opacity:0,bottom:42,cursor:'pointer'})
        .bind('click',on_page_up);
        
        $body
        .bind('PAGEUP',on_page_up)
        .bind('PAGEDOWN',on_page_down)
        .bind('URI_CHANGE',on_uri_change)
        
        
        function on_uri_change(){
		  if (_location.pathNames.length == 1) {
			  $subnav.stop().animate({opacity:0},550,'easeOutQuart')
			  $self.stop().animate({height:70},550,'easeOutQuart')
		  } else {
			  $subnav.stop().animate({opacity:1},550,'easeOutQuart')
			   $self.stop().animate({height:126},550,'easeOutQuart')
		  }
		  
          if (_location.pathNames.length>=3)
            $icon.stop().animate({bottom:45,opacity:1},0,'easeOutQuart')
          else
            $icon.stop().animate({bottom:42,opacity:0},0,'easeOutQuart')
        }
        
        function on_page_up(e) {

          
          if (_location.pathNames.length>=3) {
          
            var new_path = '';
            
            for(var i=0;i<_location.pathNames.length-1;i++)
              	new_path+='/'+_location.pathNames[i]
              
            $.address.value(new_path)
                
            
          
          
          }
          
          $navs.stop().animate({opacity: 1},400,'easeOutQuart');
          
                

        
        }
        
        function on_page_down(e) {
        
          $navs.stop().animate({opacity: .4},400,'easeOutQuart');
          
        }
        
        
        function on_mouse_move(e) {
        
          var y =  e.pageY
          
          var scrl = ($body.attr('scrollTop'));
          
          if (y-scrl<125 ){
          
            if (status!=1)
              $body.triggerHandler('PAGEUP');  
            
            status = 1
            
          }else{
          
            if (status!=0)
              $body.triggerHandler('PAGEDOWN');
              
            status = 0;
            
          }
        
        }
        
      }
      
      /* ---------------------------- */

      /* NAVIGATION */
      
      function Navigation() {
      
        var $self = $('div#nav');
        
        $self.find('ul#navigation li').each(function(){new NavItem($(this))})
        
        function NavItem($self){
        
          var $a  = $self.find('a'),
              $address = $a.attr('rel'),
              $id = $a.attr('rev');
              
              
          
          $body
          .bind('URI_CHANGE',on_uri_change)
          .bind('PROXY_ARTIST',on_proxy)
          
          
          $a.bind('mouseover',function(){$body.triggerHandler('ARTIST',$id)})
          
          $a.bind('mouseout',function(){$body.triggerHandler('ARTIST','')})
          
          function on_proxy(e,id) {
            
            if (id.indexOf($id)>1)
              $self.removeClass('active').addClass('active')
            else
              $self.removeClass('active');
          }
          
          
          function on_uri_change(e) {
          
            if (_location.pathNames[0].indexOf($id)>-1)
              $self.removeClass('active').addClass('active')
            else
              $self.removeClass('active');
            
              
          
          }
          
        
        }
        
      
      }//Navigation
      
      /* ---------------------------- */

      /* SUBNAV */
      
      function SubNavigation() {
      
        var $self   = $('div#subnav'),
            $h1     = $('<h1/>').appendTo($self),
            $snav   = $('<div/>').attr('id','extra-nav').appendTo($self),
            active  = '',
            id      = '';
            
        
        //$body.bind('SEGEMENT_ACTIVE',on_segment)
        
        $body
        .bind('EXTRA_NAV',on_extra_nav)
        .bind('URI_CHANGE',on_uri_change)
        
        
        
        function on_extra_nav(e,data,i){

          id = i;
          
          $snav.html($(data))
          
          $snav.find('a.address').address()
          
          $snav.find('a._blank').blanklink()
        
        }
        
        
        function on_uri_change(e) {
        
          
          
          if (_location.pathNames.length==2){
            
            if (id!=_location.pathNames[1])
              $snav.html('');
            
            $snav.stop().animate({opacity:1},750,'easeOutQuart')
            
            
          }else{
          
            $snav.stop().animate({opacity:0},750,'easeOutQuart')
            
          }
        
        }
        
        
        new SubHead();
        
        function SubHead(){
          
            $body
            .bind('SUB',on_sub)
            .bind('SUB_CAPTION',on_caption)
            
            function on_caption(e,title,typ) {
            
              switch (typ) {
                
                case "on":
                
                  $h1.html(title)
                  
                break;
                
                case "off":
                default:
                
                  $h1.html(active)
                
                break;
              
              }
            
            }
            
            
            function on_sub(e,title,typ){
            
             
              
              switch (typ) {
                
                case "on":
                
                  set_title(title)
                  
                break;
                
                case "off":
                default:
                
                  set_title(title)
                
                break;
              
              }
              
               active = title;
            
            }
                
            
            
            function set_title(t,reset) {
              if (t!=$h1.html() || reset)
              {
              
              $h1.html('');
              
				  if (_location.pathNames.length>1) {
					$h1.html(t).appendTo($self);
					
					if(_location.pathNames[0]=="About") {
						$h1.stop().css({opacity:0})
					} else {
				  
						$h1.stop().css({opacity:0}).animate({opacity:1},750,'easeInOutQuart')
					}
					
				  }
			  }
            
            }
          }
              
      }//Navigation


      /* ---------------------------- */

      /* SUBNAV */
      
      function SubNav($content) {
          
          var $self = $('div#subnav'),
              $dl = $content.find('dl')

          if ($dl.length>0)
            new SubHead($dl);
          else
            $self.html('');
            
          
          

      }
      /* ---------------------------- */

      /* TEMPLATES */
      
      var TEMPLATES = {
      
      
      
        AT_INTRO: function($self) {
        
                          
          
        
        } //AT_INTRO
        ,
        
        AT_TEXT: function($self) {
         
          var $rule = $('<div/>').addClass('rule').appendTo($self)
		 if(_location.pathNames.length == 1) {
		 	 $rule.css({top: 90})
		 }
          
          
         
        } //AT_TEXT
         
        ,
		
		AT_HOME_GRID: function($self) {
		 var $Thumbs = $self.find('.AT-HOME-GRID-THUMBS'),
              $Slides = $self.find('.AT-HOME-GRID-SLIDES'),
              $Wrapper = $self.find('.AT-HOME-GRID-WRAPPER'),
              auto_display = $self.hasClass('AUTO'),
              is_gallery   = $self.hasClass('GALLERY'),
			  showCaption  = true,
              offset       = 960,
              photos       = 0;
          
          $self.find('a.AT-HOME-GRID-THUMB').each(function(i){photos++;new AT_HOME_GRID_THUMB($self,$(this),i)})
		  $self.find('a.AT-HOME-GRID-THUMB-NOBORDER').each(function(i){showCaption=true; photos++;new AT_HOME_GRID_THUMB($self,$(this),i)})
		  
	
          
          $self.bind('SEEK',on_seek)
          
          if (is_gallery){
        
            offset = 960;
            
            $Thumbs.css({width:offset})
            
          }
		  
          
          //////////////////////////////////////////
          
          function AT_HOME_GRID_THUMB($owner,$self,$index) {
          
            var $img = $self.find('img'),
                $src = $img.attr('src').split('_thumbnails/').join(''),
                $caption = $img.attr('alt'),
                loaded = false,
                initialized = false;
            
            ///////////////////////////////
            

             
            $img.css({opacity:0})
            
            var $tmp_img = $('<img/>')
            
            $tmp_img.bind('load',on_cache)
            
            $tmp_img.attr('src',$img.attr('src'))
            
            function on_cache(e){
            
              on_continue();
            
            }

            //if (_location.pathNames.length==2) 
              //on_continue();
              
            function on_continue(e) {
            
              $img.stop().animate({padding:0},70*$index).animate({opacity:1},950,'easeInOutQuart',function(){initialized=true})
            
              loaded = true;
              
              $self.addClass('initialized')
              
            }

                        
            ///////////////////////////////
            
            $self
            .bind('mouseover',on_mouse_enter)
            .bind('mouseleave',on_mouse_leave)
            
            
            if(is_gallery)
              $self.bind('click',on_click)
            
            //.address()
			
            function on_mouse_enter(e) {
              
              if (initialized){
                
                $img.stop().animate({opacity: .60},550,'easeOutQuart')
				
				//$img.src = $img.src.replace("_off","_on");
				
				//var source = ($img.attr("src").replace("_off","_on"));
				
				//$img.attr("src", source);

                
                if (!is_gallery)
					if(!showCaption) {
						$body.triggerHandler('SUB_CAPTION',[$caption,'off'])
					} else {
                  		$body.triggerHandler('SUB_CAPTION',[$caption,'on'])
					}
                
              }
              
              
            }
            
            function on_mouse_leave(e) {
            
              if (initialized) {
              
               $img.stop().animate({opacity: 1},550,'easeOutQuart')
				
				//var source = ($img.attr("src").replace("_on","_off"));
				
				//$img.attr("src", source);
                
                if (!is_gallery)
                 $body.triggerHandler('SUB_CAPTION',[$caption,'off'])
                 
              }
            
              
            }
            
            function on_click(e) {
            
              if (is_gallery)
                $owner.triggerHandler('SEEK',[$src,$index])
              
              e.preventDefault();
            
            }
          
          
          }
          
          //////////////////////////////////////////
          
          function on_seek(e,src,i) {
            
            $Slides.html(' ' )
            
            var $detail = $('<img/>')
           
            $detail
            .bind('load',on_detail_load)
            .attr('src',src)
            
            if (is_gallery) {
            
              $(window).bind('scroll',on_scroll)
            
            }
            
            function on_scroll(e) {
              
              var currentTopOffset = document.documentElement.scrollTop || document.body.scrollTop;
              
              $Slides.css({paddingTop:currentTopOffset})
            
            }
            
                      
            function on_detail_load(e) {
             
              if(is_gallery)
                $Wrapper.stop().animate({marginLeft:-offset},1000,'easeInOutQuart',finish_seek)
              else
                $Wrapper.stop().animate({marginTop:-$self.outerHeight()},1000,'easeInOutQuart',finish_seek)
              
              $detail.css({opacity: 0,cursor:'pointer'}).appendTo($Slides).animate({opacity:1},1000,'easeInOutQuart')
            
            }
             
             
            function finish_seek() {

             $detail.bind('click',function() {$detail.animate({opacity:0},1000,'easeInOutQuart');$Wrapper.stop().animate({marginLeft:0},1000,'easeInOutQuart')})
             
            }
            
          } //on_seek
			  
		}
		,
      
        AT_GRID: function($self) {
          
          var $Thumbs = $self.find('.AT-GRID-THUMBS'),
              $Slides = $self.find('.AT-GRID-SLIDES'),
              $Wrapper = $self.find('.AT-GRID-WRAPPER'),
              auto_display = $self.hasClass('AUTO'),
              is_gallery   = $self.hasClass('GALLERY'),
              offset       = 960,
              photos       = 0;
          
          $self.find('a.AT-GRID-THUMB').each(function(i){photos++;new AT_GRID_THUMB($self,$(this),i)})
		  $self.find('a.AT-GRID-THUMB-FOUR').each(function(i){showCaption=false; photos++;new AT_GRID_THUMB($self,$(this),i)})
          
          $self.bind('SEEK',on_seek)
          
          if (is_gallery){
        
            offset = (photos<16) ? 760 : 960
            
            $Thumbs.css({width:offset})
            
          }
          
          //////////////////////////////////////////
          
          function AT_GRID_THUMB($owner,$self,$index) {
          
            var $img = $self.find('img'),
                $src = $img.attr('src').split('_thumbnails/').join(''),
                $caption = $img.attr('alt'),
                loaded = false,
                initialized = false;
            
            ///////////////////////////////
            

             
            $img.css({opacity:0})
            
            var $tmp_img = $('<img/>')
            
            $tmp_img.bind('load',on_cache)
            
            $tmp_img.attr('src',$img.attr('src'))
            
            function on_cache(e){
            
              on_continue();
            
            }

            //if (_location.pathNames.length==2) 
              //on_continue();
              
            function on_continue(e) {
            
              $img.stop().animate({padding:0},70*$index).animate({opacity:1},950,'easeInOutQuart',function(){initialized=true})
            
              loaded = true;
              
              $self.addClass('initialized')
              
            }

                        
            ///////////////////////////////
            
            $self
            .bind('mouseover',on_mouse_enter)
            .bind('mouseleave',on_mouse_leave)
            
            
            if(is_gallery)
              $self.bind('click',on_click)
            
            //.address()
            
            
            function on_mouse_enter(e) {
              
              if (initialized){
                
                $img.stop().animate({opacity: .60},550,'easeOutQuart')
                
                if (!is_gallery)
                  $body.triggerHandler('SUB_CAPTION',[$caption,'on'])
                
              }
              
              
            }
            
            function on_mouse_leave(e) {
            
              if (initialized) {
              
                $img.stop().animate({opacity: 1},550,'easeOutQuart')
                
                if (!is_gallery)
                  $body.triggerHandler('SUB_CAPTION',[$caption,'off'])
                 
              }
            
              
            }
            
            function on_click(e) {
            
              if (is_gallery)
                $owner.triggerHandler('SEEK',[$src,$index])
              
              e.preventDefault();
            
            }
          
          
          }
          
          //////////////////////////////////////////
          
          function on_seek(e,src,i) {
            
            $Slides.html(' ' )
            
            var $detail = $('<img/>')
           
            $detail
            .bind('load',on_detail_load)
            .attr('src',src)
            
            if (is_gallery) {
            
              $(window).bind('scroll',on_scroll)
            
            }
            
            function on_scroll(e) {
              
              var currentTopOffset = document.documentElement.scrollTop || document.body.scrollTop;
              
              $Slides.css({paddingTop:currentTopOffset})
            
            }
            
                      
            function on_detail_load(e) {
             
              if(is_gallery)
                $Wrapper.stop().animate({marginLeft:-offset},1000,'easeInOutQuart',finish_seek)
              else
                $Wrapper.stop().animate({marginTop:-$self.outerHeight()},1000,'easeInOutQuart',finish_seek)
              
              $detail.css({opacity: 0,cursor:'pointer'}).appendTo($Slides).animate({opacity:1},1000,'easeInOutQuart')
            
            }
             
             
            function finish_seek() {

             $detail.bind('click',function() {$detail.animate({opacity:0},1000,'easeInOutQuart');$Wrapper.stop().animate({marginLeft:0},1000,'easeInOutQuart')})
             
            }
            
          } //on_seek
          
                 
        }//ATGRID
        
        ,
        
        AT_SIDE: function($self) {
        
          var $Items = $self.find('div.AT-SIDE-ITEMS'),
              active = 0;
          
          $Items.css({position:'relative'})
          
          $self.find('div.AT-GRID-ITEM').each(function(i){new AT_ITEM($self,$(this),i)});
          
          $self.css({width:$(window).width()}).bind('SEEK',on_seek)
          
          $(window).bind('resize',on_resize) 
          
          function on_resize(e){
          
            $self.css({width:$(window).width()})
            
          }
          
            


          function on_seek(e,$src,left,i) {
            active = i;
           
            $Items.stop().animate({left:-left},1000,'easeInOutQuart')
          
          }
          
          //////////////////////////////////////////
          
          function AT_ITEM($owner,$self,$index) {
          
            var width     = $self.outerWidth(),
                left      = $self.offset().left - _widescreen_offset,
                $hint     = $('<div/>'),
				$videoItem 	  = $self.find('div.AT-VIDEO-ITEM'),
                $img      = $self.find('img'),
				$bcObject = $self.find('object'),
                is_active = false;
                
            var $media = $img 
            
            //if ($index>0)
              $img.css({opacity:1})
				
		
            /*
            $hint
            .css({opacity: ($index==1)?1:0})
            .addClass('nav-cue-next')
            .appendTo($self)
            .bind('click',on_click)
            */
			
			
		  
		  $body.bind('URI_CHANGE',dispose_video_item)
		
        
       	 	function dispose_video_item() {
				$bcObject.remove();
        
			}
            
            $owner
            .bind('SEEK',on_seek)
            .bind('PROXY_SEEK',on_proxy)
            
            $self
            .bind('mouseover',on_mouse_enter)
            .bind('mouseleave',on_mouse_leave)
            .bind('click',on_click)
            
            $self.css({position:'relative'}).css({cursor:'pointer'})
            
            $img.css({opacity:0})
            
            var $tmp_img = $('<img/>')
            
            $tmp_img.bind('load',on_cache)
            
            $tmp_img.attr('src',$img.attr('src'))
            
            
            function on_cache(e) {
            
              $img.animate({padding:0},50*$index).animate({opacity:1},950,'easeInOutQuart')
            
              $self.css({background:'#fff'})
              $self.addClass('initialized')
              
            }

            
            function on_mouse_enter(e) {
				
              $media.stop().animate({opacity:1},750,'easeOutQuart')
                         
            }
			
            
            function on_mouse_leave(e) { 

              if (active!=$index){
                $media.stop().animate({opacity:1},750,'easeOutQuart')
              }   
            }
			
            
            function on_click(e) {
				
              if (!is_active) {
              
                is_active = true;
              
                on_mouse_enter(false)
                
                $owner.triggerHandler('SEEK',[$self,left,$index])
                
              }else{
                $owner.triggerHandler('PROXY_SEEK',$index+1)
              
              }
			  
              togglePause($index);
            
            }
            
            function on_proxy(e,id) {
				
              if ($index==id && $index !=1)
                on_click();
            
            }
            
            function on_seek(e,src,l,i) {
            
              if (i!=$index && is_active) {
              
                is_active = false;
                
                $media.stop().animate({opacity:1},750,'easeOutQuart')
              
                
              
              }
              
              /*
              
              if ($index==i+1)
              
                $hint
                .stop()
                .animate({left:0},500,'easeOutQuart')
                .animate({opacity:1},500,'easeOutQuart')
                
              else
                $hint.stop().animate({opacity:0},500,'easeOutQuart')
              
              */  
            
            }
            
            
          
            
            
            
          
          
          
          }
          
        
        
        }//AT_SIDE
        
        ,
        
        //////////////////////////////////////////
        
        AT_OBJECT_DETAIL: function ($self,$dl) {
        
          
          var $dd        = $dl.find('dd'),
              $item      = $self.find('.AT-OBJECT-DETAIL-ITEM'),
              $img       = $item.find('img'),
              $detailnav = $('<div/>').addClass('AT-OBJECT-DETAIL-NAV').prependTo($self),
              dlength     = $dd.length,
              content    = new Array(),
              active     = 0;
              
          $dd.each(
            function(i){
              
              content.push(
                //$(this).find('img').attr('src')
                $(this).html()
              )
              
              var index = i+1
              
              new SequenceLink(index);

              
          });
                    
          
          
          if (dlength>1)
            $item
            .bind('click',on_click)
            .css({cursor: 'pointer',opacity:0})
          
          $item.stop().animate({opacity:1},750,'easeOutQuart')
          
          
          function SequenceLink(index) {
          
            var $a = $('<a/>')
              .attr({href:'#/'+index,rev:(index-1)})
              .html(index)
              .bind('click',on_number_click)
              
            if (dlength>1)
              $a.appendTo($detailnav)
              
            if (index==1)
              $a.addClass('active')
              
            $self.bind('DETAIL',on_detail)
            
            function on_number_click(e) {
          
              active = $(this).attr('rev');
              
              
            
              sequence();
            
              e.preventDefault();
          
            }
            
            function on_detail(e,id) {
            
              if (id==index)
                $a.removeClass().addClass('active')
              else
                $a.removeClass()
            
            }

          }
                    
          
          function on_click(e){
          
            active++;
            
            if (active>=content.length)
              active = 0;

            sequence();
          
            e.preventDefault();
          }
          
          function sequence() {
            
            $self.triggerHandler('DETAIL',active+1)
            
          
            $item.stop().animate({opacity:0},750,'easeOutQuart',repost)
            
          }
          
          function repost(e) {
            
            $item.html($(content[active]))
            
            //$('<img/>').attr('src',images[active]).appendTo($item)
            
            $item.animate({opacity:1},750,'easeOutQuart')
          
          }
              
           
        
        }
        ,
        
        //////////////////////////////////////////
        
        AT_OBJECTS: function($self) {
        
          $self.find('div').each(function(i) {new AT_OBJECT_A($self,$(this),i)})
          
          
          
          //////////////////////////////////////////
          
          function AT_OBJECT_A($owner,$self,$index) {
          
            
            var $img   = $self.find('img'),
                $title = $img.attr('alt')
            
            ///////////////////////////////
            
            $body.bind('URI_CHANGE',on_uri_change)
            
            function on_uri_change(e) {
            
              /*if (_location.pathNames.length>2) {
                $img.animate({padding:0},25*$index).animate({opacity:0},650,'easeInOutQuart')
              }else{*/
                $img.animate({padding:0},12*$index).animate({opacity:1},650,'easeInOutQuart')
              //}
            
            }
            
            
            $body.bind('CONTINUE',on_continue)
             
            $img.css({opacity:1})
            
            var $tmp_img = $('<img/>')
            
            $tmp_img.bind('load',on_cache)
            
            $tmp_img.attr('src',$img.attr('src'))
            
            function on_cache(e){
            
              //$img.animate({padding:0},50*$index+250).animate({opacity:1},950,'easeInOutQuart')
            
              //$self.addClass('initialized')
            
              if (_location.pathNames.length==2)
                on_continue();
              
            }
            
            function on_continue(e) {
            
              $img.animate({padding:0},25*$index).animate({opacity:1},950,'easeInOutQuart',function(){initialized=true})
            
              loaded = true;
              
              $self.addClass('initialized')
                
            }
            
            
            
            ///////////////////////////////
            
            
            $self
            .bind('mouseenter',on_mouse_enter)
            .bind('mouseleave',on_mouse_leave)
            .bind('click',on_click)
            
            function on_click(e) {
            
              //alert($self.find('a'))
              
              e.preventDefault();
              
            }
            
            function on_mouse_enter(e) {
            
              $body.triggerHandler('SUB_CAPTION',[$title,'on'])
              
              $self.stop().animate({opacity:.6},550,'easeOutQuart')
            
            }
            
            function on_mouse_leave(e) {
            
              $body.triggerHandler('SUB_CAPTION',[$title,'off'])
              
              $self.stop().animate({opacity:1},550,'easeOutQuart')            
              
            }
          
          
          }
        
      }// AT_OBJECTS
      
      ,
      
      AT_VERT: function($self) {
      
        var $Items = $self.find('.AT-VERT-ITEMS'),
            o_top  = 0,
            total  = 0;
			backPressed = false;
        
        $self.css({height: $(window).height(),overflow:'hidden'})
        
        $self.find('.AT-VERT-ITEM').each(
          function(i){
            total++;
            new VERT_ITEM($self,$(this),i)
          })
        
        $self.bind('SEEK',on_seek)
        
        
          
        $Items.css({position:'relative'})
		
        
        
        function on_seek(e,id,h) {
			
			if(id == 0) {
				$icon.stop().animate({opacity:0}, 1000, 'easeInOutQuart')
			} else {
				$icon.stop().animate({opacity:1}, 1000, 'easeInOutQuart')
			}
				
			if(backPressed) {
				o_top+=h;
				backPressed = false;
			}  else {
            	o_top-=h;
			}
            
			
            $Items.stop().animate({marginTop:o_top},1000,'easeInOutQuart')
            
            $('html,body').stop().animate({scrollTop:0},1000,'easeInOutQuart')
            
            //$Items.stop().animate({marginTop:-$(window).height()*(id+1)},1000,'easeInOutQuart')
          
          }
        
        
        function VERT_ITEM($owner,$self,$index) {
        
        
          var   width     = $self.outerWidth(),
                height    = ($(window).height()-200<600) ? 600 : $(window).height()-200,
                left      = $self.offset().left - _widescreen_offset,
                $hint     = $('<div/>'),
                $img      = $self.find('img'),
                is_active = ($index==0) ? true : false,
                o_top     = $self.offset().top;
                
          
          $self.css({paddingBottom:0,height: height,cursor:'pointer'})
          
          
          var $media = $img 
            
           
              $img.css({opacity:.4})
              
            
            $owner
            .bind('SEEK',on_seek)
  
            
            $self
            .bind('mouseover',on_mouse_enter)
            .bind('mouseleave',on_mouse_leave)
            .bind('click',on_click)
			
			$icon
        	.css({opacity:0,bottom:42,cursor:'pointer'})
        	.bind('click',on_page_up);

        
        	function on_page_up(e) {
				if (is_active && $index !=0) {
					backPressed = true;
					$owner.triggerHandler('SEEK',[$index-1,height])
				}
			}
          
				/*if ($index < total-1) {
				
				  if (is_active) 
					$owner.triggerHandler('SEEK',[$index+1,height])
				  else
					$owner.triggerHandler('SEEK',[$index,height])
				  
				}
                
            
          
		  	}*/
            
            $self.css({position:'relative'}).css({cursor:'pointer'})
            
            $body.bind('resize',on_resize)
            
            $img.css({opacity:0})
            
            var $tmp_img = $('<img/>')
            
            $tmp_img.bind('load',on_cache)
            
            $tmp_img.attr('src',$img.attr('src'))
            
            
            function on_cache(e) {
            
              $img.animate({padding:0},50*$index).animate({opacity:1},950,'easeInOutQuart')
            
              $self.css({background:'#fff'})
              
              $self.addClass('initialized')
              
            }

            function on_resize(e) {
            
              if (is_active) {
              
                //$owner.triggerHandler('SEEK',[$index,$self.outerHeight()])
              
              }
              
            }
            
            function on_seek(e,i,src) {
            
              
              if ($index==i) {
                
                is_active = true;
                
                $media.stop().animate({opacity:1},750,'easeOutQuart')
              
              }else{
              
                
                if (!is_active)
                  $media.stop().animate({opacity:1},750,'easeOutQuart')
                
                
                
                is_active = false;
              
                
              }
              
            
            }
            
            
            function on_mouse_enter(e) { 
            
              $media.stop().animate({opacity:1},750,'easeOutQuart')
              
                            
            }
            
            function on_mouse_leave(e) { 
            
              if (!is_active){
              
                $media.stop().animate({opacity:1},750,'easeOutQuart')
                
                
                
              }
              
              
                
            }
			
			

          
          
          
          function on_click(e) {
          
             //$media.stop().animate({opacity:1},750,'easeOutQuart')

            
            if ($index < total-1) {
            
              if (is_active) 
                $owner.triggerHandler('SEEK',[$index+1,height])
              else
                $owner.triggerHandler('SEEK',[$index,height])
              
            }
              
            e.preventDefault();
          
          }
        
        
        }
      }
      
      ,
      
      AT_VIDEO: function($self) {
        
        var $a = $self.find('a.video'),
            $video = $self.find('div.AT-VIDEO-PLAYER'),
            $playback = $self.find('div.AT-VIDEO-PLAYBACK'),
            $copy = $self.find('div.AT-VIDEO-COPY'),
            $h1 = $video.find('h1'),
            $mov = $h1.attr('title');
        
         
        $body.bind('URI_CHANGE',dispose_video)
        
        $('<div/>').attr('id','FLVPLAYBACK').appendTo($playback)
        
        show_video();
        
        function dispose_video() {
        
          $playback.remove();
        
        }
        
        function show_video() {
			
        
          //$copy.stop().animate({opacity:1},1100,'easeInOutQuart',function(){
            
            var src = 'content/'+_location.pathNames[0]+'/'+_location.pathNames[1]+'/_assets/video/'+$mov.split('.mov').join('.f4v');
            
            var flashvars = {
                src: src
            };
      
            var params = {
            menu: "false",
            allowFullScreen: "true",
            wmode:"transparent"
            };
            
            var attributes = { 
            id:'flash_engine', 
            name:'flash_engine' 
            };
            
            swfobject.embedSWF("VideoPlayer.swf", "FLVPLAYBACK", "960","575", "10.0.0", "lib/js/swfobject/expressInstall.swf",flashvars,params, attributes);   
            
     
          
          //});
          
          

        
        }
         
      } //AT_VIDEO
	  ,
	  
	  AT_ZOOM: function($self) {
	  
	  	var $zoomOut = $self.find('div.ZOOM-OUT'),
            $zoomIn = $self.find('div.ZOOM-IN');
			$zoomItems = $self.find('img.AT-ZOOM-ITEM'),
			selected = 0;
			
			$zoomOut.css({opacity:0,cursor:'pointer'})
			$zoomIn.css({opacity:.6,cursor:'pointer'})
			
		$zoomOut
		 .bind('mouseover',on_mouse_enter_out)
         .bind('mouseleave',on_mouse_leave_out)
         .bind('click',on_prev)
		 
		$zoomIn
		 .bind('mouseover',on_mouse_enter_in)
         .bind('mouseleave',on_mouse_leave_in)
         .bind('click',on_next)
		 
		  function on_mouse_enter_out(e) {
			  if(selected > 0) {
			 	 $(this).stop().animate({opacity:1},750,'easeOutQuart')
			  }
		  }
            
            function on_mouse_leave_out(e) {
				if(selected > 0) {
               	 	$(this).stop().animate({opacity:.6},750,'easeOutQuart') 
				}
             }
			 
			 
			 function on_mouse_enter_in(e) {
				 if(selected < $zoomItems.length-1) {
			 		 $(this).stop().animate({opacity:1},750,'easeOutQuart')
				 }
		  	}
            
            function on_mouse_leave_in(e) {
				if(selected < $zoomItems.length-1) {
               		$(this).stop().animate({opacity:.6},750,'easeOutQuart') 
				}
             }
			 function on_prev(e) {
				 if(selected > 0) {
				 	selected--;
					$zoomIn.stop().animate({opacity:.6},750,'easeOutQuart')
					
					hideOthers();
					
					
					if(selected == 0) {
						$(this).stop().animate({opacity:0},750,'easeOutQuart')
					}
				 }
			 }
			 
			 function on_next(e) {
				 if(selected < $zoomItems.length-1) {
				 	selected++;
					$zoomOut.stop().animate({opacity:.6},750,'easeOutQuart')
					
					hideOthers();
					
					
					
					if(selected == $zoomItems.length-1) {
						$(this).stop().animate({opacity:0},750,'easeOutQuart')
					}
				 }
			 }
			 
			 function hideOthers() {
			 	$zoomItems.each(
          				function(i){
							if(i == selected) {
								$(this).css({opacity:0, 'display': 'block'});
								$(this).animate({opacity: 1.0}, 1000, function() {
								});
							} else {
								
								$(this).css('display', 'none');
							}
         				 })
			 }
              
		 
		
	  }
	  ,
	  
	  AT_MOON: function($self) {
		  
		  setTimeout(function() { slideSwitch() }, 1000);


         
      } //AT_MOON
	  ,
	  
	  AT_INTRO_VIDEO: function($self) {
            $introVideo = $self.find('div.AT-INTRO-PLAYER'),
			$introPlayback = $self.find('div.AT-INTRO-PLAYBACK');
			
        
		$body.bind('URI_CHANGE',dispose_intro_video)
		
		dispose_intro_video();
		
        
        function dispose_intro_video() {
			$tempID = $("#myExperience167653380001"); 
			$tempID.remove();
		  if(_location.pathNames.length == 1 && _location.pathNames[0] == "JimDenevan") {
			  add_video();
		  }
        
        }
		
		
		
		function add_video() {
			
			$introPlayback = $('<div/>').attr('id','AT-INTRO-PLAYBACK').appendTo($introVideo)
			
			
			
				$introPlayback.append("<div style=\"display:none\"></div><object id=\"myExperience167653380001\" class=\"BrightcoveExperience\"><param name=\"bgcolor\" value=\"#000000\" /><param name=\"width\" value=\"800\" /><param name=\"height\" value=\"450\" /><param name=\"playerID\" value=\"167653380001\" /><param name=\"publisherID\" value=\"96978055001\"/><param name=\"isVid\" value=\"true\" /><param name=\"isUI\" value=\"true\" /><param name=\"dynamicStreaming\" value=\"true\" /><param name=\"@videoPlayer\" value=\"326251151001\" /></object><script type=\"text/javascript\">runMobileCompatibilityScript('myExperience', 'anId');</script><script type=\"text/javascript\">brightcove.createExperiences();</script>");
				
				
		
		}
        
        
        
         
      } //AT_VIDEO_BC
	  ,
	  
	  AT_BC_VIDEO: function($self) {
            $bcVideo = $self.find('div.AT-VIDEO-BC-PLAYER'),
			$bcObject = $self.find('object');
			
			$body.bind('URI_CHANGE',dispose_bc_video)
        
        function dispose_bc_video() {
			$bcObject.remove();
		}
        
         
      } //AT_VIDEO_BC
	  ,
	 	  
	  AT_AUDIO: function($self) {
		  var $audioPlayback = $self.find('div.AT-AUDIO-PLAYBACK');
		  
	  	$body.bind('URI_CHANGE', dispose_audio)
		
		$('<div/>').attr('id','AUDIOPLAYBACK').appendTo($audioPlayback)
		
		show_audio();
		
		function dispose_audio() {
			$audioPlayback.remove();
		}
		
		function show_audio() {
        
          //$copy.stop().animate({opacity:1},1100,'easeInOutQuart',function(){
            
            var src = 'content/'+_location.pathNames[0]+'/'+_location.pathNames[1]+'/_assets/audio/'+_location.pathNames[2] + '.mp3';
            
            var flashvars = {
                src: src
            };
      
            var params = {
            menu: "false",
            allowFullScreen: "true",
            wmode:"transparent"
            };
            
            var attributes = { 
            id:'flash_engine', 
            name:'flash_engine' 
            };
            
            swfobject.embedSWF("audio_player.swf", "AUDIOPLAYBACK", "825","30", "10.0.0", "lib/js/swfobject/expressInstall.swf",flashvars,params, attributes);   
     
          
          //});
          
          

        
        }
	  }
      
      } //templates
      
      
      /* ---------------------------- */

      /* ContentManager */
      
      function ContentManager() {
      
        var $self           = $('div#content'),
            $segments       = $('div#segments'),
            $segment_items  = $('div.segment'),
            uri_length      = 0,
            active_segment  = 0;

        //$segments.css({position:'relative'})
        
        $body
        .bind('URI_CHANGE',on_uri_change)
        .bind('SEGMENT_READY',on_segment_init);
        
         $(window).bind('resize',on_resize)
          
         function on_resize(e) {
			 
			if(uri_length-1 == 0) {
				$segments.stop().animate({marginTop:-$(window).height()*(uri_length-1)+95},1000,'easeInOutQuart')  
			} else {
			 
          		$segments.stop().animate({marginTop:-$(window).height()*(uri_length-1)+150},1000,'easeInOutQuart')  
			}
          
          //$body.stop().animate({scrollTop:$(window).height()*(uri_length-1)+150},1000,'easeInOutQuart')
            
         }
        
        
        $segment_items.each(function(i){
        
          new Segment($(this),i)
        
        })
        
        function height_offset(active_seg){
        
          var h = 0,
              i = 0;
          
          $segment_items.each(function(){
          
      
            if (i<active_seg)
              h += ($(this).outerHeight() > $(window).height()) ? $(this).outerHeight() : $(window).height();
            
            i++;
          
          });  
          
          return h;
        
        }
        
        function on_uri_change(e,ignore) {
          
          if (ignore) return;
          
          uri_length = _location.pathNames.length
          
          adjust_view();
          
          active_segment = uri_length
                    
          _segments = _location.pathNames
          
          
             
        }
        
        function on_segment_init(e) {
        
          
          //adjust_view();
        
        }
        
        function adjust_view(){
        
          var h = height_offset((uri_length-1));
		  
         if(h == 0) {
			$segments.stop().animate({marginTop:-h+95},1000,'easeInOutQuart',function(){$body.triggerHandler('SEGMENTS_ACTIVE')})
		 } else {
         	$segments.stop().animate({marginTop:-h+150},1000,'easeInOutQuart',function(){$body.triggerHandler('SEGMENTS_ACTIVE')})
		 }
          
          $('html,body').stop().animate({scrollTop:0},1000,'easeInOutQuart')
          
          
        }
        
        /* ---------------------------- */
        
        /* AddressManager */
        
        function Segment($self,$index) {
        
          var $dl,
              active = false,
              subtitle = '',
              last   = '',
              id     = '',
              sub    = '',
              _html  = '',
              queue  = '',
              home   = true;
              
          
          $body
          .bind('URI_CHANGE',on_uri_change)
          .bind('SEGMENT_LOADED',on_segment)
          
          
          
          $(window).bind('resize',resize)
          
          resize();
          
          if ($index==0)
            queue=true
          
          function resize(e) {
            
            var h = $(window).height();
           /*TODO*/            

           if($index > (uri_length-1))

              $self.css({minHeight: 0}) 

            else 

              $self.css({minHeight:h}) 

              
			/*
            $self.css(

              {minHeight: h}

            )*/

            

            //$self.css({height: h})


            
            
          
          }
          
          function dispatch() {
          
            if ($index==uri_length-1){ 
            
               $body.triggerHandler('SUB',[subtitle,'on'])
               
               $body.triggerHandler('SEGMENT_LOADED',$index) 
            }

            
          }
          
          function on_segment(e,id) {
          
            if (id==$index) {

              $body.triggerHandler('SEGMENT_INIT',$index)

              intro();
              
             
              
            }

          
          }
          
          function intro() {
          
            $self.stop().animate({opacity:1},600,'easeOutQuart',intro_complete)
          
          }
          
          function intro_complete() {
          
            $body.triggerHandler('SEGMENT_READY',$index)
          
          }
          
          function on_uri_change(e) {
          
            
            
            var uri_length = _location.pathNames.length
              
           
            
            if ($index<uri_length) {
              
             //alert(id + " == " + _location.pathNames[$index] + " : " + $index + " < " + uri_length)
             
             
             
             
             
              if (id==_location.pathNames[$index]) {
              
                dispatch();
                
              }else{
                
                id =  _location.pathNames[$index];
                
                //alert('need to load: '+ id)
                
                
                
                resize();
                
                load_content();
                
                
                              
              }
              
              
              
              
            }else{
            
            /*TODO*/
            //if($index > (uri_length-1))
            //  $self.css({overflow:'hidden'}).animate({height: 0},1000,'easeInOutQuart')
            //else 
            //  $self.animate({height: $(window).height()},1000,'easeInOutQuart')
            
              dispose();
			  resize();
              
              
            }

          } // uri_change
          
          
          function load_next() {
          
            if (queue){
            
              queue = false;
              
              load_content();
            
            }
          
          }
          
          function load_content() {
          
            
            if ((active && uri_length-1==$index ) || home==true){
                           
              home = false;
                           
              queue = true
              
              dispose(true)
              
              return;
               
            }
            
             //alert('load ' + _location.pathNames[$index])
           
            
            $.ajax({
                beforeSend: function() {},
                data: {
                  path:_location.path,
                  id:$index
                },
                error: function () {},
                success: on_response,
                url: 'content/content.php'
             });
             
             function on_response(response) {
             
               //$self.addClass('precache')
               //$self.template({html:response}).html()
               
               _html = response;
               
               $self.html(_html)
               
               $dl = $self.find('dl')
               
               var $dt = $dl.find('dt');
                   
                   

               if ($dt.length>0)
                 subtitle = !($dl.hasClass('ignore-display')) ? $dt.html() : '';
               
               active = true;
               
               initialize_content();
               
             }
          
			 // call our coremetrics page view
			 var arrlen = _location.pathNames.length;
			
			 cm_pageid = _location.pathNames[arrlen-1];
			 cm_catid = _location.pathNames[0];
			 cmCreatePageviewTag(cm_pageid,cm_catid, null, null);
			 
          }
          
          function initialize_content() {
                        
            //dispatch()  
            
            $self.find('div.EXTRA').each(function(){ $body.triggerHandler('EXTRA_NAV',[$(this).html(),id]) })
          
            $self.find('div.AT-GRID').each(function(){new TEMPLATES.AT_GRID($(this))})
			
			$self.find('div.AT-HOME-GRID').each(function(){new TEMPLATES.AT_HOME_GRID($(this))})
          
            $self.find('div.AT-OBJECTS').each(function(){new TEMPLATES.AT_OBJECTS($(this))})
          
            $self.find('div.AT-OBJECT-DETAIL').each(function(){new TEMPLATES.AT_OBJECT_DETAIL($(this),$dl)})
          
            $self.find('div.AT-VIDEO').each(function(){new TEMPLATES.AT_VIDEO($(this))})
			
			 $self.find('div.AT-INTRO-VIDEO').each(function(){new TEMPLATES.AT_INTRO_VIDEO($(this))})
			
			$self.find('div.AT-AUDIO').each(function(){new TEMPLATES.AT_AUDIO($(this))})
          
            $self.find('div.AT-SIDE').each(function(){new TEMPLATES.AT_SIDE($(this))})
          
            $self.find('div.AT-VERT').each(function(){new TEMPLATES.AT_VERT($(this))})
          
            $self.find('div.AT-TEXT').each(function(){new TEMPLATES.AT_TEXT($(this))})
          
            $self.find('div.AT-INTRO').each(function(){new TEMPLATES.AT_INTRO($(this))})
			
			$self.find('div.AT-MOON').each(function(){new TEMPLATES.AT_MOON($(this))})
			
			$self.find('div.AT-ZOOM').each(function(){new TEMPLATES.AT_ZOOM($(this))})
			
			$self.find('div.AT-BC-VIDEO').each(function(){new TEMPLATES.AT_BC_VIDEO($(this))})
          
            $self.find('a.address').address();
            
            $self.find('a._blank').blanklink();
            
            dispatch();
            
          
          }
          
          function dispose(repost) {
			  
			if(!repost) {
				var h = $(window).height();
           		 $self.css(
              		{height: 0}
            	)
				
			}
            $self.stop().animate({opacity:0},1000,'easeOutQuart',clean_up)
            
            function clean_up() {
            
              active = false;
              
              if (repost) {
                
                load_next();
              
              }
              
             // alert($index + " < " + _location.pathNames.length)
              
              if ($index>=_location.pathNames.length) {
              
               id = '';
              
               $self.html('')
               
               //alert('cleared: ' + $index)
              
              }
            
            }
            
              
          
          }
        
          
        
        }
        
        
        
      
      }//ContentManager
      
      /* ---------------------------- */

      /* AddressManager */
      
      function AddressManager() {
      
      
            var title     = document.title,
                DBUG_MODE = false;

            // Simple log
            var log = function(msg) {
            
              if (DBUG_MODE) {
              
                if (!$('.log').length) 
                    $('<div class="log"></div>').appendTo('body');
                    
                
                $('.log').append(msg.replace(/^([^:]*):(.*)$/, '<p><b>$1:</b> <span class="$1">$2</span></p>'))
                    .attr({scrollTop: $("div").attr('scrollHeight')})
                    .find('p:nth-child(even)').addClass('even');
                    
              }
                    
            }
            
            // Default tracker mock
            var pageTracker = {
            
                _trackPageview: function() {
                
                    log('track: ' + arguments[0]);
                    
                }
                
            }

            // Serialization utility
            var serialize = function(obj, re) {
            
                var result = [];
                
                $.each(obj, function(i, val) {
                
                    if ((re && re.test(i)) || !re)
                        result.push(i + ': ' + (typeof val == 'object' ? val.join 
                            ? '\'' + val.join(', ') + '\'' : serialize(val) : '\'' + val + '\''));
                            
                });
                
                return '{' + result.join(', ') + '}';
            }
            
            // Init and change handlers
            $.address
            .init(on_address_init)
            .change(on_address_change);
            
            /////////////////////////////////////
            
            function on_address_init(event) {
            
                log('init: ' + serialize({
                    value: $.address.value(), 
                    path: $.address.path(),
                    pathNames: $.address.pathNames(),
                    parameterNames: $.address.parameterNames(),
                    queryString: $.address.queryString()
                }));
                
            }
            
            ////////////////////////////////////
            
            function on_address_change(event) {
            
                
                
                log('change: ' + serialize(event, /parameters|parametersNames|path|pathNames|queryString|value/));
                
                var names = $.map(event.pathNames, function(n) {
                    return n.substr(0, 1).toUpperCase() + n.substr(1);
                }).concat(event.parameters.id ? event.parameters.id.split('.') : []);
                
                var links = names.slice();
                
                var match = links.length ? links.shift() + ' ' + links.join('.') : 'Home';
                
                $('a').each(function() {
                    $(this).toggleClass('selected', $(this).text() == match);
                });
                
                $.address.title([title].concat(names).join(' / '));
                
                dispatch_event(event)
                
            }
            
            function dispatch_event(event) {
            
              _location = {path:event.path,pathNames:event.pathNames};
            
              if(_location.path=='/')
                _location = {path:'/Home',pathNames:new Array("Home")}
                
                
                $body.triggerHandler('URI_CHANGE');
            
            
            }
            
            
      } // Address
      
      
      
      function Typewriter() {
      
        var $self = '',
            $phrases = new Array(
              
              
              {caption:'Our most valuable commodity',id:'AndrewZuckerman/Trust'},
//              {caption:'A thing of beauty',id:'JaneCampion/BrightStarMovie',rev:'/AlicesBlog'},
              {caption:'Rachael the child',id:'DavidEustace/InSearchOfEustace/MyDaughter'},
//              {caption:'Getting to know the light',id:'JaneCampion/BrightStarMovie/GreigFrasersGallery'},
              {caption:'Passing through alright to get to wonderful',id:'AndrewZuckerman/Trust/StillBill'},
              {caption:'Rachael the woman',id:'DavidEustace/InSearchOfEustace/Portraits'},
//              {caption:'An unexpected sender',id:'JaneCampion/BrightStarMovie/ValentineLetter'},
              {caption:'Simple truths',id:'AndrewZuckerman/Trust/HighFalls'},
//              {caption:'A brighter word than bright',id:'JaneCampion/BrightStarMovie/ProductionPhotographs'},
              {caption:'Love from scratch',id:'AndrewZuckerman/Trust/LocandaViniEOlii'},
              {caption:'Quiet moments when nothing is said',id:'DavidEustace/InSearchOfEustace/MyDad'},
//              {caption:'Determination',id:'JaneCampion/BrightStarMovie/OnSet'},
              {caption:'Brotherhood',id:'AndrewZuckerman/Trust/LaddBrothers'},
//              {caption:'The strength of trees',id:'JaneCampion/BrightStarMovie/GreigFrasersGallery2'},
              {caption:'381.5 miles',id:'DavidEustace/InSearchOfEustace/Journey'},
//              {caption:'Our London',id:'JaneCampion/BrightStarMovie/ArtDepartment2'},
              {caption:'Due east of LA',id:'DavidEustace/InSearchOfEustace/Signs'},
//              {caption:'Doing things your way',id:'JaneCampion/BrightStarMovie/NotesToTheApprentice'},
              {caption:'The day\'s headline',id:'DavidEustace/InSearchOfEustace/MJ'},
//              {caption:'A place where I will share',id:'JaneCampion/BrightStarMovie/Introduction'},
              {caption:'In search of Eustace',id:'DavidEustace/InSearchOfEustace/Film'},
//              {caption:'Learning the steps, mastering the dance',id:'JaneCampion/BrightStarMovie/DanceClass'},
              {caption:'Rubbish',id:'DavidEustace/InSearchOfEustace/Scrapbook'},
              {caption:'24-7',id:'AndrewZuckerman/Trust/LevenBetts'},
//              {caption:'The shadows of clotheslines',id:'JaneCampion/BrightStarMovie/LocationPictures'},
              {caption:'Six weeks, thirteen hands',id:'AndrewZuckerman/Trust/MrNed'},
              {caption:'Something we got right',id:'DavidEustace/InSearchOfEustace'},
//              {caption:'Close your eyes',id:'JaneCampion/BrightStarMovie/ChildrensActingWorkshop'},
//              {caption:'An unstoppable momentum',id:'JaneCampion/BrightStarMovie/Storyboards'},
//              {caption:'It\'s all there waiting for you if you make a little effort',id:'JaneCampion/BrightStarMovie/JaneInterview'},
              {caption:'It all comes with age',id:'AndrewZuckerman/Trust/Wisdom'},
              {caption:'We made it',id:'DavidEustace/InSearchOfEustace/Journey'}
              
              
            ),  
            $content = $('div#index'),
            _concat = '... '
            caption = $phrases[0].caption+_concat,
            active = 0,
            last_active = -1,
            $active_link = create_new_link(),
            $active_link_last = $active_link,
            char = 0,
            is_active = true,
            typespeed = 24,
            typedelay = 850;

        play();
        
        
        
        $body
        .bind('URI_CHANGE',on_uri_change)
        .bind('SEGMENT_INIT',on_segment_init)
        
        
        function on_uri_change(e,id) {
            
            
            
            pause();
        
        }
        
        function on_segment_init(e,id) {
        
          if (_location.path=='/Home' || _location.path=='/Home/' || _location.path== '/')
            play();
          else
            pause();
            
        
        }
        
        function pause() {
          
          is_active = false;
          
        }
        
        function play() {
        
          $content = $('div#index');

		  if ($content.length<1)
            return;
          
          is_active = true;
          
          //alert (active + " :  " +$phrases.length)
          
          if (active>0)
            resume()
      
          advance();
          
        }
        
        function resume() {
          
            for (var i=0;i<active;i++){
             
              var $link = create_new_link(i);
            
            }
              

            
        
        }
    
        
        function dispose() {
        
          is_active = false;
        
        }
        
        function create_new_link(index) {

		  var phrase_index = (index!=undefined) ? index : active
          
          var $a = $('<a/>').attr('href','#/'+$phrases[phrase_index].id).attr('rel','address:/'+$phrases[phrase_index].id).attr('id','index-'+phrase_index)
          
          if(index)
            $a.html($phrases[index].caption+_concat)
            
          $a.address();
          
          $content.append($a);
          
          new IndexLink($a);

		  return $a
        
        }
        
        function type(){

          if (active!=last_active){
            
            $body.triggerHandler('TYPING',[$active_link.attr('href').split('/')[1],active]);
            
            $active_link.addClass('typing');
            
            last_active = active;
            
            $active_link_last.removeClass();
            
            $active_link_last = $active_link;
            
          }
          
          $active_link.html(caption.substr(0, char++));
          
          if(char < caption.length+1) {
          
            if(is_active)
              setTimeout(iterate, typespeed);
          
          } else {
          
            if(is_active)
              advance();
            
          }  
          
        }
        
        function iterate(){
          
            type();
        
        }
        
        function advance() {
        
          char = 0;
          
          if (active<$phrases.length){
        
          
            $active_link = create_new_link();
          
            caption = $phrases[active].caption+'... ';
          
            if (active<$phrases.length)
              setTimeout(iterate, typedelay);
            
           active++;
          
          }
            

        }
        
        
        function IndexLink($self) {

          var $id = $self.attr('rel');
          
          $body.bind('ARTIST',on_nav)
          
          $self
          .bind('mouseenter', function(e){ $body.triggerHandler('PROXY_ARTIST',$id) })
          .bind('mouseleave', function(e){ $body.triggerHandler('PROXY_ARTIST','none') })
                      
          
          function on_nav(e,id) {

            if ($id.indexOf(id)>-1 && id!='')
              $self.removeClass('proxy-nav').addClass('proxy-nav')
            else
              $self.removeClass('proxy-nav')
          }
        
        }
        
        
        
      }//Typewriter
      
    
    } //Index
    
    
   
  } //url

} //com