$(document).ready(function() {

	$("#login_link").attr("href", "#");

	$("#buzzville_connect").toggle(function() {
		$('#buzzville_connect_dialog').show();
	}, function() {
		$('#buzzville_connect_dialog').hide();
	});

	$('#gamesSelect').bind('change', function() {
		var url = $('#gamesSelect').val();

		if (url != "undefined")
			document.location = url;
	});

	var stack = []
	var games = [ {
		title : "Maîtrisez la Farandole des Eléments !",
		href : "/jeux-en-ligne/flash/loopies/jeu-loopies.html",
		src : "/img/home/slideshow/loopies.jpg",
		alt : "Les Loopies",
		img : new Image(650, 250)
	}, {
		title : "Un lac qui réserve bien des surprises !",
		href : "/jeux-en-ligne/flash/fishmania/jeu-fishmania.html",
		src : "/img/home/slideshow/fishmania.jpg",
		alt : "Fishmania",
		img : new Image(650, 250)
	}, {
		title : "Des cocktails qui rapportent...",
		href : "/jeux-en-ligne/flash/happyhour/jeu-happyhour.html",
		src : "/img/home/slideshow/happyhour.jpg",
		alt : "Happy Hour",
		img : new Image(650, 250)
	}, {
		title : "Une aventure vraiment endiablée !",
		href : "/jeux-en-ligne/flash/goldmine/jeu-goldmine.html",
		src : "/img/home/slideshow/diamondmine.jpg",
		alt : "La mine de Diamants",
		img : new Image(650, 250)
	}, {
		title : "Retrouvez le trésor des pirates !",
		href : "/jeux-en-ligne/jeux-premium/pirates/jeu-premium-pirates.html",
		src : "/img/home/slideshow/pirates.jpg",
		alt : "Pirates",
		img : new Image(650, 250)
	}, {
		title : "Le classique des jeux de plateau.",
		href : "/jeux-en-ligne/flash/yamsparty/jeu-yamsparty.html",
		src : "/img/home/slideshow/yamsparty.jpg",
		alt : "Yam&rsquo;s Party",
		img : new Image(650, 250)
	} ];

	// preload slideshow slides
	var $slideshow = $('#slideshow');
	$(games).each(function(index, game) {
		if ($('A[title=' + game.title + ']', $slideshow).size() == 0) {
			$img = $(game.img)
			$img.attr('alt', game.alt);

			$img.bind('load', function() {
				var $link = $('<a/>').attr('href', game.href).attr('title', game.title);
				$link.html(this);

				stack.push($link)
			})

			$img.attr('src', game.src);
		}
	});

	// cycle the slideshow
	$('#slideshow').cycle({
		fx : 'scrollHorz',
		pause : 1,
		next : '#next',
		prev : '#prev',
		before : onBefore
	});

	// slide show before callback
	function onBefore(current, next, options) {
		var $slideInfoInner = $("#slideInfoInner");
		if (options.addSlide)
			while (stack.length)
				options.addSlide(stack.pop())

		$('h2', $slideInfoInner).html("<a href='" + this.href + "' title='" + this.title + "'>" + $(this).children()[0].alt + "</a>");
		$('p', $slideInfoInner).html(this.title);
	}

	// load in our twitter info
	$twitter = $('#twitter')
	$twitter.twitter({
		height : 70,
		width : 200,
		callback : function() {
			$twitter.delay(1000).cycle({
				fx : 'scrollUp',
				timeout : 5000
			});
		}
	});

	// the prizes
	$('#lastWinnersInner').cycle({
		fx : 'scrollDown',
		slideExpr : 'li',
		timeout : 3000
	});

});
