var e3Tabs = {
	tabView: 'opened', //list is closed or opened
	animating: false,
	openBoxes: function(){
		if(e3Tabs.tabView == 'closed'){
			e3Tabs.animating = true;
			if(mobileChecker.whichMobile == "iphone" || mobileChecker.whichMobile == "itouch" || mobileChecker.whichMobile == "ipad" || mobileChecker.whichMobile == "android" || mobileChecker.whichMobile == "webos"){
				$('ul.exhibitor-panel').toggleClass('closed opened');
				e3Tabs.animating = false;
				e3Tabs.tabView = 'opened';
				$('ul.list-panel').toggleClass('closed opened');
				$('ul.info-panel').toggleClass('closed opened');
				$('ul.detail-panel').toggleClass('closed opened');
			} else {
				$('ul.exhibitor-panel').switchClass('closed','opened',500,function(){e3Tabs.animating = false; e3Tabs.tabView = 'opened';});
				$('ul.list-panel').switchClass('closed','opened',500);
				$('ul.info-panel').switchClass('closed','opened',500);
				$('ul.detail-panel').switchClass('closed','opened',500);
			}
			$('ul.exhibitor-panel .tabTitle a').css('cursor','default').unbind('click',e3Tabs.openBoxes);
			$('ul.list-panel .tabTitle a').css('cursor','default').unbind('click',e3Tabs.openBoxes);
			$("#prodMenu li").removeClass("selected");
			if($("#article_container").length > 0){$("#article_container").empty();}
			if($("#mpDiv").length > 0){jwplayer('mpDiv').stop();}
		}
	},
	closeBoxes: function(){
		if(e3Tabs.tabView == 'opened'){
			e3Tabs.animating = true;
			if(mobileChecker.whichMobile == "iphone" || mobileChecker.whichMobile == "itouch" || mobileChecker.whichMobile == "ipad" || mobileChecker.whichMobile == "android" || mobileChecker.whichMobile == "webos"){
				$('ul.exhibitor-panel').toggleClass('closed opened');
				e3Tabs.animating = false;
				e3Tabs.tabView = 'closed';
				$('ul.list-panel').toggleClass('closed opened');
				$('ul.info-panel').toggleClass('closed opened');
				$('ul.detail-panel').toggleClass('closed opened');
			} else {
				$('ul.exhibitor-panel').switchClass('opened','closed',500, function(){e3Tabs.animating = false; e3Tabs.tabView = 'closed';});
				$('ul.list-panel').switchClass('opened','closed',500);
				$('ul.info-panel').switchClass('opened','closed',500);
				$('ul.detail-panel').switchClass('opened','closed',500);
			}
			$('ul.exhibitor-panel .tabTitle a').css('cursor','pointer').bind('click',e3Tabs.openBoxes);
			$('ul.list-panel .tabTitle a').css('cursor','pointer').bind('click',e3Tabs.openBoxes);
		}
	},
	updateInfo: function(linkClicked){
		//not used
		//alert("Product Info should update with: " + $(linkClicked).html());
		//AJAX TO GRAB CONTENT FOR PRODUCT INFO
	},
	getDetails: function(){
		//not used
		//AJAX TO GRAB DETAILS
	}
}

var voteBox = {
	gameID:'',
	userID:'',
	newPtrLoc:0,
	init:function(){
		//check if box exists
		if($("#voteBox").length > 0){
			voteBox.gameID = $("#voteBox").attr('class');
			voteBox.userID = Cookie.get("voteUserID");
			if(voteBox.gameID == '')return false;
			//changes opacity of elements to be slightly transparent
			$("#voteBox li a").each(function(i,value){
				$(this).css('opacity',.75);
			});
			
			var whichVote = Cookie.get(voteBox.gameID);
			//read cookie for game
			if(whichVote != null && whichVote != ''){
				voteBox.disableVoting();
				$("#voteBox li.pointer").css('display','block');
				$("#voteBox li a").css('opacity',1);
				$("#voteBox li.whatDoYouThink").toggleClass('whatYouVoted', true);
				$("#voteBox li.whatYouVoted").html('What You Voted');
				voteBox.positionPointer(whichVote);
			} else {
				//setup listeners
				$("#voteBox li a").each(function(i,value){
					$(this).click(function(e){
						$("#voteBox li").css('display','block');
						voteBox.voteFor($(this).attr('class'));
						e.preventDefault(); 
					}).hover(function(){
						//move pointer to center of this element
						$(this).css('opacity',1);
					},function(){
						$(this).css('opacity',.75);
					});
				});
			}
		}
	},
	voteFor:function(whichVote){
		/* Updating is not support yet - TLB 05/26/2011
		// Are we updating a vote?
		var existingVote = Cookie.get(voteBox.gameID);
		if(!!existingVote && !!voteBox.userID) {
			// AJAX request to update vote into game
			$.ajax({url: '/game/vote/' + voteBox.gameID + '/' + voteBox.userID,
				success: function(r) {
					// update cookie
					Cookie.set(voteBox.gameID,whichVote,1 * 356);
				}
			});
		}
		else {
		*/
			// AJAX request to store vote into game
			$.ajax({url: '/game/vote/' + voteBox.gameID + '/' + whichVote + '?format=json',
				success: function(r) {
					// add cookie
					Cookie.set(voteBox.gameID,whichVote,1 * 356);
					//Cookie.set("voteUserID",r.voteId,1 * 356);
				}
			});
		//}
		//position pointer
		voteBox.positionPointer(whichVote);

		//disable clicks
		//voteBox.disableVoting();
	},
	disableVoting: function(){
		//disable clicks
		$("#voteBox ul li a").each(function(){
			$(this).click(function(e){
				e.preventDefault();
			}).css('cursor','default');
		});
	},
	positionPointer: function(whichVote){
		voteBox.newPtrLoc = Math.ceil($("#voteBox li").find("a."+whichVote).position().left + ($("#voteBox li").find("a."+whichVote).width() / 2) - ($("#voteBox .pointer").width() / 2)); //centers pointer over box
		$("#voteBox .pointer").stop().animate({'left':voteBox.newPtrLoc},250);
	}
}
