unordered_list = 1;
boolean_list = 2;
one_d_list = 3;
two_d_list = 4;

function LoadSavedSpectackle(id)
{	
jQuery.getJSON('/saved_spectackles/'+id+'.json', function(data){
          jQuery('#test_output').html(jQuery.toJSON(data));
//		  products = jQuery.secureEvalJSON(data.products_json);
		  filters =  jQuery.secureEvalJSON(data.filters_json);
		  starred_products =  jQuery.secureEvalJSON(data.products_json);
		  
			DoFilter();
			DoStar(starred_products);
			sort_field = data.sort_field;
			sort_ascending = data.sort_ascending;
			if(sort_field != "null")
			{
				SortBy(sort_field,sort_ascending);
			}
        });
	
}
function DoFilter()
{
	// filters - list of filters on this page
//	filters[attribute type id][0] - ordered list of attribute values
//  filters[attribute type id][1] - previous min slider value
//  filters[attribute type id][2] - previous max slider value
//  filters[attribute type id][3] - whether 'all' is selected

// now we have loaded  the filters, re filter them
for (var j in filters) 
	{
		if(filters[j][4]==unordered_list)
		{
			filters[j][3]=1; // need reset the filters so that it looks like we are moving from 'select all' to selecting a specific one
			// loop round the attributes for this filter
			for(var i in filters[j][5])
			{
			
				if(filters[j][5][i][0]==1 || filters[j][4]==boolean_list)
				{
					CheckBoxChecked(j,i,j,filters[j][5][i][1]);
					jQuery('.regular_checkbox_'+j).each(function() {
			this.checked = true;
				});
				}
		
				
			}
		}
	
		else if(filters[j][4]==one_d_list || filters[j][4]==two_d_list)
		{
			if(filters[j][1]!=filters[j][6] || filters[j][2]!=filters[j][7])
			{
				SliderFilter(j);
				throw_slide_event = false; // hack to stop the event firing
				if(j!='price')
				{
					min = filters[j][1];
					max = filters[j][2];
				}
				else
				{
					min = filters[j][1];
					max = filters[j][2];
				}
				 jQuery("#slider_" + j).slider("moveTo",min,0);
				 jQuery("#slider_" + j).slider("moveTo",max,1);
				throw_slide_event = true;
			}	
				
		}
		
	}
}

function SliderFilter(filter)
{
for(i=0;i<products.length;i++)
	{
			
			SliderRefineProduct(products[i],filter,filters[filter][1],filters[filter][2]);
		
	}
}

function DoStar(starred_product)
{
	for(var product_id in starred_products)
	{
		StarProduct(product_id);
	}
}

function StarProduct(product_id)
{
	if(parseInt(product_id)>1)
	{
		jQuery("#star_" +product_id).addClass('compare-checked');
		products[product_order[product_id]][4] = true;
	}
}

function LoadStarredFromUrl(products)
{
	if(products != 0)
	{
		for(var i=0;i<products.length;i++)
		{
			product_id = products[i].split('-')[0];
			StarProduct(product_id);
		}
	
	}
	
}