
var scrollToNextProject = false; //false will scroll to the closed project, true will scroll to the next

function initAccordion() {
	
	newLink = $('<a class="more" href="#" style="text-decoration:none; font-size:1px">&nbsp;</a>');
	newLink.click(function(){
						 
		thisLink = $(this);
		expandable = thisLink.prev();
		
		$theProject = thisLink.parents('.project');
		
		collapsed = (thisLink.attr('class') == 'more');
		
		expandable.slideToggle({
			duration: 1000,
			complete: function(){
				if (collapsed) {
					thisLink.removeClass('more');
					thisLink.addClass('less');
				} else {
					thisLink.removeClass('less');
					thisLink.addClass('more');
					
					/*if (scrollToNextProject) {
						$theNextProjectAnchor = $theProject.next().find('a.anchor');
						scrollWin($theNextProjectAnchor, 1000);  
					} else {
						scrollWin($theProject, 1000);  
					}*/
					
				}
			}
		});
		
		if (collapsed == false) {
			
			if (scrollToNextProject) {
				$theNextProjectAnchor = $theProject.next().find('a.anchor');
				scrollWin($theNextProjectAnchor, 1000);  
			} else {
				scrollWin($theProject, 1000);  
			}
			
		}
		
		return false;
		
	});
	newLink.insertAfter('.expandable');
	
	
	newLink = $('<a class="more" href="#">more</a>');
	newLink.click(function(){
						 
		thisLink = $(this);
		expandable = thisLink.prev();
			
		expandable.slideToggle({
			duration: 500,
			complete: function(){
				if (thisLink.attr('class') == 'more') {
					thisLink.removeClass('more');
					thisLink.addClass('less');	
					thisLink.html('less');
				} else {
					thisLink.removeClass('less');
					thisLink.addClass('more');
					thisLink.html('more');
				}
			}
		});
		
		return false;
		
	});
	newLink.insertAfter('.expandableText');	
	
    if (scrollToNextProject) {
		addAnchorLinksForAllProjects();   
	}
	
}
					
function scrollWin(el, duration){
	$('html, body').animate({
		scrollTop: el.offset().top
	}, duration);
}

function addAnchorLinksForAllProjects() {
	
	$('.project .left h3').each(function(i) {  
								
		pId = "project" + i;
		newLink = $('<div style="position:relative;"><a id="' + pId + '" name="' + pId + '" class="anchor" href="#" style="position:absolute; top:-70px;"></a></div>');
		
		newLink.insertAfter($(this));
		
  	});			
	
}

function collapseAll() {
	
	$('.project .expandable').each(function(i) {
		
		thisBox = $(this);
		thisLink = thisBox.next();
		
		if (thisLink.attr('class') == 'less') {
			
			thisBox.hide();
			
			thisLink.removeClass('less');
			thisLink.addClass('more');
			thisLink.html('more');
			
		}
		
  	});			
	
}


