$(document).ready(function($) {
	
	//DRAWERS
	$('li.drawer H2.drawer-handle:not(.open)').next().hide();
	$('h2.drawer-handle').click(function () {
		if ($(this).is('.open')) {
		}
		else {
			// find the open drawer, remove the class, move to the UL following it and hide it
			$('h2.open').removeClass('open').next().slideUp('slow');
			// add the open class to this H2, move to the next element (the UL) and show it
			$(this).addClass('open').next().slideDown('slow');
		}
	});
	
	//SERVICES SLIDER
	var n = $(".services div").length;
	var item_width = 405; 
   	var left_value = item_width * (-1);
	$('.services').css('width',n * item_width);
	$('.services').css('position','absolute');
	$(".services div").each(function(i){
		var nextlink = n - 1;

		if (i != nextlink) {
		    $(this).append('<a href="#" class="next ir imgOpa">Next &#187;</a>');
		}
		if (i != 0) {
		    $(this).append("<a href='#' class='prev ir imgOpa'>&#171; Prev</a>");
		}
	});
	//if user clicked on next button
   	$('.services div a.next').click(function() {
		//get the right position
   		var left_indent = parseInt($('.services').css('left')) - item_width;
		//slide the item
   		$('.services').animate({left : left_indent}, "slow", function () { });
		//cancel the link behavior
   		return false;
	});
	//if user clicked on previous button
   	$('.services div a.prev').click(function() {
		//get the right position
   		var left_indent = parseInt($('.services').css('left')) + item_width; 
		//slide the item
   		$('.services').animate({left : left_indent}, "slow", function () { });
		//cancel the link behavior
   		return false;
	});
	
	//IMAGE OPACITY
	$(function() {
	    $('.imgOpa').css({
		    opacity:0.4
	    })
	    $('.imgOpa').each(function() {
		    $(this).hover(
			    function() {
				    $(this).stop().animate({ opacity: 1.0 }, 10);
                },
			    function() {
				    $(this).stop().animate({ opacity: 0.6 }, 500);
		    })
	    });
    });
	
});
