    var rNum = Math.floor(Math.random()*1001) ;
    
    $(document).ready( function() {      
        $('.imageGal').contextMenu ( {
		    menu: 'myMenu'
		},
		function(action, el, pos) {
			var id = $(el).attr('id') ;
			var lot = id.substring ( 2 ) ;

			if ( action == 'magnify' )
			{
			    jQuery.facebox({ image: '/common/getscaledimage.asp?fn=/sigpieces/lots/lot'+ lot + '.jpg&ms=600&wm=1' });
			}
			else if ( action == 'bid' )
			{
				$.getJSON('lotasjson.asp?l='+lot+'&rn='+rNum, function ( lotInfo ) {
					$('#bid-form').dialog('open');							

					$('#maxbid').val ( lotInfo.nextBid ) ;
					$('#lotName').html ( lotInfo.name ) ;
					$('#lotNum').val ( lot ) ;
					$('#lotImage').attr ( 'src', '/sigpieces/lots/lot'+lot+'.jpg' ) ;															
				});						
			}
			else if ( action == 'watch' )
			{
			    jQuery.facebox({ ajax: '/auction/watchpop.asp?l=' + lot } ) ;
			}						
		});
				
		if ( jQuery.cookie ( 'AWPID' ) == null )
		{
		    $('#myMenu').disableContextMenuItems('#bid,#watch');
        }
                
        function filterPage ()
        {    
            var newQuery = $.query.set ( 'c', $('#CategoryTable').val () ).set ( 's', $('#typeTable').val () ).set ( 'page', 1 ).set ( 'PageSize', $('#pageSizeSel').val () ).toString () ;
            var pathname = $(location).attr ( 'pathname' ) ;
            
            $.cookie ( 'AWGALTYPE', $('#typeTable').val (), { expires: 1000 } ) ;
            $.cookie ( 'AWGALCAT', $('#CategoryTable').val (), { expires: 1000 } ) ;
            $.cookie ( 'AWGALLPAGESIZE', $('#pageSizeSel').val (), { expires: 1000 } ) ;
                
            $(location).attr ( 'href', pathname + newQuery ) ;                 
        }
                
        $('.optionsSel select').change ( filterPage ) ;
    });
  
  	$(function() {				
		$("#bid-form").dialog({
			autoOpen: false,
			height: 300,
			width: 400,
			modal: true,
			buttons: {
				'Place Bid': function() { 
					$(this).dialog('close') ;
					$('#bidresponse').dialog ('open') ;

					$.ajax({
					  url: 'savebidqs.asp?bidder=' + jQuery.cookie ( 'AWPID' ) + '&from=' + jQuery.cookie ( 'AWEMAIL' ) + '&lot1=' + $('#lotNum').val() + '&max1=' + $('#maxbid').val(),
					  cache: false,
					  success: function ( bidRsp){
					    $('#bidresult').html ( bidRsp );
					  }
					});					
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {

			}
		}); 
		
		$('#bidresponse').dialog({
			autoOpen: false,
			height: 280,
			width: 370,
			modal: true,
			buttons: { Ok: function () { $(this).dialog ('close') ; } }
		} ) ;
	});
