// ** Product Details ** //
function init() {
	/* START temporary testing until integration */
	//scrapbook_callback();
	/* STOP  temporary testing until integration */

	/* This code was included in global.js, not sure why, but retained it for reference */
   
	var href = document.location.href;
   
	if (href.match(/product/i)) Scrapbook.GetProduct(href, scrapbook_callback);
	else if (href.match(/kitchengallery/i)) Scrapbook.GetKitchen(href, scrapbook_callback);

}

function startInit() {
	window.setTimeout(init, 500);
}

// ** AJAX Related Calls ** //
function scrapbook_callback( response ) {


	/* START temporary testing until integration */
	/* randomly set isIncluded value */
	var isIncluded = (typeof response != "undefined") ? response.value.Included : 0;
	//var test = new Date();
	//isIncluded = test%2;
	/* STOP  temporary testing until integration */

	/* retrieve link elements */
	var add = document.getElementById("add-to-scrapbook");
	var view = document.getElementById("view-scrapbook");
	if (!add || !view) return;

	/* default assumption is to add item */
	var el = add;
	var other = view;
	
	/* switch to view if appropriate */
	if (isIncluded) {
		el = view;
		other = add;

	}
	
	/* toggle visibility */
	el.className = el.className.replace(/hide/,"");
	if (!other.className.match(/hide/)) {
		other.className += " hide";
	}
}

/* Assign onload function */
window.onload=init;

