function changepic() {
	
	if (lang == 'de') {
		var lastpic = 'gethelp'
	} else {
		var lastpic = 'showpress'
	}
	
	var activepic = $('#carousel div:visible');
	if ( activepic.attr('id') != lastpic ) {
		activepic.next().show();
		var picname = activepic.next().attr('id');
		$('#carousel ul.nav li a').removeClass('selected');
		$('#carousel ul.nav li[rel="' + picname + '"] a').addClass('selected');
	} else {
		$('#logos').show();
		$('#carousel ul.nav li a').removeClass('selected');
		$('#carousel ul.nav li[rel="logos"] a').addClass('selected');
	}
	activepic.hide();
}

$(document).ready(function() {

	// There's a clickable area above the Facebook like button. Let's open it
	// in a new window!
	$('#fans-facebook-top').click(function(){
		window.open('http://www.facebook.com/VoucherCodes.co.uk', '_blank', 'toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,menubar=1');
	})
	
	
	// Most Wanted featured articles -  make the 
	// whole li block clickable 
	$('.mostwanted-wrapper ul li').click(function() {
		window.location = $(this).find('a').attr('href');
	})

	$('.mostwanted-logo').click(function(){
		window.location = '/most-wanted/';
	})
	
	
	// The FANS OF VOUCHERCODES carousel
	$('ul.comments').cycle({
		fx: 'fade',
		speed: 500,
		timeout: 4000,
		pause: true,
		before: switchBalloon
	})

	function switchBalloon() {		
		var i = $(this).attr('name');
		var prev = i - 1;
		if (prev == 0) prev = 4;
		$('#fans-commentsFooter').removeClass('fans-commentsFooter' + prev).addClass('fans-commentsFooter' + i);				
	}
	
	
	// Make the three columns of offers/categories clickable
	$('ul.numbers-10 li:not(.link)').hover(function() {
		$(this).find('a').addClass('green-arrow');
	}, function() {
		$(this).find('a').removeClass('green-arrow');
	}).click(function(){
		window.location = $(this).find('a').attr('href');
	})
	
	$('ul#categories li:not(.link)').hover(function() {
		$(this).find('a').addClass('green-arrow');
	}, function() {
		$(this).find('a').removeClass('green-arrow');
	}).click(function(){
		window.location = $(this).find('a').attr('href');
	})	
	
	
	
	$('.transition').cycle({ 
		fx:     'fade', 
		timeout: 5000,
		pager:  '#carousel-nav ul',
	    pagerAnchorBuilder: function(idx, slide) {
	        // return sel string for existing anchor
	        return '#carousel-nav ul li:eq(' + (idx) + ') a';
		},
		pause:	true
	});
	
	function onBefore() { 
		var pos = $(".activeSlide").next().offset().top; //get position of the element *after* .activeSlide
		$("#marker").animate({top: pos}); //move marker to this position
	};
	
	$('#carousel-nav ul li:eq(0)').click(function() { 
		$('.transition').cycle(0); 
		return false; 
	});
	
	$('#carousel-nav ul li:eq(1)').click(function() { 
		$('.transition').cycle(1); 
		return false; 
	});
	
	$('#carousel-nav ul li:eq(2)').click(function() { 
		$('.transition').cycle(2); 
		return false; 
	});
	
	$('#carousel-nav ul li:eq(3)').click(function() { 
		$('.transition').cycle(3); 
		return false; 
	});

});
