
/*-- Initializing some jQuery things ----*/

$(document).ready(function(){
		
	$('#pageQuote h2').sifr(
		{font: 'flash/sifr-fonts/handel', color:'#fff', offsetTop: 12}
	);
	
	
	// set visibility from imageframe
	$('#frame').css('display', 'block');
	
	// swap projectimages and position grey frame
	$('#projectThumbsBlock a').click( function(i, element) {
		var changeSrc = $(this).attr('href');
		$('#largeVisual').attr("src", changeSrc);
        
        // added to remove the hidden class for the large visual, projectname & intro
		$('#textSwap img').removeClass('hidden');
        $('#pageVisualTop .jScrollPaneContainer').removeClass('hidden');
		
		var frameOffset = $('#projectThumbsBlock a').index($(this)) * 115;
		$('#frame').css('top', frameOffset);
		return false;
	});
    
    // toggle the large visual & projectname to text
    $('a#readmore').click( function(event) {
		$('#textSwap img').addClass('hidden');
        
		// hide scrollpane
        $('#pageVisualTop .jScrollPaneContainer').addClass('hidden');
		
		return false;
    });
    
    $('#textSwap').click( function(event) {
        $('#textSwap img').addClass('hidden');
        
		// hide scrollpane
        $('#pageVisualTop .jScrollPaneContainer').addClass('hidden');
		
		return false;
    });
    
    // add class to image if javascript is enabled
	$('#textSwap img').removeClass('hidden');
    
    // this initialises the scollpanes on the page.
	$('#scrollableText').jScrollPane({showArrows:true});
	$('#scrollableIntro').jScrollPane({showArrows:true});
	
	$('.scrollableText').jScrollPane({showArrows:true});
	$('.scrollableIntro').jScrollPane({showArrows:true});

	// start slideshow
	setInterval( "slideSwitch()", 5000 );
	
	//--
  if ($('div#leftCol ul.projectlist').length) {
    var projectList = $('div#leftCol ul.projectlist');

    $(projectList).find('li').addClass('collapsed');
    
    projectList.find('li span').click(function () {

      projectList.find('li').each(function() {
        $(this).find('ul').hide();
        $(this).parent().addClass('collapsed');
      });
      
      $(this).parent().find('ul').toggle();
    });
    
  }
  

});


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
