
$(document).ready(function() {
	
	// hide details  
	$(".details").hide();  

	// show details
	$('.expand a').click(function() {
		$(this).parent().parent().find('.details').show('slow');
		$(this).parent().hide('slow');
		return false;
	});
	
	// hide details
	$('.collapse a').click(function() {
		$(this).parent().parent().hide('slow');
		$(this).parent().parent().parent().find('.expand').show('slow');
		return false;
	});

	// previous portofolio item
	$("#arrows #prev").livequery('click', function() {
		$("#portofolio_item").load(this.href).fadeIn('slow');;
		return false;
	});

	// next portofolio item
	$("#arrows #next").livequery('click', function() {
		$("#portofolio_item").load(this.href).fadeIn('slow');
		return false;
	});

	// services accordion
	$("#accordion").accordion({ autoHeight: false });
	
	// photo gallery
	$("#slider a").click(function() {
		// get current index
		idx = $("#photoimg").data('idx');
		if (idx === undefined) { idx = 1; }

		// increase or decrease indexx
		if ($(this).parent().attr("id") == "sprev") { idx--;	} 
		else { idx++; }

		// check if next index is out of range
		if (idx < 1 || idx > $('#photos').children().size()) { return false; }
	
		// change image src
		selector = "#photos li:nth-child(" + idx + ") img";
		$("#photoimg").attr('src', $(selector).attr('src'));
		
		// change the title
		$("#slider #photo p").attr('innerHTML', $(selector).attr('longdesc'));
		
		// store the new index
		$("#photoimg").data('idx', idx);
		
		return false;
	}); 

}); 