$(document).ready(
	function(){
	
	
	// Sliding panels effect
	$('.panels').kwicks({
		max : 580,
		spacing : 0,
		easing: 'easeInOutQuad',
		duration: 1200
	});


	// Projects grid
	if ($("#grid").length > 0) {
		$('.object dt').hide();
		$('.object dd').hide().fadeIn('slow');
		$('.object').hover(
			function(){
				$(this).find('dd').stop().fadeTo(0,.3);
				$(this).find('dt').show();
			},
			function(){
				$(this).find('dt').hide();
				$(this).find('dd').fadeTo(1200,1);
			}
		)
	}

	// Photo gallery Cycle setup
	if ($("#gallery ul li").length > 0) {
	
	var index = 0, hash = window.location.hash;
	if (hash) {
		index = /\d+/.exec(hash)[0];
		index = (parseInt(index) || 1) - 1; // slides are zero-based
	}
		
		$('#gallery ul').cycle({
    		speed:   600, 
   			timeout:  0,
			startingSlide: index,
   			cleartype: true,
			next: '#nextImage,#gallery li img',
			prev: '#previousImage',
			previous: '#previousImage',
   			sync:0,
   			easing: 'easeInOutQuad',
   			pager: null,
   			after: function(curr,next,opts) {
				window.location.hash = opts.currSlide + 1;
			}
		})


	
	}
   	
   	
   	


	// Back button
	if($(".back").length > 0 ) {
		$(".back").click(function(event) {
				history.back();
		});
	}
	
	
	// External links
    $("a[rel='external']").addClass("external").click(function() { 
    	window.open($(this).attr('href')); 
    	return false;
    });


	// Publications 
	
	if ($('.publications').length > 0) {
	$('.carousel').hide();
	
	$('.carousel').cycle({
    	fx: 'scrollHorz',
 		speed:   2000,
		timeout: 0, 
 		cleartype: true,
		next: $(this),
		prev: '#previousImage',
		previous: '#previousImage'
		})
	
	$('#image-holder').hide();
	$('.publications #grid a').click(function(e){
		var src= $(this).attr('href');
		$('#image-holder img').remove();
		$('#image-holder').append('<img src="'+src+'" id="myimage" width="940" height="540" alt="" />');
		$('#myimage').hide();
		$('#myimage').load(function(){
			$('#myimage').fadeIn('fast');
		});
		if ($('#image-holder').is(":hidden")) {
			$('#image-holder').slideDown('slow');
			$('#image-holder').addClass('open');
		}
		e.preventDefault();
	})
	
	$('#image-holder').click(function(){
		$(this).removeClass('open').slideUp('slow');
	})
	
	}
})

