function initMe() 
    {

		var 
		oTable = $('#searchResultsTable').dataTable( {
			"bProcessing": true,
			"bServerSide": true,
			"bStateSave" : true,
			"sAjaxSource": "/gamewatch/summarySearchJSON.php",
			"sDom": 'prt<lip><"clear">',
			"aaSorting": [[4,'desc']],
			"iDisplayLength": 25,
			"sDom": 'p<"customFilters dataTables_filter">rt<lip><"clear">',
			"aoColumns": [
				{ "mDataProp": "commonName" , sWidth : "415px" },
				{ "mDataProp": "titleType" , sWidth : "40px" },
				{ "mDataProp": "platform" , sWidth : "40px" },
				{ "mDataProp": "lowestCurrentPrice" , sWidth : "80px" },
				{ "mDataProp": "dealScore" , sWidth : "40px" },
				{ "mDataProp": "savingsScore" , sWidth : "40px" },
				{ "mDataProp": "discountFromLowestRegular" , sWidth : "40px" },
				{ "mDataProp": "averageScore" , sWidth : "40px" },
				{ "mDataProp": "averageRegularPrice" , sWidth : "50px" },
				{ "mDataProp": "lowestHistoricalPrice", sWidth : "80px"  },
				{ "mDataProp": "vendors", sWidth : "120px"   }
			],
			"bAutoWidth" : false
		/*	"aoColumns" : [
			,
			,{ sWidth : "50px" }
			{ sWidth : "50px" },
			{ sWidth : "50px" },
			{ sWidth : "50px" },
			{ sWidth : "50px" }*/
		} );

		var linkHtml='<span class="quickLink" onclick="filter_price(0,5);">Under $5</span>';
		linkHtml+='<span class="quickLink" onclick="filter_price(0,10);">Under $10</span>';
		linkHtml+='<span class="quickLink" onclick="filter_price(0,15);">Under $15</span>';
		linkHtml+='<span class="quickLink" onclick="filter_discount(50);">&gt;50% off</span>';
		linkHtml+='<span class="quickLink" onclick="filter_discount(75);">&gt;75% off</span>';
		linkHtml+='<span class="quickLink" onclick="filter_review(70);">&gt;70 Review</span>';
		linkHtml+='<span class="quickLink" onclick="filter_price_clear()">Clear</span>';
		$("div.customFilters").append(linkHtml);
		
       	$("#filter_0").change( function () {            	
        		oTable.fnFilter( $(this).val(), 0 );
        		} );
	
      	$("#filter_1").change( function () {            	
       		oTable.fnFilter( $(this).val(), 1 );
       		} );

      	if (getCookie("country") != null) {
      		$("#countrySelect").val(getCookie("country"));
      	}  	else {
      		$("#countrySelect").val("US");
      	}
      	
      	
      	$("#countrySelect").change( function () {           
          	setCookie("country",$(this).val(),10);
          	location.reload(true);       		
       		} );

      	$("#filter_2").keyup( function () {            	
       		oTable.fnFilter( $(this).val(), 2 );
       		} );

      	$("#filter_3").keyup( function () {            	
       		oTable.fnFilter( $(this).val(), 3 );
       		} );

     	$("#filter_4").keyup( function () {            	
       		oTable.fnFilter( $(this).val(), 4 );
       		} );
     	$("#filter_5").keyup( function () {            	
       		oTable.fnFilter( $(this).val(), 5 );
       		} );
      	
      	$("#searchFilter").keyup( function () {            	
       		oTable.fnFilter( $(this).val());
       		} );

       	
      	$('th[title]').qtip({  position: {
             at: 'top.center' ,  
             my: 'bottom.left' , 	
           	 viewport: $(window)	
     		 }
   		  });
        oTable.fnSetColumnVis( 8 , false);      
        oTable.fnSetColumnVis( 9, false);      
        restoreState();

	//	oTable.fnSetFilteringDelay();
    }

function restoreState() {
    var oTable = $('#searchResultsTable').dataTable();
    var settings=oTable.fnSettings();
   
    var columns=settings.aoColumns;
    for (var count = 1; count < columns.length;count++) {
        var cb=	$("#cbColShow_" + count);
			cb.prop("checked",columns[count].bVisible);        
    }

    $("#searchFilter").val(settings.oPreviousSearch.sSearch);

    var filters=settings.aoPreSearchCols;
    for (var count = 0; count < filters.length;count++) {
        var cb=	$("#filter_" + count);
        if (cb != null) {
			cb.val(filters[count].sSearch);
        }        
    }
    
		
}

function filter_price(minPrice,maxPrice) {
  	$("#filter_2").val(minPrice).keyup();
  
  	$("#filter_3").val(maxPrice).keyup();

}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function filter_review(discount) {
  	$("#filter_5").val(discount).keyup();	
}

function filter_discount(discount) {
  	$("#filter_4").val(discount).keyup();	
}
function filter_price_clear(minPrice,maxPrice,discount) {
	$('#filter_2').val('');
	$('#filter_3').val('');
	$('#filter_4').val('');
	$('#filter_5').val('');
	
	 var oTable = $('#searchResultsTable').dataTable();
  	 var oSettings=oTable.fnSettings();
  	oSettings.aoPreSearchCols[ 2 ].sSearch = "";
	oSettings.aoPreSearchCols[ 3 ].sSearch = "";
	oSettings.aoPreSearchCols[ 4 ].sSearch = "";	
	oSettings.aoPreSearchCols[ 5 ].sSearch = "";
	oTable.fnDraw();
	
 
}


function fnShowHide( iCol, state )
{
    /* Get the DataTables object again - this is not a recreation, just a get of the object */
    var oTable = $('#searchResultsTable').dataTable();
      oTable.fnSetColumnVis( iCol, state );      
}


