;(function($) {
	
// ensure the availability of console.log()
if (!window.console) window.console = { log: function() {} };
	
// ----------------------------------------------------------------------------
// Carousel
// ----------------------------------------------------------------------------	
$(function() {
	var carousel = $('.carousel');
	var articles = carousel.find('.articles');
	var items = carousel.find('.articles ul li');
	var framewidth = items.filter(':first').outerWidth()+10;
	var index = 0;
	
	carousel.find('.button').click(function() {
		if (index == items.length -1 || index + 3 > items.length-1) { // rewind
			console.log('Rewind the console');
			articles.find('ul:first').animate({left: index = 0});
			$(this).removeClass('prev').addClass('next');
		}
		else {
			index += 3;
			index = Math.min(index, items.length-1);
			console.log('Move carousel to item', index);
			articles.find('ul:first').animate({left: -1*index*framewidth});
			if (index == items.length-1 || index + 3 > items.length-1)
				$(this).removeClass('next').addClass('prev');
		}
	});
});
	
// ----------------------------------------------------------------------------
// Superfish
// ----------------------------------------------------------------------------
$(function() {
	$('ul.sf-menu').supersubs({ 
		minWidth: 10, // minimum width of sub-menus in em units 
      	maxWidth: 40, // maximum width of sub-menus in em units 
		extraWidth: 1 // extra width can ensure lines don't sometimes turn over 
	}).superfish({
		//autoArrows: !($.browser.msie && $.browser.version == '6.0'),
		autoArrows: false,
		speed: 'fast',
		onShow: function() {
			$(this).prev('a').addClass('open');
		},
		onHide: function() {
			$(this).prev('a').removeClass('open');
		}
	});
	$('ul.sf-menu').css("margin-left", 960-$('ul.sf-menu').width());
});

// ----------------------------------------------------------------------------
// Fancy box
// ----------------------------------------------------------------------------
$(function() {
	$('.fancy').fancybox();
});

// ----------------------------------------------------------------------------
// Drop shadow
// ----------------------------------------------------------------------------
$(function() {
	$('.drop-shadow').wrap('<div class="dswrap1"><div class="dswrap2"><div class="dswrap3"></div></div></div>');
});

})(jQuery);

