var currentItemsCategory = "slots";
var theModelCarousel = null; 

function modelCarousel_initCallback(carousel) { 
	theModelCarousel = carousel;
}; 

var mycarousel_itemList = new Array();
var mycarousel_itemList = {

 blackjack: [
	{ src: 'images/carousel/items/blackjack/american.png', title: 'American Blackjack', name: 'americanbj' },
	{ src: 'images/carousel/items/blackjack/european.png', title: 'European Blackjack', name: 'modifiedbjeu' },
	{ src: 'images/carousel/items/blackjack/super7.png', title: 'Super 7 Blackjack', name: 'blackjack' },
	{ src: 'images/carousel/items/blackjack/singledeck.png', title: 'Single Deck Blackjack', name: 'singledeckbj' },
	{ src: 'images/carousel/items/blackjack/21burn.png', title: '21 Burn Blackjack', name: 'burnbj' },
	{ src: 'images/carousel/items/blackjack/pirate21.png', title: 'Pirate 21', name: 'pirate21' },
	{ src: 'images/carousel/items/blackjack/pontoon.png', title: 'Pontoon', name: 'pontoon' }
],

 poker: [
	{ src: 'images/carousel/items/pokergames/oasis.png', title: 'Oasis Poker', name: 'oasispoker' },
	{ src: 'images/carousel/items/pokergames/3cardpoker.png', title: '3 Card Poker', name: '3cardpoker' },
	{ src: 'images/carousel/items/pokergames/caribbean.png', title: 'Caribbean Poker', name: 'carpoker' },
	{ src: 'images/carousel/items/pokergames/ridem.png', title: 'Ride`m Poker', name: 'ridem' },
	{ src: 'images/carousel/items/pokergames/paigow.png', title: 'Pai Gow', name: 'paigow' }
],

 slots: [
	{ src: 'images/carousel/items/slots/pharaohking.png', title: 'Pharaoh King', name: 'pharaohking' },
	{ src: 'images/carousel/items/slots/jackpotjamba.png', title: 'Jackpot Jamba', name: 'jamba' },
	{ src: 'images/carousel/items/slots/ghoulsgold.png', title: 'Ghouls Gold', name: 'ghoulsgold' },
	{ src: 'images/carousel/items/slots/chasethecheese.png', title: 'Chase The Cheese', name: 'chasethecheese' },
	{ src: 'images/carousel/items/slots/diamondjackpot.png', title: 'Diamond Jackpot', name: 'diamondps' },
	{ src: 'images/carousel/items/slots/aztectreasure.png', title: 'Aztec Treasure', name: 'aztectreasure' },
	{ src: 'images/carousel/items/slots/diamonddreams.png', title: 'Diamond Dreams', name: 'diamonddreams' },
	{ src: 'images/carousel/items/slots/wizardscastle.png', title: 'Wizard`s Castle', name: 'wizardscastle' },
	{ src: 'images/carousel/items/slots/captaincash.png', title: 'Captain Cash', name: 'captaincash' },
	{ src: 'images/carousel/items/slots/reeloutlaws.png', title: 'Reel Outlaws', name: 'reeloutlaws' },
	{ src: 'images/carousel/items/slots/mermaidspearl.png', title: 'Mermaid`s Pearl', name: 'mermaids' },
/*	{ src: 'images/carousel/items/slots/hiddenloot.png', title: 'Hidden Loot', name: 'hiddenloot' },*/
	{ src: 'images/carousel/items/slots/backintime.png', title: 'Back In Time', name: 'backintime' },
/*	{ src: 'images/carousel/items/slots/dashforcash.png', title: 'Dash For Cash', name: 'dashforcash' },*/
	{ src: 'images/carousel/items/slots/invaders.png', title: 'Invaders', name: 'invaders' },
	{ src: 'images/carousel/items/slots/lucky7.png', title: 'Lucky 7', name: 'lucky7' },
	{ src: 'images/carousel/items/slots/monkeymoney.png', title: 'Monkey Money', name: 'monkeymoney' },
	{ src: 'images/carousel/items/slots/outofthisworld.png', title: 'Out of this World', name: 'outofthisworld' },
	{ src: 'images/carousel/items/slots/thebees.png', title: 'The Bees', name: 'thebees' },
/*	{ src: 'images/carousel/items/slots/thebighit.png', title: 'The Big Hit', name: 'thebighit' },*/
	{ src: 'images/carousel/items/slots/triplecrown.png', title: 'Triple Crown', name: 'triplecrown' }
],

 videoslots: [
	{ src: 'images/carousel/items/slots/vegas.png', title: 'Mr. Vegas', name: 'mrvegas' },
	{ src: 'images/carousel/items/slots/enchanted.png', title: 'Enchanted', name: 'enchanted' },
	{ src: 'images/carousel/items/slots/barbarycoast.png', title: 'Barbary Coast', name: 'barbarycoast' },
	{ src: 'images/carousel/items/slots/onceuponatime.png', title: 'Once Upon a Time', name: 'onceuponatime' },
	{ src: 'images/carousel/items/slots/azectreasure3.png', title: 'Aztec Treasures', name: 'aztectreasure3' },
	{ src: 'images/carousel/items/slots/gladiator.png', title: 'Gladiator', name: 'gladiator' },
	{ src: 'images/carousel/items/slots/threewishes.png', title: 'Three Wishes', name: 'threewishes' },
	{ src: 'images/carousel/items/slots/heist.png', title: 'Heist', name: 'heist' },
	{ src: 'images/carousel/items/slots/slotfather.png', title: 'Slotfather', name: 'slotfather' },
	{ src: 'images/carousel/items/slots/glamlife.png', title: 'Glam Life', name: 'glamlife' },
	{ src: 'images/carousel/items/slots/madscientist.png', title: 'Mad Scientist', name: 'madscientist' },
	{ src: 'images/carousel/items/slots/treasureroom.png', title: 'Treasure Room', name: 'treasureroom' }
],

 roulette: [
	{ src: 'images/carousel/items/roulette/european.png', title: 'European Roulette', name: 'europeanroulette' },
	{ src: 'images/carousel/items/roulette/american.png', title: 'American Roulette', name: 'americanroulette' },
	{ src: 'images/carousel/items/roulette/vipeuropean.png', title: 'VIP European Roulette', name: 'viphamburgroulette' },
	{ src: 'images/carousel/items/roulette/vipamerican.png', title: 'VIP American Roulette', name: 'vipamericanroulette' }
],

 keno: [
	{ src: 'images/carousel/items/softgames/vrb.png', title: 'Virtual RaceBook 3D', name: 'vracing' },
	{ src: 'images/carousel/items/softgames/traditionalkeno.png', title: 'Traditional Keno', name: 'traditionalkeno' },
/*	{ src: 'images/carousel/items/softgames/headsortails.png', title: 'Heads or Tails', name: 'hot' },*/
	{ src: 'images/carousel/items/softgames/instantkeno.png', title: 'Instant Keno', name: 'instantkeno' },
	{ src: 'images/carousel/items/softgames/krazykeno.png', title: 'Krazy Keno', name: 'krazykeno' },
	{ src: 'images/carousel/items/softgames/skratcherz.png', title: 'Skratcherz', name: 'scratcherz' }/*,
	{ src: 'images/carousel/items/softgames/sureshot.png', title: 'Sure Shot', name: 'sureshot' }*/
],

 cardtable: [
	{ src: 'images/carousel/items/tablegames/craps.png', title: 'Craps', name: 'craps' },
	{ src: 'images/carousel/items/tablegames/casinowar.png', title: 'Casino War', name: 'casinowar' },
	{ src: 'images/carousel/items/tablegames/highlow.png', title: 'Draw Hi-Lo', name: 'drawhilo' },
	{ src: 'images/carousel/items/tablegames/baccarat.png', title: 'Baccarat', name: 'baccarat' },
	{ src: 'images/carousel/items/tablegames/reddog.png', title: 'Red Dog', name: 'reddog' }
],

 videopoker: [
	{ src: 'images/carousel/items/videopoker/jacksorbetter.png', title: 'Jacks Or Better', name: 'jack' },
	{ src: 'images/carousel/items/videopoker/tensorbetter.png', title: 'Tens Or Better', name: 'tensbetter' },
	{ src: 'images/carousel/items/videopoker/deuceswild.png', title: 'Deuces Wild', name: 'deuce' },
	{ src: 'images/carousel/items/videopoker/doublejokerpoker.png', title: 'Double Joker Poker', name: 'doublejoker' },
	{ src: 'images/carousel/items/videopoker/multihandpoker.png', title: 'Multi-Hand Video Poker', name: 'multihandpoker' },
	{ src: 'images/carousel/items/videopoker/allamerican.png', title: 'All American', name: 'allamerican' },
	{ src: 'images/carousel/items/videopoker/pyramidpoker.png', title: 'Pyramid Poker', name: 'pyramidpoker' },
	{ src: 'images/carousel/items/videopoker/bonusdeuces.png', title: 'Bonus Deuces', name: 'bonusdeuces' },
	{ src: 'images/carousel/items/videopoker/deucesandjoker.png', title: 'Deuces and Joker Poker', name: 'jokerdeuces' },
	{ src: 'images/carousel/items/videopoker/fivedrawpoker.png', title: 'Five Draw Poker', name: 'fivepoker' },
	{ src: 'images/carousel/items/videopoker/jokerpoker.png', title: 'Joker Poker', name: 'joker' },
	{ src: 'images/carousel/items/videopoker/splitwayroyal.png', title: 'Split Way Royal', name: 'splitwayroyal' }
]

};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	// The index() method calculates the index from a
	// given index who is out of the actual item range.
	var idx = carousel.index(i, mycarousel_itemList[currentItemsCategory].length);
	carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[currentItemsCategory][idx - 1], i));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
	carousel.remove(i);
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item, number) {
	return '<a class="selector_game_image" href=#click' + number + ' onClick=openFreeGame("' + item.name + '");><img src="' + item.src + '" width="171" height="107" alt="' + item.title + '" /></a>' 
	+ '<div class="selector_game_title">' + item.title + '</div>';
};

var mycarousel_itemList3d = [
	{ src: 'images/3dcarousel/items/mrvegas.png', title: 'Mr. Vegas', name: 'mrvegas' },
	{ src: 'images/3dcarousel/items/enchanted.png', title: 'Enchanted', name: 'enchanted' },
	{ src: 'images/3dcarousel/items/coast.png', title: 'Barbary Coast', name: 'barbarycoast' },
	{ src: 'images/3dcarousel/items/once.png', title: 'Once Upon a Time', name: 'onceuponatime' },
	{ src: 'images/3dcarousel/items/aztec.png', title: 'Aztec Treasures', name: 'aztectreasure3' },
	{ src: 'images/3dcarousel/items/gladiator.png', title: 'Gladiator', name: 'gladiator' },
	{ src: 'images/3dcarousel/items/3wishes.png', title: 'Three Wishes', name: 'threewishes' },
	{ src: 'images/3dcarousel/items/heist.png', title: 'Heist', name: 'heist' },
	{ src: 'images/3dcarousel/items/slotfather.png', title: 'Slotfather', name: 'slotfather' },
	{ src: 'images/3dcarousel/items/glamlife.png', title: 'Glamlife', name: 'glamlife' },
	{ src: 'images/3dcarousel/items/mad.png', title: 'Mad Scientist', name: 'madscientist' },
	{ src: 'images/3dcarousel/items/treasure.png', title: 'Treasure Room', name: 'treasureroom' }

];

function mycarousel_itemVisibleInCallback3d(carousel, item, i, state, evt) {
	var idx = carousel.index(i, mycarousel_itemList3d.length);
	carousel.add(i, mycarousel_getItemHTML3d(mycarousel_itemList3d[idx - 1]));
};

function mycarousel_getItemHTML3d(item) {
	return '<a href=#click onClick=openFreeGame("' + item.name + '");><img src="' + item.src + '" width="180" height="130" alt="' + item.title + '" /></a>';
};


jQuery(document).ready(function() {

	jQuery('#mycarousel').jcarousel({
		vertical: false,
		wrap: 'circular',
		scroll: 2,
		itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
		itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback },
		initCallback: modelCarousel_initCallback
	});

	selectGameCategory(currentItemsCategory);

	jQuery('#mycarouseld').jcarousel({
		vertical: false,
		wrap: 'circular',
		scroll: 1,
		itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback3d },
		itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
	});

});

function hideAllSelections() {
    $("#blackjack_selected").css('background-image','url(images/z.gif)');
    $("#roulette_selected").css('background-image','url(images/z.gif)');
    $("#cardtable_selected").css('background-image','url(images/z.gif)');
    $("#slots_selected").css('background-image','url(images/z.gif)');
    $("#videoslots_selected").css('background-image','url(images/z.gif)');
    $("#videopoker_selected").css('background-image','url(images/z.gif)');
    $("#poker_selected").css('background-image','url(images/z.gif)');
    $("#keno_selected").css('background-image','url(images/z.gif)');
}

function makeSelectionsClickable() {
    $("#blackjack_selected").css('cursor','pointer');
    $("#roulette_selected").css('cursor','pointer');
    $("#cardtable_selected").css('cursor','pointer');
    $("#slots_selected").css('cursor','pointer');
    $("#videoslots_selected").css('cursor','pointer');
    $("#videopoker_selected").css('cursor','pointer');
    $("#poker_selected").css('cursor','pointer');
    $("#keno_selected").css('cursor','pointer');
}

function selectGameCategory(category) {
	hideAllSelections();
	makeSelectionsClickable();
    	$("#"+category+"_selected").css('background-image','url(images/carousel/'+category+'_selected.png)');
    	$("#"+category+"_selected").css('cursor','auto');
}

function setGameCategory(category) {
	currentItemsCategory = category;
	theModelCarousel.reset();
	selectGameCategory(category);
}

function openFreeGame(gameName) {
	var host = "http://"+window.location.host;
        var width = 800, height = 708;
        var xOffset = 0, yOffset = 0;

        var winPop = window.open(
        	host + "/free/" + gameName + ".jsp",
        	'wnd',
        	'location=no,menubar=no,resizable=yes,scrollbars=no,toolbar=no,width=' + width + ',height=' + height + ',screenX=' + xOffset + ',screenY=' + yOffset + ',top=' + yOffset + ', left=' + xOffset, true);
	if (winPop == null || typeof(winPop) == "undefined") {
		alert("Sorry, the game window has been blocked. Please disable your pop-up blocker.");
	} else {
		winPop.focus();
	}

    return false;
}
