var firstAjaxContent = true;
	$(document).ready(function(){
		tb_show("","#TB_inline?height=auto&width=671&inlineId=loading_screen_container","", "loading");
		$("#TB_title").hide();
		var valid = 0;
		var bookID = getCookie("HD_Workbook");
			refdate = new Date();			
			$.get("workbook", { method: "visit", CacheControl: refdate.valueOf(), ID: emailWorkbookID}, function(vali){
				valid = $(vali).find('WorkbookSetting').attr('id');
				if (bookID != $(vali).find("Workbook").attr('id')) setWorkbook($(vali).find("Workbook").attr('id'));
				var workMess = $(vali).find('WorkbookMessage').text();
				if(workMess){
					load();
					var contentDiv = $("#TB_ajaxContent");
					contentDiv.empty();
					contentDiv.css({display: "none"});	
					contentDiv.append("<img src='/images/common/popup/top_bg.gif' width='671' height='26' alt=''><div id='inline-sample-content' class='thickbox_div'><p class='text_content'>"+workMess+"</p><\/div><img src='/images/common/popup/bottom_bg.gif' width='671' height='26' alt=''>");
					contentDiv.fadeIn("fast");
					$("#TB_title").show();
				} else if(parseInt(valid)>0){
					load();
				} else {
					var contentDiv = $("#TB_ajaxContent");
					contentDiv.empty();
					contentDiv.css({display: "none"});	
					contentDiv.append("<img src='/images/common/popup/top_bg.gif' width='671' height='26' alt=''><div id='inline-sample-content' class='thickbox_div'><h4>You currently have no products saved to your Workbook.</h4><p class='text_content'>Please visit Our Products to see the comprehensive line of Hunter Douglas<br />custom window fashions. There you'll be able to view complete products details<br />and <img src='/images/common/checkbox_checked.gif' alt='' width='15' height='15' /> <strong>save them<\/strong> to your Workbook.<\/p><img src='/images/my-workbook/screencap.jpg' alt='' id='screencap' width='94' height='125' /><p class='button_outline'><a href='/our-products.jsp'><span class='button_text'>Visit Our Products <img src='/images/customer-support/small_arrow_right_white.gif' alt='' width='13' height='13' /><\/span><span class='button_right'><\/span><\/a><\/p><\/div><img src='/images/common/popup/bottom_bg.gif' width='671' height='26' alt=''>");
					contentDiv.fadeIn("fast");
					$("#TB_overlay").click(tb_remove);
					$("#TB_title").show();
					$("#count").empty();
					$("#count").append("You have saved no products");					
				}
			});
	});
	
	function prepToggleContainer(){		
		if(firstAjaxContent) {
		
			 tb_remove();
			 
			 firstAjaxContent = false;
			 $('.my_workbook_products div.heading_container').unbind('click');
			 $('.details .my_workbook_products div.heading_container').toggle(
  			function () {
				var theAnchor = $(this).find("a");
				var theProductContainer  = $(this).parent().attr("id");
  				if (typeof document.body.style.maxHeight === "undefined") {
  					$("#" + theProductContainer + " .myworkbook_product_wrapper").show();
  				}
  				else{
  					$("#" + theProductContainer + " .myworkbook_product_wrapper").show(300);
				}
  				$(this).parent().addClass("expanded ");
  				theAnchor.html('<img src="images/common/small_arrow_up.png" alt="Expand Worksheet" width="13" height="13" />Hide my saved information about this product'); 
				
				
				
  			},
  			function () {
  			 	var theAnchor = $(this).find("a");
  				var theProductContainer  = $(this).parent().attr("id");
    			if (typeof document.body.style.maxHeight === "undefined") {
    				$("#" + theProductContainer + " .myworkbook_product_wrapper").hide();
  				}
  				else{
  					$("#" + theProductContainer + " .myworkbook_product_wrapper").hide(300);
  				}
  				$(this).parent().removeClass("expanded");
  				theAnchor.html('<img src="images/common/small_arrow_down.png" alt="Expand Worksheet" width="13" height="13" />Show my saved information about this product');
				});
				$('div.heading_container').hover(
				   function(){
             		  $(this).addClass("hover");
             },
         	   function(){
             		    $(this).removeClass("hover");
   			});
   			
   			clearingDiv = '<div class="clear"></div>';
			$(".photo_printable .section_container").append(clearingDiv);
			$(".my_workbook_products").append(clearingDiv)
		  }		
			
		}
		
var newProductCount = -1; 

	function remove(id, type, product_id){
		refdate = new Date();
		ref=refdate.valueOf();
		$.get("workbook", { method: "delete", SettingID: id, CacheControl: ref });
  	switch(type)
			{
			case 'product':
			  $("#workbook_products"+id).hide();
			  var productCount = $("#productCount").text();
			  newProductCount = productCount - 1;
			  $("#productCount").empty();
			  $("#productCount").append(newProductCount);
			  $("#count").empty();
			  $("#count").append("You have saved information about "+newProductCount+" Hunter Douglas product(s)");
			  break;    
			case 'gallery':
			  var galleryCount = true;
			  $("#gallery_"+id).hide();
			  var currentCount = $('#galleryCount_'+product_id).text();
			  var count = currentCount - 1;
			  $('#galleryCount_'+product_id).empty();
			  $('#galleryCount_'+product_id).append(count);
			  var itemCount = $('#itemCount_'+product_id).text();
			  var newItemCount = itemCount - 1;
			  $('#itemCount_'+product_id).empty();
			  $('#itemCount_'+product_id).append(newItemCount);
			  $('#numEntries_'+product_id).empty();
			  $('#numEntries_'+product_id).append('<p>Show my saved information about this product</p>');
			  if(newItemCount <= 0){		
				$("#remove_"+product_id).unbind('click');			  
			  	$('#expand_'+product_id).hide();
			  	$('#remove_'+product_id).show();
				galleryCount = false;
			  }
			  if (count <= 0){
			  	$('#photo_printable_div_'+product_id).hide();
			  }
			  break;
			case 'detail':
			  var detailCount = true;
			  $("#detail_container_"+id).addClass('removed'); 
			  var currentCount = $('#detailCount_'+product_id).text();
			  var count = currentCount - 1;
			  $('#detailCount_'+product_id).empty();
			  $('#detailCount_'+product_id).append(count);
			  var itemCount = $('#itemCount_'+product_id).text();
			  var newItemCount = itemCount - 1;
			  $('#itemCount_'+product_id).empty();
			  $('#itemCount_'+product_id).append(newItemCount);
			  $('#numEntries_'+product_id).empty();  
			  $('#numEntries_'+product_id).append('<p>Show my saved information about this product</p>');
			  if(newItemCount <= 0){
				$("#remove_"+product_id).unbind('click');
			  	$('#expand_'+product_id).hide();
			  	$('#remove_'+product_id).show();
				detailCount = false;
			  }
			  if (count <= 0){
			  	$('#photo_detail_div_'+product_id).hide();
			  }
			  break;
			case 'room':
			  var roomCount = true;
			  $("#room_container_"+id).addClass('removed');
			  var currentCount = $('#roomCount_'+product_id).text();
			  var count = currentCount - 1;
			  $('#roomCount_'+product_id).empty();
			  $('#roomCount_'+product_id).append(count);
			  var itemCount = $('#itemCount_'+product_id).text();
			  var newItemCount = itemCount - 1;
			  $('#itemCount_'+product_id).empty();
			  $('#itemCount_'+product_id).append(newItemCount);
			  $('#numEntries_'+product_id).empty();
			  $('#numEntries_'+product_id).append('<p>Show my saved information about this product</p>');
			  if(newItemCount <= 0){
				$("#remove_"+product_id).unbind('click');
			  	$('#expand_'+product_id).hide();
			  	$('#remove_'+product_id).show();
				roomCount = false;
			  }
			  if (count <= 0){
			  	$('#photo_roomscene_div_'+product_id).hide();
			  }
			  break;
			}
			if(!roomCount && !detailCount && !galleryCount){
				$('#expand_'+product_id).parent().parent().removeClass('expanded');
				$('#expand_'+product_id).parent().parent().parent().removeClass('details');
			}
			
	}
 	
 function getCookie (name){
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
        {
        var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
                break;
        }
return null;
}

function getCookieVal (offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
        endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

var count = 0;

function load(){
	count = 0;
	$("#innerContents").hide()
	refdate = new Date();
	//AJAX call to fetch WorkBook settings
	$.get("workbook", { method: "visit", CacheControl: refdate.valueOf()}, function(xml){
	//AJAX call to fetch all products
	$.get("content.jsp", { object: "Product", fields:"ProductTradeName,ProductDescription,ProductMainImage"},  function(prd){
		//loop through products on productid
		$(prd).find('Product').each(function(){
			var prd_id = $(this).attr('id')
			var ttl = $(this).find('ProductTradeName').text()			
			ttl = ttl.replace(/&#174;/g, "<sup>&reg;</sup>");	
			var img = $(this).find('ProductMainImage').attr('assetid')
			var desc = $(this).find('ProductDescription').text()
			desc = desc.replace(/&#174;/g, "<sup>&reg;</sup>");			
			//loop through settings on WorkbookSettingID
			    $(xml).find('WorkbookSetting').each(function(){
			    	var productPresent = false;
			    	//assign WorkBook vars
					var setting_id = $(this).attr('id')
					var product_id = $(this).find('Product').attr('id')
					var definition = $(this).find('WorkBookSettingDefinition').text()
					var settingsku = $(this).find('WorkbookSettingSKU').text()
					var settingtype = $(this).find('WorkBookSettingType').text()
					if((prd_id==product_id) && (settingsku=='') && (productPresent == false)){
						productPresent = true;
			    		productContent = '';
			    		var firstImage = true;
						$("#innerContents").empty();
						count = count + 1;							
						if(productPresent == true){	
						var productNumEntries = 0; 
						var galleryCount = 0;
						var detailCount = 0;
						var roomCount = 0;
						//var sceneCounter = 0;
						    
						    //loop through settings on WorkbookSettingID
						    $(xml).find('WorkbookSetting').each(function(){
								if((prd_id == $(this).find('Product').attr('id')) && ($(this).find('WorkBookSettingType').text() != '')){
									
									productNumEntries = productNumEntries + 1;
									var set_id = $(this).attr('id')
									var sdef = $(this).find('WorkBookSettingDefinition').text()
									var ssku = $(this).find('WorkbookSettingSKU').text()
									var stype = $(this).find('WorkBookSettingType').text()
									var sdefarray = sdef.split("&");
									if(stype == 'image'){
										galleryCount = galleryCount + 1;
										
			      							$.get("content.jsp", {object: "GalleryImage", id: ssku}, function(gal){
		
			      								$(gal).find('GalleryImage').each(function(){
			      									var image=$(this).find('GalleryImage').attr('url')
					      							var alt=$(this).find('Caption').text()
					      								if(image){
					      									
					      									$("#photo_printable_div_"+product_id).show();
					      									$("#photo_printable_"+product_id).empty();
					      									$("#photo_printable_"+product_id).append('<h3>'+ttl+' Photos</h3>');
					      						imageContent =	
					      									'<div class="section" id="gallery_'+set_id+'">'+
										      				'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
										      				'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
										      				'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
										      				'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+
										      				'<img src="images/my-workbook/photo_printable_top_glow.png" alt="" class="photo_printable_top_glow" width="220" height="5" />'+	
										      				'<img src="images/my-workbook/photo_printable_left_glow.png" alt="" class="photo_printable_left_glow" width="5" height="120" />	'+
										      				'<img src="images/my-workbook/photo_printable_bottom_glow.png" alt="" class="photo_printable_bottom_glow" width="220" height="5" />	'+
										      				'<img src="images/my-workbook/photo_printable_right_glow.png" alt="" class="photo_printable_right_glow" width="5" height="120" />'+							
										      				'<p class="remove_link"><a href="javascript:remove('+set_id+',\'gallery\','+product_id+');">Remove Photo</a></p>'+
										      				'<img src="'+image+'&height=120&width=210" alt="'+alt+'" width="210" height="120" />'+
										      				'<a href="/HunterDouglasPrint.pdf?mode=photo&'+sdef+'" title="Adobe&reg; Reader&reg is required" class="icon_and_text_link" target="_blank" rel="pdf"><img src="images/common/icon_print.png" alt="" width="22" height="21" /><span>Print Photo</span><img src="images/pdficon_small.gif" class="pdficon" alt="" width="12" height="14" /></a>'+
										      				'</div>';
										      				
										      		
													
													$("#gallery_"+product_id).hide();
													$("#gallery_"+product_id).append(imageContent);
													$("#gallery_"+product_id).show(1000);
													$("#galleryCount_"+product_id).empty();
													$("#galleryCount_"+product_id).append(galleryCount);
													$("#itemCount_"+product_id).empty();
													$("#itemCount_"+product_id).append(productNumEntries);
			      									}
	      										});
	      								
	      									});	
	      								
									}
									
									
									else if(stype == 'swatch'){
										if(sdef.search(/mode=detail/)>0){
											detailCount = detailCount + 1;										
											$.get("/php/xcart/product_xml.php", { sku:ssku }, function(skus){
												var color = $(skus).find('color_name').text()
												var item_num = $(skus).find('product_id').text()
												// var size = $(skus).find('size').text()
												// var size_label = $(skus).find('size_label').text()
												var fabric = $(skus).find('fabric_name').text()
												var fabric_label = $(skus).find('fabric_label').text()
												var material = $(skus).find('material_name').text()
												var finish = $(skus).find('finish_name').text()
												var swatch_details = '';
												// if (size != '') swatch_details += '<p><label>'+size_label+':</label> '+size+'</p>';
												if (fabric != '') swatch_details += '<p><label>'+fabric_label+':</label> '+fabric+'</p>';
												if (material != '') swatch_details += '<p><label>Material:</label> '+material+'</p>';
												if (finish != '') swatch_details += '<p><label>Finish:</label> '+finish+'</p>';
												if (color != '') swatch_details += '<p><label>Color:</label> '+color+'</p>';
												var texture_id = $(skus).find('texture_id').text().toLowerCase()
												var structure_shot = $(skus).find('structure_shot_url_id').text().toLowerCase()
												swatch_details = swatch_details.replace(/&#174;/g, "<sup>&reg;</sup>");
											
												$("#photo_detail_div_"+product_id).show();
												$("#photo_detail_"+product_id).empty();
												$("#photo_detail_"+product_id).append('<h3>'+ttl+' Detail Views</h3>');
												$("#detailCount_"+product_id).empty();
												$("#detailCount_"+product_id).append(detailCount);
												$("#itemCount_"+product_id).empty();
												$("#itemCount_"+product_id).append(productNumEntries);
								      			if(sdef.search(/tape_pcode=/)>0){
													var newSku = sdefarray[3].replace(/tape_pcode=/, "");
														$.get("/php/xcart/product_xml.php", { sku:newSku }, function(tape){
															var tapesAdd2 = $(tape).find('tapes_additional_scene7_args').text()
															var texture_id2 = $(tape).find('texture_id').text().toLowerCase()
															var tapes_render_url_id = $(skus).find('tapes_render_url_id').text()
															var tapes_additional = $(skus).find('tapes_additional_scene7_args').text()
															var swatchURL = ('http://s7d4.scene7.com/ir/render/EnlightenRender/'+tapes_render_url_id+'?wid=210&object=product&src=120x120-'+texture_id+'&'+tapes_additional+'&obj=tape&src=120x120-'+texture_id2+'&'+tapesAdd2);
															var tapeNum = $(tape).find('swatch_id').text()
															// var tapeSize = $(tape).find('size').text()
															var tapeColor = $(tape).find('color_name').text()
															
															detailContent =
												      			'<div class="section_holder" id="detail_container_'+set_id+'">'+
												      			'<div class="section" id="detail_'+set_id+'">'+
												      			'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/photo_printable_top_glow.png" alt="" class="photo_printable_top_glow" width="220" height="5" />'+	
												      			'<img src="images/my-workbook/photo_printable_long_left_glow.png" alt="" class="photo_printable_left_glow" width="5" height="156" />	'+
												      			'<img src="images/my-workbook/photo_printable_bottom_glow.png" alt="" class="photo_printable_bottom_glow" width="220" height="5" />	'+
												      			'<img src="images/my-workbook/photo_printable_long_right_glow.png" alt="" class="photo_printable_right_glow" width="5" height="156" />'+								
												      			'<p class="remove_link"><a href="javascript:remove('+set_id+',\'detail\','+product_id+');">Remove Photo</a></p>'+
												      			'<img src="'+swatchURL+'" alt="" width="210" height="156"  class="product_shot" />'+
												      			'</div>'+
												      			'<div class="section" id="detail_wide_'+set_id+'">'+
												      			'<p><label>Item Number:</label> '+item_num+'</p>'+
															swatch_details +
												      			'<p class="icon_and_text_link_container">'+
											      				'<p><label>Tape Item Number:</label> '+tapeNum+'</p>'+
											      				'<p><label>Tape Color:</label> '+tapeColor+'</p>'+
											      				'</p>'+
												      			'<p class="icon_and_text_link_container">'+
												      			'<a href="/HunterDouglasPrint.pdf?'+sdef+'" title="Adobe&reg; Reader&reg is required" target="_blank" ref="pdf" class="icon_and_text_link text_print_photo"><img src="images/common/icon_print.png" alt="" width="22" height="21" /><span>Print Detail View</span><img src="images/pdficon_small.gif" class="pdficon" alt="" width="12" height="14" /></a>'+
												      			'<a href="javascript:getiMagineLinkQS(\''+escape(sdef)+'\');" class="icon_and_text_link text_open_imagine_design_center"><img src="images/common/icon_imagine.png" alt="" width="13" height="21" class="imagine_logo" /><span>Open iMagine Design Center</span></a>'+
												      			'</p>'+
												      			'</div>'+
												      			'</div>';																
												      			//$("#detail_"+product_id).hide();		
																$("#detail_"+product_id).append(detailContent);
												      			//$("#detail_"+product_id).show(300);
															});
													}else{
														detailContent =
																'<div class="section_holder" id="detail_container_'+set_id+'">'+
																'<div class="section" id="detail_'+set_id+'">'+
												      			'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+
												      			'<img src="images/my-workbook/photo_printable_top_glow.png" alt="" class="photo_printable_top_glow" width="220" height="5" />'+	
												      			'<img src="images/my-workbook/photo_printable_long_left_glow.png" alt="" class="photo_printable_left_glow" width="5" height="156" />	'+
												      			'<img src="images/my-workbook/photo_printable_bottom_glow.png" alt="" class="photo_printable_bottom_glow" width="220" height="5" />	'+
												      			'<img src="images/my-workbook/photo_printable_long_right_glow.png" alt="" class="photo_printable_right_glow" width="5" height="156" />'+								
												      			'<p class="remove_link"><a href="javascript:remove('+set_id+',\'detail\','+product_id+');">Remove Photo</a></p>'+
																'<img src="http://s7d4.scene7.com/is/image/Enlighten/'+structure_shot+'?wid=210" alt="" width="210" height="156"  class="product_shot" />'+
																'</div>'+
												      			'<div class="section" id="detail_wide_'+set_id+'">'+
												      			'<p><label>Item Number:</label> '+item_num+'</p>'+
															swatch_details +
												      			'<p class="icon_and_text_link_container">'+
												      			'<a href="/HunterDouglasPrint.pdf?'+sdef+'" title="Adobe&reg; Reader&reg is required" target="_blank" ref="pdf" class="icon_and_text_link text_print_photo"><img src="images/common/icon_print.png" alt="" width="22" height="21" /><span>Print Detail View</span><img src="images/pdficon_small.gif" class="pdficon" alt="" width="12" height="14" /></a>'+
												      			'<a href="javascript:getiMagineLinkQS(\''+escape(sdef)+'\');" class="icon_and_text_link text_open_imagine_design_center"><img src="images/common/icon_imagine.png" alt="" width="13" height="21" class="imagine_logo" /><span>Open iMagine Design Center</span></a>'+
												      			'</p>'+
												      			'</div> '+
												      			'</div> ';																
												      			$("#detail_"+product_id).append(detailContent);
													}													
								      		});
								      	}else if(sdef.search(/mode=room/)>0){
								      		roomCount = roomCount + 1;
								      		$.get("/php/xcart/product_xml.php", { sku:ssku }, function(skus){
												var color = $(skus).find('color_name').text()
												var item_num = $(skus).find('product_id').text()
												// var size = $(skus).find('size').text()
												// var size_label = $(skus).find('size_label').text()
												var fabric = $(skus).find('fabric_name').text()
												var fabric_label = $(skus).find('fabric_label').text()
												var material = $(skus).find('material_name').text()
												var finish = $(skus).find('finish_name').text()
												var scene7rv = $(skus).find('additional_scene7_rv_arguments').text()
												var swatch_details = '';
												// if (size != '') swatch_details += '<p><label>'+size_label+':</label> '+size+'</p>';
												if (fabric != '') swatch_details += '<p><label>'+fabric_label+':</label> '+fabric+'</p>';
												if (material != '') swatch_details += '<p><label>Material:</label> '+material+'</p>';
												if (finish != '') swatch_details += '<p><label>Finish:</label> '+finish+'</p>';
												if (color != '') swatch_details += '<p><label>Color:</label> '+color+'</p>';
												var texture_id = $(skus).find('texture_id').text().toLowerCase()
												var structure_shot = $(skus).find('structure_shot_url_id').text().toLowerCase()
												swatch_details = swatch_details.replace(/&#174;/g, "<sup>&reg;</sup>");
								      	
								      		$("#photo_roomscene_div_"+product_id).show();
											$("#roomscene_"+product_id).empty();
											$("#roomscene_"+product_id).append('<h3>'+ttl+' Room Scenes</h3>');
											$("#roomCount_"+product_id).empty();
											$("#roomCount_"+product_id).append(roomCount);
											$("#itemCount_"+product_id).empty();
											$("#itemCount_"+product_id).append(productNumEntries);
								      		if(sdef.search(/tape_pcode=/)>0){
								      			var newSku = sdefarray[3].replace(/tape_pcode=/, "");
													$.get("/php/xcart/product_xml.php", { sku:newSku }, function(tape){
														var texture_id2 = $(tape).find('texture_id').text()
														var tapeNum = $(tape).find('swatch_id').text()
														// var tapeSize = $(tape).find('size').text()
														var tapeColor = $(tape).find('color_name').text()
									      				if (sdefarray[4] == 'room=b'){
															var swatchURL = 
															('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
															$(skus).find('bedroom_tapes_url_id').text() +
															'-1500?wid=210&obj=bedroom_treatment&src='+texture_id+'&'+scene7rv+'&obj=bedroom_tape&src='+texture_id2);
															for (var $s=5; $s < sdefarray.length; $s++){
																var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
																if (string !=''){
																swatchURL += string;
																}
															}
														}else if (sdefarray[4] == 'room=k'){
															var swatchURL = 
															('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
															$(skus).find('kitchen_tapes_url_id').text() +
															'-1500?wid=210&obj=kitchen_treatment&src='+texture_id+'&'+scene7rv+'&obj=kitchen_tape&src='+texture_id2);
															for (var $s=5; $s < sdefarray.length; $s++){
																var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
																if (string !=''){
																swatchURL += string;
																}
															}
														}else if (sdefarray[4] == 'room=l'){
															var swatchURL = 
															('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
															$(skus).find('living_room_tapes_url_id').text() +
															'-1500?wid=210&obj=living_treatment&src='+texture_id+'&'+scene7rv+'&obj=living_tape&src='+texture_id2);
															for (var $s=5; $s < sdefarray.length; $s++){
																var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
																if (string !=''){
																swatchURL += string;
																}
															}
														}
																									      	
												      	sceneContent =
												      				'<div class="section_holder" id="room_container_'+set_id+'">'+
												      				'<div class="section" id="room_'+set_id+'">'+
												      				'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
												      				'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
												      				'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
												      				'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+
												      				'<img src="images/my-workbook/photo_printable_top_glow.png" alt="" class="photo_printable_top_glow" width="220" height="5" />'+	
												      				'<img src="images/my-workbook/photo_printable_long_left_glow.png" alt="" class="photo_printable_left_glow" width="5" height="156" />	'+
												      				'<img src="images/my-workbook/photo_printable_bottom_glow.png" alt="" class="photo_printable_bottom_glow" width="220" height="5" />	'+
												      				'<img src="images/my-workbook/photo_printable_long_right_glow.png" alt="" class="photo_printable_right_glow" width="5" height="156" />'+			
												      				'<p class="remove_link"><a href="javascript:remove('+set_id+',\'room\','+product_id+');">Remove Photo</a></p><img src="'+swatchURL+'" alt="" width="210" height="156" class="product_shot" />'+
												      				'</div>'+
												      				'<div class="section" id="room_wide_'+set_id+'">'+
												      				'<p><label>Item Number:</label> '+item_num+'</p>'+
																swatch_details +
												      				'<p class="icon_and_text_link_container">'+
												      				'<p><label>Tape Item Number:</label> '+tapeNum+'</p>'+
																    '<p><label>Tape Color:</label> '+tapeColor+'</p>'+
												      				'</p>'+
												      				'<p class="icon_and_text_link_container">'+
												      				'<a href="/HunterDouglasPrint.pdf?'+sdef+'" target="_blank" title="Adobe&reg; Reader&reg is required" ref="pdf" class="icon_and_text_link text_print_photo"><img src="images/common/icon_print.png" alt="" width="22" height="21" /><span>Print Room View</span><img src="images/pdficon_small.gif" class="pdficon" alt="" width="12" height="14" /></a>'+
												      				'<a href="javascript:getiMagineLinkQS(\''+escape(sdef)+'\');" class="icon_and_text_link text_open_imagine_design_center"><img src="images/common/icon_imagine.png" alt="" width="13" height="21" class="imagine_logo" /><span>Open iMagine Design Center</span></a>'+
												      				'</p>'+
												      				'</div>'+
												      				'</div>';
																	$("#room_"+product_id).append(sceneContent);
								      			});
								      		
											}else{						      		
								      		
								      			if (sdefarray[3] == 'room=b'){
													var swatchURL = 
													('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
													$(skus).find('bedroom_url_id').text() +
													'-1500?wid=210&obj=bedroom_treatment&src='+texture_id+'&'+scene7rv);
													for (var $s=4; $s < sdefarray.length; $s++){
														var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
														if (string !=''){
														swatchURL += string;
														}
													}
												}else if (sdefarray[3] == 'room=k'){
													var swatchURL = 
													('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
													$(skus).find('kitchen_url_id').text() +
													'-1500?wid=210&obj=kitchen_treatment&src='+texture_id+'&'+scene7rv);
													for (var $s=4; $s < sdefarray.length; $s++){
														var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
														if (string !=''){
														swatchURL += string;
														}
													}
												}else if (sdefarray[3] == 'room=l'){
													var swatchURL = 
													('http://s7d4.scene7.com/ir/render/EnlightenRender/'+
													$(skus).find('living_room_url_id').text() +
													'-1500?wid=210&obj=living_treatment&src='+texture_id+'&'+scene7rv);
													for (var $s=4; $s < sdefarray.length; $s++){
														var string = '&obj='+sdefarray[$s].replace(/_textureid=/, "&src=");
														if (string !=''){
														swatchURL += string;
														}
													}
												}
										sceneContent =
							      				'<div class="section_holder" id="room_container_'+set_id+'">'+
							      				'<div class="section" id="room_'+set_id+'">'+
							      				'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
							      				'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
							      				'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
							      				'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+
							      				'<img src="images/my-workbook/photo_printable_top_glow.png" alt="" class="photo_printable_top_glow" width="220" height="5" />'+	
							      				'<img src="images/my-workbook/photo_printable_long_left_glow.png" alt="" class="photo_printable_left_glow" width="5" height="156" />	'+
							      				'<img src="images/my-workbook/photo_printable_bottom_glow.png" alt="" class="photo_printable_bottom_glow" width="220" height="5" />	'+
							      				'<img src="images/my-workbook/photo_printable_long_right_glow.png" alt="" class="photo_printable_right_glow" width="5" height="156" />'+			
							      				'<p class="remove_link"><a href="javascript:remove('+set_id+',\'room\','+product_id+');">Remove Photo</a></p><img src="'+swatchURL+'" alt="" width="210" height="156" class="product_shot" />'+
							      				'</div>'+
							      				'<div class="section" id="room_wide_'+set_id+'">'+
							      				'<p><label>Item Number:</label> '+item_num+'</p>'+
											swatch_details +
							      				'<p class="icon_and_text_link_container">'+
							      				'<a href="/HunterDouglasPrint.pdf?'+sdef+'" target="_blank" ref="pdf" class="icon_and_text_link text_print_photo"><img src="images/common/icon_print.png" alt="" width="22" height="21" /><span>Print Room View</span><img src="images/pdficon_small.gif" class="pdficon" alt="" width="12" height="14" /></a>'+
							      				'<a href="javascript:getiMagineLinkQS(\''+escape(sdef)+'\');" class="icon_and_text_link text_open_imagine_design_center"><img src="images/common/icon_imagine.png" alt="" width="13" height="21" class="imagine_logo" /><span>Open iMagine Design Center</span></a>'+
							      				'</p>'+
							      				'</div>'+
							      				'</div>';
											$("#room_"+product_id).append(sceneContent);
							      				}
							      			});
							      		}
							      	}
							    }
					      	});							
																				
					      	productContent +='<div class="my_workbook_products_container"><div class="my_workbook_products" id="workbook_products'+setting_id+'">'+
										'<div class="heading_container">'+
										'<h2>Product Name <span>'+ttl+'</span></h2>'+
										'<div id="expand_'+product_id+'"><a href="#product'+setting_id+'_wrapper" id="product'+setting_id+'_expandbutton" class="expand_button"><img src="images/common/small_arrow_down.png" alt="Expand Worksheet" width="13" height="13" />Show my saved information about this product</a></div>'+
										'</div>'+ 
								      	'<div class="photo_featured">'+
								      	'<div class="featured_photo_img">'+
										'<img src="images/my-workbook/image_coverup_top_left_corner.gif" class="image_coverup_top_left_corner" alt="" width="3" height="3" />'+
										'<img src="images/my-workbook/image_coverup_top_right_corner.gif" class="image_coverup_top_right_corner" alt="" width="3" height="3" />'+
										'<img src="images/my-workbook/image_coverup_bottom_left_corner.gif" class="image_coverup_bottom_left_corner" alt="" width="3" height="3" />'+
										'<img src="images/my-workbook/image_coverup_bottom_right_corner.gif" class="image_coverup_bottom_right_corner" alt="" width="3" height="3" />'+ 
								      	'<img src="/php/asset.php?id='+img+'&height=132&width=240" alt="" width="240" height="132" /></div>'+
								      	'<p class="featured_photo_copy">'+desc+'</p>'+
								      	'<p class="button_outline text_view_product_page" style=""><a href="our-products-detail.jsp?id='+product_id+'">View Product Page</a></p>';
								      	
								      	// added for the spring 2009 special promotion
								      	if(product_id == 53 || product_id == 6 || product_id == 1 || product_id == 4){
								      	//if(false){
								      		productContent += '<p class="button_outline text_special_promotion" style=""><a href="/2010spring">Energy Efficient Promotion</a></p>';
								      		// if (product_id == 53 || product_id == 3 || product_id == 35 || product_id == 6) productContent += '<p class="button_outline text_special_promotion2" style=""><a href="/childsafety">Season of Giving Free LiteRise<sup>&reg;</sup> Promotion</a></p>';
								      	} else {
											baitWait("WWW=MyWorkbook",product_id);
										}
								      	// end special promo addition
								      	
					  productContent += '<p class="button_gray text_print_product_summary" style=""><a href="/HunterDouglasPrint.pdf?mode=product&id='+product_id+'" title="Adobe&reg; Reader&reg is required" rel="pdf" target="_blank">Print Product Summary</a></p>'+
								      	'<div id="remove_'+product_id+'"><p class="button_gradient text_remove_product" style=""><a href="javascript:remove('+setting_id+',\'product\');"><span class="button_text">Remove Product</span><span class="button_right"><span class="button_right_content"></span></span></a></p></div>'+
								     	'</div>'+
								      	'<div id="product_'+product_id+'_innerContent" class="myworkbook_product_wrapper">'+
								      	'<div id="galleryCount_'+product_id+'"></div><div id="detailCount_'+product_id+'"></div><div id="roomCount_'+product_id+'"></div><div id="itemCount_'+product_id+'"></div>'+
					     				'<div id="photo_printable_div_'+product_id+'">'+
					     				'<div class="photo_printable"><div id="photo_printable_'+product_id+'"></div>'+
					     				'<div class="section_container" id="gallery_'+product_id+'">'+									
										'</div>'+
										'</div>'+
										'</div>'+
										'<div id="photo_detail_div_'+product_id+'">'+
										'<div class="photo_detail"><div id="photo_detail_'+product_id+'"></div>'+
										'<div class="section_container" id="detail_'+product_id+'">'+
										'<div></div>' +
										'</div>'+
										'</div>'+
										'</div>'+
										'<div id="photo_roomscene_div_'+product_id+'">'+
										'<div class="photo_roomscene"><div id="roomscene_'+product_id+'"></div>'+
							      		'<div class="section_container" id="room_'+product_id+'">'+										
										'</div>'+										
							    		'</div>'+
					      				'</div>'+										
					      				'</div>'+
					      				'</div>'+
					      				'</div>';					      																				
										
					      				$("#contents").append(productContent);
					      				$("#photo_printable_div_"+product_id).hide()
										$("#photo_detail_div_"+product_id).hide()
										$("#photo_roomscene_div_"+product_id).hide()
										$('#galleryCount_'+product_id).hide()
										$('#detailCount_'+product_id).hide()
										$('#roomCount_'+product_id).hide()
										$('#itemCount_'+product_id).hide()
										$('#productCount').hide()
										if (productNumEntries > 0){
 											$("#remove_"+product_id).click(function(event){
													var c = confirm("You currently have items associated with this product.\n\nIf you remove this product, all saved items for this product will also be removed. Do you want to continue?");
													if(!c){event.preventDefault();}
											});
											$("#expand_"+product_id).show()
											$('#expand_'+product_id).parent().parent().parent().addClass('details');
										} else {
										$("#remove_"+product_id).show()
										$("#expand_"+product_id).hide()
										}
					      }
					    } 
					    if((product_id == "0") && ($("#starter").text() == '')) {
						    $("#starter").append('<div id="my_workbook_starter_guide">'+
								'<div class="heading_container">'+
								'<h2>Starter Guide <span>Things to Consider Summary</span></h2>'+
								'<p class="button_outline text_view_summary" style=""><a href="'+definition+'"><span class="button_text">View Summary <img src="images/common/small_arrow_right.png" alt="" width="13" height="13" /></span><span class="button_right"><span class="button_right_content"></span></span></a></p>'+
								'</div>'+		
								'</div>');		
						}	
						
						
						 
						$("#count").empty();
						$("#count").append("You have saved information about "+count+" Hunter Douglas product(s)");
						$("#productCount").empty();
						$("#productCount").append(count);
					});
				});
			});
		});
		$("#contents").ajaxStop(prepToggleContainer);
			
	}
