// JavaScript Document

var current_ctg = 0;
var current_page = 1;
var current_results = 9;
var current_subctg = "";

/*	Show/Hide Drop-Down Menu
/*----------------------------------------------------------*/
function toggleMenu(menuID){
	if($("#"+menuID+" ul").css("display") == "none"){
		$("#product-category ul ul").hide();
		$("#"+menuID+" ul").show();
	}else{
		$("#"+menuID+" ul").hide();
	}
}


/*	Update Menu Selection
/*----------------------------------------------------------*/
function updateMenu(e, menuID, value){
	e = e || window.event;
	var alink = e.target;
	var text = $(alink).text();
	
	$("#"+menuID+" li a.choice").html(text);
	toggleMenu(menuID);
	$("#loader").fadeIn();
	$("#productlist").fadeOut("fast");
	
	if(menuID == "product-subcategories"){
		if(value != null) current_subctg = value;
		else current_subctg = text;
		current_page = 1;
	}else{
		current_results = value;
	}
	$("#productlist").load("/includes/ajax/ajax_products.php", {ctg:current_ctg, page:current_page, subctg:current_subctg, results:current_results},
		function(){
			$("#productlist").fadeIn("slow");
			$("#loader").fadeOut();
		}
	);
}


/*	Product Category Paging
/*----------------------------------------------------------*/
function viewPage(num){
	$("#loader").fadeIn();
	$("#productlist").fadeOut("fast");
	current_page = num;
	$("#productlist").load("/includes/ajax/ajax_products.php", {ctg:current_ctg, page:num, subctg:current_subctg, results:current_results}, function(){
		$("#productlist").fadeIn("slow");
		$("#loader").fadeOut();
	});
}


/*	View All Results
/*----------------------------------------------------------*/
function viewAll(){
	if($("#product-results ul").css("display") != "none"){
		toggleMenu();
	}
	$("#product-subcategories li a.choice").html("All Products");
	$("#loader").fadeIn();
	$("#productlist").fadeOut("fast");
	current_page = 1;
	current_subctg = "";
	$("#productlist").load("/includes/ajax/ajax_products.php", {ctg:current_ctg, page:current_page, subctg:current_subctg, results:current_results},
		function(){
			$("#productlist").fadeIn("slow");
			$("#loader").fadeOut();
		}
	);
}


/*	Launch 360 Viewer
/*----------------------------------------------------------*/
function threesixtyViewer(id){
	window.open("/includes/view/products_360view.php?id="+id, "360 Product Viewer", "width=475, height=350, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no");	
}