jQuery(document).ready(function($){
	$(".rel-docs li:last-child").addClass("last-child");
	
	if($('#c-sidebar .submenu').length=='0'){
		$('#c-sidebar').parent().hide();
	}
	
	$('ul.sf-menu').superfish({
		delay: 50,
		speed: 'fast',
		autoArrows: false
	});
	
	$(".social img").hover(
		function() {
			var n = $(this).attr('class');
			$(this).attr('src',urlpath+'img/'+n+'-hover.png');
		}, function() {
			var n = $(this).attr('class');
			$(this).attr('src',urlpath+'img/'+n+'.png');
		}
	);

	var currentPosition = 0;
	var slideWidth = 870;
	var slides = $('.slide');
	var numberOfSlides = slides.length;

	// Remove scrollbar in JS
	$('#slidesContainer').css('overflow', 'hidden');

	// Wrap all .slides with #slideInner div
	slides.wrapAll('<div id="slideInner"></div>').css({
		'float' : 'left',
		'width' : slideWidth
	});

	// Set #slideInner width equal to total width of all slides
	$('#slideInner').css('width', slideWidth * numberOfSlides);

	// Insert controls in the DOM
	$('#slideshow')
		.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
		.append('<span class="control" id="rightControl">Clicking moves right</span>');

	// Create event listeners for .controls clicks
	$('.control').bind('click', function(){
		// Determine new position
		currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
		
		if(currentPosition == -1){
			currentPosition = numberOfSlides-1;
		}else if(currentPosition == numberOfSlides){
			currentPosition = 0;
		}
		
		// Move slideInner using margin-left
		$('#slideInner').animate({
			'marginLeft' : slideWidth*(-currentPosition)
		});
	});	
});
