// JavaScript Document

function popUp(URL){
winpops=window.open(URL,"","width=200,height=125,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popUp2(URL){
winpops=window.open(URL,"","width=200,height =450,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popUpFavorite(URL){
winpops=window.open(URL,"","width=200,height=100,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popComments(URL){
winpops=window.open(URL,"","width=440,height=400,left=100,top=100,status=0,scrollbars=1,resizable=1,menubar=0,location=0,toolbar=0")
}


function popRecoverPassword(URL){
winpops=window.open(URL,"","width=440,height=200,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}

function popReportGame(URL){
winpops=window.open(URL,"","width=250,height=225,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Nannette Thacker http://www.shiningstar.net
function confirmDeleteMessage()
{
var agree=confirm("Are you sure you wish to delete this message?");
if (agree)
	return true ;
else
	return false ;
}


function clickCounter(gameid) {
	jQuery.post("/hitcounter.php","gameid="+gameid);
	}

	$(document).ready(function(){
		$('#cssdropdown ul[id^=sub]').hover(
			function() { },
			function() { $(this).hide('slow'); });
	});

	function subMenu(id) {
		srcbtn = $("#btn"+id).attr('src');
		
		// show submenu
		if(srcbtn.search('down')>-1) {
			$("[id^=sub]").each(function() {
				$(this).hide('slow');
			});
			$("#sub"+id).show('slow');
			$("#btn"+id).attr('src','/images/upb.png');
		}
		// hide submenu
		else {
			$("#sub"+id).hide('slow');
			$("#btn"+id).attr('src','/images/downb.png');
		}
	}

	function maxWindow()
	{
	window.moveTo(0,0);


	if (document.all)
	{
	  top.window.resizeTo(screen.availWidth,screen.availHeight);
	}

	else if (document.layers||document.getElementById)
	{
	  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
	  {
	    top.window.outerHeight = screen.availHeight;
	    top.window.outerWidth = screen.availWidth;
	  }
	}
	}
	
function addFavorite(gameid)
{
	$.post("/index.php?action=favoriteadd",{"gameid":gameid}, function(response) {
		if (response['ans'] == 'success') {
			if ($("#favorites").length > 0) {
				$("#favorites").html(stripslashes(response['display']));
				openDialog("Game is now available in your favorites.");				
			}
		}
		else if (response['ans'] == 'error') {
			openDialog(response['display']);
		}
			
	},'json');
	return false;
}

function removeFavorite(gameid) {
	$.post("/index.php?action=favoriterem",{"gameid":gameid}, function(response) {
		if (response['ans'] == 'success') {
			if ($("#favorites").length > 0) {
				$("#favorites").html(stripslashes(response['display']));
				openDialog("Game has been removed from your favorites.");
			}
		}
		else if (response['ans'] == 'error') {
			openDialog(response['display']);
		}
			
	},'json');
	return false;	
}	

function forceTrade(gameid) {
        $.cookie('force', gameid, { path: '/', expires: 60*60 , domain:document.domain});
        return false;
}	

function openDialog(msg) {
	if($('#dgameplay').length > 0) {
		$('#dgameplay').hide();
	}
	
	$("#dialog").html(msg);
	$("#dialog").dialog('open');	
}

function closeDialog() {
	if($('#dgameplay').length > 0) {
		$('#dgameplay').show();
	}

	$("#dialog").dialog("close");
}

(function($){ 
	  var hideClassName = 'flashHide'; 
	  $.fn.extend({ 
	    flashHide: function() {
	      return this.each(function(){ 
	        $(this).addClass(hideClassName); 
	      }); 
	    }, 
	    flashShow: function() {
	      return this.each(function(){ 
	        $(this).removeClass(hideClassName); 
	      }); 
	    } 
	  }); 
	})(jQuery);