function featured_overlay(x){
	switch(x)
				{
					case "Featured Item":
					return '/site/images/featured-overlay.gif';
					break;					
					case "Christmas Sale":
					return '/images/graphics/christmas-overlay.png'; 
					break;					
					 case "NewYears":
					return '/images/graphics/gold-overlay.png'; 
					break;			 
					case "Winter Sale":
					return '/images/graphics/winter-blowout-overlay.png'; 
					break;			 
					case "Spring Sale":
					return '/images/graphics/Overlay-Spring.png'; 
					break;			
					case "Fathers Day":
					return '/images/graphics/Overlay-Fathers.png'; 
					break;			
					case "July4th":
					return '/images/graphics/Overlay-July4th.png'; 
					break;			
					case "Summer Days":
					return '/images/graphics/Overlay-SummerDays.png'; 
					break;			
					case "Fall Sale":
					return '/images/graphics/Overlay-FallSale.png'; 
					break;			
					case "Thanksgiving":
					return '/images/graphics/Overlay-Thanksgiving.png'; 
					break;			
					case "Outlet Item":
					return '/images/graphics/Overlay-Outlet.png'; 
					break;			
					case "Warehouse Sale":
					return '/images/graphics/Overlay-WarehouseSale.png'; 
					break;
					case "Free Gift":
					return '/images/graphics/Overlay-FreeGift.png'; 
					break; 
					case "Made In USA":
					return '/images/graphics/Overlay-MadeInTheUSA.png'; 
					break;   
					case "Black Friday":
					return '/images/graphics/Overlay-BlackFriday.png'; 
					break;    
					case "Cyber Monday":
					return '/images/graphics/Overlay-CyberMonday.png'; 
					break;    
					case "Outdoor Room Sale":
					return '/images/graphics/Overlay-outdoorroomsale.png'; 
					break;      
					case "Christmas Hearth and Home":
					return '/images/graphics/overlay_christmas_hearth_sale.png'; 
					break;      
					case "Complete Fireplace Sale":
					return '/images/graphics/overlay_complete_fireplace_sale.jpg'; 
					break;      
					case "Early Bird Wood Stove Sale":
					return '/images/graphics/overlay_early_bird_woodstove_sale.png'; 
					break;      
					case "Ethanol Fireplace Sale":
					return '/images/graphics/overlay_ethanolfireplacesale.png'; 
					break;      
					case "Fireplace Grate Sale":
					return '/images/graphics/overlay_fireplace_grate_sale.png'; 
					break;      
					case "Firewood Rack Sale":
					return '/images/graphics/overlay_firewood_rack_sale.png'; 
					break;      
					case "Warm-Up Wood Stove Sale":
					return '/images/graphics/overlay_warmup_woodstove_sale175px.png'; 
					break;        
					case "Chimney Prep Sale":
					return '/images/graphics/overlay_chimney_prep_sale.png'; 
					break;          
					case "EcoSmart":
					return '/images/graphics/Overlay_ecosmart15percent175.png'; 
					break; 
					case "Best Value":
					return '/images/graphics/overlay_centuryws175px.png'; 
					break;  
					case "Blower Sale":
					return '/images/graphics/overlay_warmup_woodstove_blower175px.png'; 
					break;
					case "Show List Price":
					return ''; 
					break; 
				}
				return '';
}
function Item(x){
	this.cell = x;
	this.id = '';
	this.number = '';
	this.name = '';
	this.type = '';
	this.matrix = '';
	this.display_price = '';
	this.description = '';
	this.images = new Array();
	this.url = '';
	this.overlay = '';
	this.info_links = new Array();
	this.pop_ups = new Array();
	this.fill_me = function(el){
		var data = $('.data',el).html().split('|');
		var fields = $('.fields',el).html().split('|'); 
		this.id = data[0];
		this.name = data[1];
		this.type = data[2];
		this.matrix = data[3];
		this.display_price = data[4];
		this.description = data[5];
		this.images = data[6].split(':');
		this.url = data[7];
		this.overlay = data[8];
		this.info_links = data[9].split(':');
		this.pop_ups = data[10].split(':');
	};
	this.fill_me(x);
}
//standard functions
function format_price(x){			
	x = (x.toString().indexOf('$') == -1) ? '$' + x : x;
	x = (x.indexOf('.') == -1) ? x + '.00' : x;
	x = (x.length - x.indexOf('.') >= 3)? x : x + '0';
	x = (x.length - x.indexOf('.') > 3)? x.substring(0,x.indexOf('.')+3) : x;
	return x;
}
function normal_pop_up(url) {
	window.open(url, 'zoom', 'status,scrollbars,resizable=yes,width=720,height=620,left=100,top=90');
}
function popVOD(url) {
	var config = '';
    var newwindow = window.open(url, 'newwindow', config='height=595,width=695, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
    if(newwindow.blur) {newwindow.focus();}
}
function update_qty(qty, element) { //updates the qty of the item with the internal id = element
	element = '#qtydiv' + element;
	$(element).children('#c_selectqty').val(qty).change();
}
function retrieve_qty(element) {
	element = '#qtydiv' + element;
	return $(element).children('#c_selectqty').val();
}
//template control script
$(document).ready(function () {	
	var phonechange = true;
	//Reveal pop up - apply class 'reveal' to an element, add an additional class of 'reveal_'+'id of item to reveal'
	$('.reveal').each(function () {
							   $(this).click(function (e) {
									var new_id = $(this).attr('id');
									//backwards compatible with previous version relying on id's beginning with 'reveal_'
									if (new_id.indexOf('reveal_')+1){
										new_id = '#' + new_id.replace('reveal_','');
									}else{
										var classes = $(this).attr('class').split(' ');
										for(j=classes.length;j--;){
											if(classes[j].indexOf('reveal_')+1){
												new_id = '#' + classes[j].replace('reveal_','');
												break;
											};
										}
									}
									$(new_id).show();
									$(new_id).trigger('on_reveal',[$(this),e]);
									e.preventDefault;
								});
					});	
	//Close pop up - apply class 'close' to an element, set an additional class to 'close_'+'id of item to close'
	$('.close').each(function () {
							   $(this).click(function (e) {
									var new_id = $(this).attr('id');
									if (new_id.indexOf('close_')+1){
										new_id = '#' + new_id.replace('close_','');
									}else{
										var classes = $(this).attr('class').split(' ');
										for(i=classes.length;i--;){
											if(classes[i].indexOf('close_')+1){
												new_id = '#' + classes[i].replace('close_','');
												break;
											};
										}
									}
									$(new_id).hide();
									$(new_id).trigger('on_close');
									e.preventDefault;
								});
					});
	//Learning Center Link Menu
	$('div.roll_over_menu > a > img').each(function () {
												$(this).mouseenter(function () {
													  var new_src = $(this).attr('src').replace('-Static','-Hover');
													  $(this).attr('src',new_src);
													  })
									   			.mouseleave(function () {
													  var new_src = $(this).attr('src').replace('-Hover','-Static');
													  $(this).attr('src',new_src);
													  });
												});
	//Draggable
	$('.dragme').each(function () {
							   	$(this).draggable({
												  handle: '#drag_handle',
												  containment: [0,0,2000,9999]
												  });
							   	});
	$('.dragme_gallery').each(function () {
							   	$(this).draggable({
												  handle: '#drag_gallery_handle',
												  containment: [0,0,2000,9999]
												  });
							   	});
	$('.dragme_movie').each(function () {
								var pq = $(this).closest('div.internal_id').attr('id');
							   	$(this).draggable({
												  handle: '#drag_movie_handle_' + pq,
												  containment: [0,0,2000,9999]
												  });
							   	});
	//Hide Accessory Items if Configured	
	allInternalIds = [];
	$("input[name='buyid']").each(function(index) {
					 		allInternalIds[index] = parseInt(this.value);
	});
 //find all internal ids on the page
    var configtest = false; //find if the page is configured
	
	var temp_length = allInternalIds.length;
	for(i=0;i<temp_length;i++) {
		var a = allInternalIds[i];
        var b = $('#configured'+a);	
        if(b.length) { 
        	if(b.val() == 'Configured' || b.val() == 'configured')configtest = true;
       	} 
	}
    for(i=0;i<temp_length;i++) {
        var a = allInternalIds[i];
        var b = $('#Display_'+a);	
        if(b.length && configtest) {
			if(b.val() == 'no' || b.val() == 'No' || b.val() == 'False' || b.val() == 'false')	{
				$('#Display_'+a).parents('tr:first').hide();	
			}
		}
     } 
	
	//Pop-Ups
	$('img.canada_easy').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-CanadaEasy.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	$('img.made_in_usa').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-MadeInUSA.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	$('img.customer_choice').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-CustomerChoice.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	$('img.eco_safe').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-Eco.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	$('img.woodland_exclusive').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-Exclusive.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	$('img.quick_ship').click(function () {
				window.open('http://www.woodlanddirect.com/site/htmldocuments/Highlight-QuickShip.html','newwindow', config='height=500,width=500,top=200,left=200 toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
	});
	
	
	var temp_id = '';
	var temp_txt = '';
	//Grid View Functions
	if($('#gridview').length) {
		//phone number for grid view
		if(phonechange){
			var data = $('.data_technical');
			var yes = 0;
			var no = 0;
			var qty = data.length;
			for (i=0;i<qty;i++){
				if("yes" == $(data[i]).html()){
					yes++;
				}else{no++;}
			}
			if (no > yes) {
				$(".phone_number").each(function(){
					$(this).html("877.919.1904");
				});
			}
			else {
				$(".phone_number").each(function(){
					$(this).html("800.919.1904");
				});
			}
		}
		var internalId = '';
		var item_id = '';
		var featured = '';
		var store_url = '';
		var price = '';
		var lrg_image = '';
		var list_price = '';
		var configured = '';
		var pop_gallery = '';
		var available = '';
		var qty_available = '';
		var show_sale_price = false;
		var sale_image = '';
		var rfq = '';
		var prc_suff = '';
		var video = '';
		var hide_matrix = false;
		
		$('.data_featured').each(function () {
			featured = $(this).html();
			internalId = $(this).parent('div').parent('div').attr('id');
			temp_id = '#'+internalId;
			item_id = $(temp_id).find('span.data_item_id').html();
			store_url = $(temp_id).find('span.data_store_url').html(); 
			price = $(temp_id).find('span.data_price').html(); 
			list_price = $(temp_id).find('span.data_list_price').html(); 
			configured = $(temp_id).find('span.data_configured').html(); 
			pop_gallery = $(temp_id).find('span.data_pop_gallery').html(); 
			available = $(temp_id).find('span.data_available').html(); 
			qty_available = $(temp_id).find('span.data_qty_available').html(); 
			rfq = ($(temp_id).find('span.data_rfq').html() === 'RFQ') ? 'Yes':'No'; 
			npm = $(temp_id).find('span.data_npm').html();
			prc_suff = ' ' + $(temp_id).find('span.data_prc_suff').html();
			brand_overlay = $(temp_id).find('span.data_brand_overlay').html();
			other_overlay = $(temp_id).find('span.data_other_overlay').html();
			show_sale_price = (featured != '' && featured != 'Free Gift' && featured != 'Show List Price' ) ? true : false;
			hide_msrp = ($(temp_id).find('span.data_msrp').html() == 'Yes')?true:false;
			hide_matrix = ($(temp_id).find('span.data_hide_matrix_options').html()== 'Yes') ? true : false;
			//Featured Item Overlay and Sale Item Overlay
			if(featured != '') {
				sale_image = featured_overlay(featured);
				if(sale_image != '')$(temp_id).find('div.grid_sale_overlay').html('<a href="' + store_url + '"><img src="' + sale_image + '"></a>');
			}
			//Item Brand Overlay
			if(brand_overlay != '') {
				$(temp_id).find('div.grid_brand_overlay').html('<a href="' + store_url + '"><img src="/images/graphics/overlay/brand/' + brand_overlay + '"></a>');
			}
			//Item Brand Overlay
			if(other_overlay != '') {
				$(temp_id).find('div.grid_other_overlay').html('<a href="' + store_url + '"><img src="/images/graphics/overlay/other/' + other_overlay + '"></a>');
			}
			if($(temp_id).find('span.data_standard_brand').html().length){
				var bparent = $(temp_id).parents('td.grid_cell');
				$(bparent).find('.grid_brand').find('img').attr('src','/images/graphics/brand/'+$(bparent).find('span.data_standard_brand').html()+'.png');
				$(bparent).find('.grid_brand').show();
			}
			//Movie Button Video Button
			var check_video = $(temp_id).find('span.data_grid_view_video').html();
			if(check_video)if(check_video.length > 0)	$(temp_id).find('div.grid_video').show();
			$(temp_id).find('img.access_movie').click(function (e) {
																	var temp_qv_id = $(this).parents('.internal_id').attr('id');
																	var video_width = 426;
																	var video_height = 240;
																	var video_url = 'http://video.woodlanddirect.com/Videos/GridViewVideos/'+ $('div#'+temp_qv_id).find('span.data_grid_view_video').html();	
																	var code = '<object classid="' +video_url+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+video_width+'" height="'+video_height+'" align="middle"><param name="scale" value="showall" />	<param name="movie" value="http://video.woodlanddirect.com/videos/GridViewVideos/'+video_url+'" />    <embed src="'+video_url+'" width="'+video_width+'" height="'+video_height+'" scale="showall" align="middle" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />	</object>';
																	$('#movie_container_'+temp_qv_id).empty();
																	$('#movie_container_'+temp_qv_id).append(code);
																	//position and fade in the QV
																	var y = e.pageY - 140; //could be dynamic
																	var x = e.pageX - 250;
																	$('#movie_gallery_'+temp_qv_id)
																		.css('left',x+'px').css('top',y+'px')
																		.appendTo('body').fadeIn('medium');
																   });
			$(temp_id).find('div.movie_gallery_close p').click(function (e) {
																	var temp_qv_id = $(this).parents('.movie_gallery').fadeOut('fast');
																   });
			//RFQ Shipping Override
			if(rfq == 'Yes') {
				$(temp_id).find('p.grid_shipping').html('Set your home apart!').css('font-size','10px');
			}
			//Availability
			if(rfq == 'Yes') {
				temp_txt = 'Our experts are waiting to assist you';
				$(temp_id).find('p.grid_availability').css('font-size','10px');
			} else if (item_id.indexOf('K') != -1 && parseInt(qty_available) > 1) {
				temp_txt = 'In Stock';
			} else if (item_id.indexOf('K') == -1 && available.substr(0, 4) != "Back") {
				temp_txt = available;
			} else if (item_id.indexOf('N') == -1 && available.substr(0, 4) != "Back") {
				temp_txt = 'In Stock';
			} else {
				temp_txt = '<strong>Backordered</strong>';
			}
			$(temp_id).find('p.grid_availability').html(temp_txt);
			tempt_txt = '';
			
			//list price
			var list_price_obj;
			var calc_list = false; //if the list price is set to display based on the category it is in then also set the sale price variable to true
			if($(temp_id).find('div.grid_list_price').length){
				list_price_obj = $(temp_id).find('div.grid_list_price');
			}else if($(temp_id).find('div.grid_list_price_NO').length){
				list_price_obj = $(temp_id).find('div.grid_list_price_NO');
			}else if($(temp_id).find('div.grid_list_price_YES').length){
				list_price_obj = $(temp_id).find('div.grid_list_price_YES');
				show_sale_price = true;
				calc_list = true;
			}else if($(temp_id).find('div.grid_list_price_Yes').length){
				list_price_obj = $(temp_id).find('div.grid_list_price_Yes');
				calc_list = true;
				show_sale_price = true;
			}
			if(show_sale_price || calc_list) {
				$(list_price_obj).show();
				if(list_price != '') {
					temp_txt = '$' + list_price;
			   	} else{
				   	list_price = parseInt(price.replace(/[$,]/g,''));
				   	list_price = Math.round((list_price/.75)*100)/100;
				   	temp_txt = '$' + list_price;
			   	}
				temp_txt = (temp_txt=='$NaN') ? 'Varies' : temp_txt; //matrix hack
				$(list_price_obj).children('span.data').html(temp_txt);
				temp_txt = '';
			} else if(rfq != 'Yes') {
				if(featured == 'Show List Price' && list_price != '') {
					temp_txt = '$' + list_price;
					temp_txt = (temp_txt=='$NaN') ? 'Varies' : temp_txt; //matrix hack
					$(list_price_obj).children('span.data').html(temp_txt);
					$(list_price_obj).show().css('color','#999');
				}else{
					$(list_price_obj).css('padding-top','5px');
					$(list_price_obj).css('padding-bottom','5px');
				}
			}
			if(hide_msrp){
				$(list_price_obj).hide();
				$(temp_id).find('div.grid_price').css('margin','7px 0');}
			//Price Label
			switch(true) {
				case (rfq == 'Yes'):
					temp_txt = 'Request a Quote <br> Call: 800.919.1904';
					$(temp_id).find('div.grid_price').css('font-size','10px');
					break;
				case (price == ' <b>$0</b>'): //shell item
					temp_txt = 'Select Your Parts';
					break;
				case (npm != ''): //rfq item
					temp_txt = '';
					break;
				case (configured == 'Configured' && !show_sale_price && !hide_matrix):
					temp_txt = 'Starting At: ';
					break;
				case (configured == 'Configured' && show_sale_price && !hide_matrix):
					temp_txt = '<strong>Starting At: </strong>';
					break;
				case (show_sale_price):
					temp_txt = '<strong>Sale Price: <strong>';
					break;
				default:
					temp_txt = 'Price:';
			}
			$(temp_id).find('div.grid_price').children('span.message').html(temp_txt);
			$(temp_id).find('div.quick_view_price').children('span.message').html(temp_txt);
			//Price
			//quantity pricing
			if($(temp_id).find("span.data_price table").length) {
				$(temp_id).find("span.data_price table").addClass("pricing_table");
				
				//Data to pass to change function
				price_data = {
					levels : $(temp_id).find("span.data_price table tr"),
					length : $(temp_id).find("span.data_price table tr").length,
					qty : [],
					price : [],
					update : false
					};
					
				//Parse the table data	
				for(i=1;i<price_data.length;i++) {
					price_data.price[i-1] = parseFloat($(price_data.levels[i]).find('td:nth-child(2)').html().replace(/\$|,/g,''));
				}
				price = '$' + price_data.price[price_data.length-2] + ' - $' + price_data.price[0];
			}
			switch(true) {
				case (price == ' <b>$0</b>' || rfq == 'Yes'):
					temp_txt = '';
					break;
				case (configured == 'Configured' && !show_sale_price):
					temp_txt = price;
					break;
				case (configured == 'Configured' && show_sale_price):
					temp_txt = '<strong>' + price + '</strong>';
					break;
				case (show_sale_price):
					temp_txt = '<strong>' + price + '</strong>';
					break;
				default:
					temp_txt = price;
			 }
			if(hide_matrix) {
				var a = temp_txt.lastIndexOf('$') - temp_txt.indexOf('$');
				if(a != 0) temp_txt = temp_txt.substring(0,temp_txt.lastIndexOf('$')-3)+'</span>';
			}
			 prc_suff = (prc_suff == ' ') ? '' : prc_suff;
			$(temp_id).find('div.grid_price').children('span.data').html(temp_txt + prc_suff);
			$(temp_id).find('div.quick_view_price').children('span.data').html(temp_txt + prc_suff);
			
			var SI_Test = false;
			if($(temp_id).find('.grid_brand_overlay img').length){
				SI_Test = ($(temp_id).find('.grid_brand_overlay img').attr('src').indexOf('/SI-') != -1)?true:false;
			} 
			if(SI_Test){
				$(temp_id).find('.grid_item_number').css('visibility','hidden');
				$(temp_id).find('.grid_availability').css('visibility','hidden');
				$(temp_id).find('.grid_gallery').css('visibility','hidden');
				$(temp_id).find('.grid_quick_view').css('visibility','hidden');
				$(temp_id).find('.grid_brand_overlay').css('position','absolute');
				$(temp_id).find('.grid_brand_overlay').css('top','180px');
				
			}else if(configured == 'Shell'){
				$(temp_id).find('.grid_item_number').css('visibility','hidden');
				$(temp_id).find('.grid_availability').css('visibility','hidden');
				$(temp_id).find('.grid_gallery').css('visibility','hidden');
				$(temp_id).find('.grid_quick_view').css('visibility','hidden');
			}
		});
	//Quick View Function
		$('.quick_view_product').mousedown(function () {
													$(this).attr('src',$(this).attr('src').replace('up','dn'));
														});
		$('.quick_view_product').mouseup(function () {
													$(this).attr('src',$(this).attr('src').replace('dn','up'));
														});
		$('#grid_quick_view').bind('on_reveal',function(e,clicked_on,old_e){
			//position and reveal window
			var offset = ($(window).width()-1000)/2 + 225;
			$(this).appendTo('body')
					.css({
						posistion: 'absolute',
						top : old_e.pageY - 300 + 'px',
						left : offset + 'px'
					});
			var temp_qv_id = $(clicked_on).closest('div.internal_id').attr('id');
			//fill quick view content
			var med_image = $('#' + temp_qv_id).find('span.data_med_image').html();
			med_image = med_image.replace(/&amp;/g,'&');
			var availability = $('#' + temp_qv_id).find('p.grid_availability').html();
			var price = $('#' + temp_qv_id).find('div.grid_price span.data').html();
			var price_label = $('#' + temp_qv_id).find('div.grid_price span.message').html();
			var canada = $('#' + temp_qv_id).find('span.data_canada_ez').html();
			var usa = $('#' + temp_qv_id).find('span.data_usa').html();
			var customer = $('#' + temp_qv_id).find('span.data_customer').html();
			var eco = $('#' + temp_qv_id).find('span.data_eco').html();
			var wd_ex = $('#' + temp_qv_id).find('span.data_wd_exclusive').html();
			var quick_ship = $('#' + temp_qv_id).find('span.data_quick_ship').html();
			var qv_rfq = $('#' + temp_qv_id).find('span.data_rfq').html();
			var qv_config = $('#' + temp_qv_id).find('span.data_configured').html();
			var qv_desc = $('#' + temp_qv_id).find('span.data_detailed_description').html();
			var qv_id = $('#' + temp_qv_id).find('span.data_item_id').html();
			var qv_store_url = $('#' + temp_qv_id).find('span.data_store_url').html();

			$('#grid_quick_view .qv_item_url').each(function(){$(this).attr('href',qv_store_url)});
			$('#grid_quick_view #qv_item_id').html('Item #: ' + qv_id);
			$('#grid_quick_view').find('div.quick_view_details_body').html(qv_desc);
			$('#grid_quick_view').find('p.quick_view_availability').html(availability);
			$('#grid_quick_view').find('p.quick_view_price span.message').html(price_label);
			$('#grid_quick_view').find('p.quick_view_price span.data').html(price);
			
			if(qv_rfq == 'Yes') {
			$('#grid_quick_view').find('p.quick_view_price span.message').css('font-size','12px');
			$('#grid_quick_view').find('p.quick_view_shipping').hide();
			}
			if(qv_config == 'Yes') {
			$('#grid_quick_view').find('p.quick_view_price span.message').css('font-size','16px');
			$('#grid_quick_view').find('p.quick_view_price span.data').css('font-size','16px');
			}
			if(canada != 'False') $('#grid_quick_view').find("img.canada_easy").show();
			if(usa == 'United States') $('#grid_quick_view').find("img.made_in_usa").show();
			if(customer == "Yes") $('#grid_quick_view').find("img.customer_choice").show();
			if(eco == "Yes") $('#grid_quick_view').find("img.eco_safe").show();
			if(wd_ex == "Yes") $('#grid_quick_view').find("img.woodland_exclusive").show();
			if(quick_ship != 'False') $('#grid_quick_view').find("img.quick_ship").show();
			
			$('#grid_quick_view').find('div.quick_view_main_image img').attr('src','http://www.woodlanddirect.com/images/graphics/bm_theme/Loader.gif')
																		.delay(1000)
																		.queue(function () {
																					$(this).attr('src',med_image);
																					$(this).dequeue();
																						});;
		});
	//move sort by to immediately above the grid view
		$('tr#handle_itemMainPortlet td table tr td table tr td.medtext').each(function () {
																						if($(this).html().indexOf("Sort by Name") != -1) {
																							var srt_by_nme = $(this).html() + ' ';
																							$(this).empty();
																							if($('#grid_view_sort_by').html().indexOf('Sort by Price') == -1) {
																								$('#grid_view_sort_by').append(srt_by_nme);
																							}
																						}
																						if($(this).html().indexOf("Sort by Price") != -1) {
																							var srt_by_prce = $(this).html();
																							$(this).empty();
																							if($('#grid_view_sort_by').html().indexOf('Sort by Price') == -1) {
																								$('#grid_view_sort_by').append(srt_by_prce);
																							}
																						}
																						});
	//move pagination to immediately above the grid view
	$('tr#handle_itemMainPortlet td table tr td table tr td table tr td.medtext').each(function () {
																								if($(this).html().indexOf('Results') != -1) {
																									if($('#grid_view_pagination').html().indexOf('Results') == -1) {
																										var results = $(this).parent('tr').html();
																										$(this).parent('tr').empty();
																										$('#grid_view_pagination').append(results);
																									}
																								}
																								});
	$('#grid_image_gallery').bind('on_reveal',function(e,clicked_on,old_e){
		//position and reveal window
		var offset = ($(window).width()-1000)/2 + 100;
		$(this).appendTo('body')
				.css({
					posistion: 'absolute',
					top : old_e.pageY - 300 + 'px',
					left : offset + 'px'
				});
		//clear previous images
		$(this).find('img.large_img').attr('src','');
		$(this).find('div.image_gallery_nav').find('img').each(function(){
			$(this).attr('src',' ').hide();
		});
		
		  var data_div = $(clicked_on).closest('div.internal_id');
		  var tempID = data_div.attr('id'); //get the internal id of the current item.
		  var alt_images = data_div.find('.data_alt_images').html().split(',');
		  var image_src = data_div.find('.data_alt_image_srcs').html().split('|');
			for (var i = 0; i <= 35;i++) { 
				image_src[i] = image_src[i].replace(/&amp;/g,'&');
				};
			$(this).find('.main_thumb').attr('src',image_src[0]).data('lrg_src',image_src[1]).show().click(function(){
				var temp_src = $(this).data('lrg_src');
				 $(this).closest('div.image_gallery')
				 		.find('img.large_img')
						.attr('src','http://www.woodlanddirect.com/images/graphics/bm_theme/Loader.gif')
						.delay(1000)
						.queue(function () {
									$(this).attr('src',temp_src);
									$(this).dequeue();
										});
			}).trigger('click');
			//Set each alt image to the correct src. Set their onclick events 
			var current_image_src ='';
			var current_lrg_img_src = '';
			for(var i = 1;i != 16;i++) {
				if(parseInt(alt_images[i-1])) {
					switch (true) {
						case (i<5):
							if(image_src[i*3-1] != '') {
								current_image_src = image_src[i*3-1];
							}else{
								current_image_src = image_src[(i*3)];
							}
							current_lrg_img_src =  image_src[(i*3)+1];
						break;
						case (i>4):
							current_image_src = image_src[(i+2)*2];
							current_lrg_img_src = image_src[(i+2.5)*2];
						break;
					}
						
					$('#grid_image_gallery').find('.alt_thumb_' + i).attr('src',current_image_src)
													.data('lrg_src',current_lrg_img_src)
													.show()
													.click(function () {
																	 var temp_src = $(this).data('lrg_src');
																	 $(this).closest('div.image_gallery')
																	 		.find('img.large_img')
																			.attr('src','http://www.woodlanddirect.com/images/graphics/bm_theme/Loader.gif')
																			.delay(1000)
																			.queue(function () {
																						$(this).attr('src',temp_src);
																						$(this).dequeue();
																							});
																	 });
				}
			}
	});
	/*
	items = new Array();
	$.each($('.grid_cell'),function(index,element){
		items[index] = new Item(element);
	});
	//*/
	}else if($('#item_drilldown').length) {
		//Item Availabilty and Item Ships with in time			
		var item_name = $('.data_item_id').html();
		var internal_id = $('.data_internal_id').html();
		var item_available = $('.data_available').html();
		var item_qty_available = parseInt($('.data_qty_available').html());
		var item_ships_within = $('.data_item_ships_within').html();
		var item_is_kit = (item_name.indexOf('K') != -1)? true: false;
		var shown_ships_within = (item_is_kit) ? '1-2 Buisness Days' : item_ships_within;
		var shown_available = '';
		var des_banner = $('#item_drilldown').find('.data_description_banner').html();
		var des_banner_url = $('#item_drilldown').find('.data_description_banner_url').html();
		var configured_matrix = ($('.data_hide_matrix_options',this).html()== 'Yes') ? 1:0;
		var featured = $('#item_drilldown').find('.data_featured_type').html();
		
		//phone number
		if (phonechange) {
			var technical = ($('.data_technical', this).html() == 'yes') ? true : false;
			if (!technical) {
				$(".phone_number").each(function(){
					$(this).html("877.919.1904");
				});
			}
			else {
				$(".phone_number").each(function(){
					$(this).html("800.919.1904");
				});
			}
		}
		//end phone number
		
		switch(item_is_kit) {
			case true:
				shown_available = (item_qty_available > 0)? 'In Stock': 'Backordered' ;
			break;
			case false:
				shown_available = item_available;
			break;
		}
		if(des_banner){
			if(des_banner_url){
				$('#tab1_content').find('.descr_content').prepend('<a href="'+des_banner_url+'" alt="Banner Link"><img src="/images/banners/DescriptionBanner/'+des_banner+'" alt="banner"></a>');
			} else{
				$('#tab1_content').find('.descr_content').prepend('<img src="/images/banners/DescriptionBanner/'+des_banner+'" alt="banner">');				
			}
		}
		$('#itemavailability').html(shown_available);
		$('#item_ships_within_time').html(shown_ships_within);
		if(shown_available.indexOf('Back') != -1)$('#item_ships_within').hide();
		
		if($('.data_design_options').html()) {$('.info_link_design_options').parent('a')
											  .css('display','block')
											  .click(function (e) {
															  normal_pop_up(this);
															  e.preventDefault();
															  });};
		if($('.data_color_options').html()) {$('.info_link_color_sample').parent('a')
											  .css('display','block')
											  .click(function (e) {
															  normal_pop_up(this);
															  e.preventDefault();
															  });};
		if($('.data_finish_options').html()) {$('.info_link_finish_options').parent('a')
											  .css('display','block')
											  .click(function (e) {
															  normal_pop_up(this);
															  e.preventDefault();
															  });};
		if($('.data_size_chart').html()) {$('.info_link_siza_chart').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_gallery').html()) {$('.info_link_gallery').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_watch_demo').html()) {$('.info_link_demo').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_owners_manual').html()) {$('.info_link_manual').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_install').html()) {$('.info_link_install').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_measure').html()) {$('.info_link_measure').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_faq').html()) {$('.info_link_faq').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_learn_more').html()) {$('.info_link_learn').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_calculator').html()) {$('.info_link_calculator').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		if($('.data_blog_article').html()) {$('.info_link_blog').parent('a')
															  .css('display','block')
															  .click(function (e) {
																			  normal_pop_up(this);
																			  e.preventDefault();
																			  });};
		$('.pop_learn').click(function (e) {
									   $('.info_link_learn').parent('a').click();
									   e.preventDefault();
									   });
		//Allow user quantity input in textbox
		if($('.data_type_qty').html() == 'Yes') {
				$('#qtyspan').show();
				$('#qty_change').hide();
				$('#qty').keypress(function(event) {
					
				});
				$('#qty').change(function(event) {
   					var tri = event.target;
					tri = $(tri).val();
					
					$('#qty_change').empty();
					$('#qty_change').append($('<option></option>').val(tri).html(tri)).val(tri).change();
				});
				$('#qty').keyup(function(event) {
					$('#qty').change();											
				});
			};
		//quantity pricing
		if($("div.qty_pricing table").length) {
			$("div.qty_pricing table").find("td").removeClass().css('padding','2px');
			$("div.qty_pricing table").find("tr:even").removeClass().css('backgroundColor','#DDD8C8');
			$("div.qty_pricing table").find("tr:odd").removeClass().css('backgroundColor','#CFC7AF');
			$("div.qty_pricing table").find("tr:first").css('backgroundColor','#564032').css('color','white');
			$("div.qty_pricing table").find("div").removeClass();
			$("div.qty_pricing table").removeClass();
			$("div.qty_pricing table").addClass("pricing_table").parent().show();
			
			//Data to pass to change function
			price_data = {
				levels : $("table.pricing_table tr"),
				length : $("table.pricing_table tr").length,
				qty : [],
				price : [],
				update : false
			};	
			//Parse the table data	
		  	for(i=1;i<price_data.length;i++) {
				price_data.qty[i-1] = parseInt($(price_data.levels[i]).find('td:nth-child(1)').html().replace(/&nbsp;|\+/g,''));
				price_data.price[i-1] = parseFloat($(price_data.levels[i]).find('td:nth-child(2)').html().replace(/\$|,/g,''));
		  	}
			
			//Update the displayed price
			$("#qty_change").change(function () {
											 
				var item_id = allInternalIds[0];
				var main_qty = parseInt($("#qtydiv").children("[name='qtyx']").val());
				var test = 0;
				
				for(y=0;y<price_data.length;y++) {
					test = (main_qty >= price_data.qty[y]) ? true : false;
					if(!test) {
						test = (y-1<0) ? 0 : y-1;
						y = price_data.length;
					}
				}
				
				var price_format = price_data.price[test] + '';				
				price_format = (price_format.indexOf('$') == -1) ? '$' + price_format : price_format;
				price_format = (price_format.indexOf('.') == -1) ? price_format + '.00' : price_format;
				$("#acc_price_value"+item_id).html(price_format);
				
				/* Run function twice to force the pricing updates to be calculated with the new values */
				price_data.update = !price_data.update;
				if(price_data.update) {
					$("#qty_change").change();
				}
			});
		}else if($("div.qty_pricing span").length) {
			var matrix_price = $("div.qty_pricing").html();
			$("div.qty_pricing").html('');
			var item_id = allInternalIds[0];
			$("#acc_price_value"+item_id).html(matrix_price);
		}else if($("#acc_price_value"+allInternalIds[0]).html() == "$0.00" || $("#acc_price_value"+allInternalIds[0]).html().length < 2) {
			var item_id = allInternalIds[0];
			var price_message;
			if($(".data_no_prc_message").length) {
				price_message = $(".data_no_prc_message").html();
			}
			if(price_message) {
				$("#acc_price_value"+item_id).html(price_message);	
				$("#total_price").html(price_message);
			}else{
				var matrix_price = $("div.qty_pricing").html().replace(/\/n|\s/g,''); // remove white space from Matrix pricing
				$("div.qty_pricing").html('');
				$("#acc_price_value"+item_id).html(matrix_price);	
				$("#total_price").html(matrix_price);
			}
		}
//Main Item Overlay
		if($('.data_main_overlay_url').html() && $('.data_main_overlay_url').html().indexOf('ynamic') == -1) {$('#main_overlay').show()
																  .attr('src','/images/graphics/overlay/main/'+$('.data_main_overlay_url').html());
																  } 
		if(featured !='') {$('#featured_overlay').show()
																  .attr('src',featured_overlay(featured));
																  } 
																  
//configured Item remove from cart fix. Creates a custom id for each required item and main item
		var random_config = Math.floor(Math.random()*1000001).toString(16);
		$('input[name="custcol_configured_item"]').each(function () {
																	$(this).closest('tr').hide();
																	$(this).val(random_config);
																	});	
		$('input[name="custcol_configured_part"]').each(function () {
																	$(this).closest('tr').hide();
																	$(this).val(random_config);
																	});

		//BEGIN DEPRECATED GALLERY FOR ITEM TEMPLATE
		if($('.image_gallery').length) {
			$('.image_gallery').each(function () {
											  var data_div = $(this).closest('div.internal_id');
											  var tempID = data_div.attr('id'); //get the internal id of the current item.
											  var alt_images = data_div.find('.data_alt_images').html().split(',');
											  var image_src = [
																	data_div.find('.data_main_thumb').html(),
																	data_div.find('.data_main_large').html(),
																	data_div.find('.data_alt_thumb1').html(),
																	data_div.find('.data_alt_thumb1a').html(),
																	data_div.find('.data_alt_large1').html(),
																	data_div.find('.data_alt_thumb2').html(),
																	data_div.find('.data_alt_thumb2a').html(),
																	data_div.find('.data_alt_large2').html(),
																	data_div.find('.data_alt_thumb3').html(),
																	data_div.find('.data_alt_thumb3a').html(),
																	data_div.find('.data_alt_large3').html(),
																	data_div.find('.data_alt_thumb4').html(),
																	data_div.find('.data_alt_thumb4a').html(),
																	data_div.find('.data_alt_large4').html(),
																	data_div.find('.data_alt_thumb5').html(),
																	data_div.find('.data_alt_large5').html(),
																	data_div.find('.data_alt_thumb6').html(),
																	data_div.find('.data_alt_large6').html(),
																	data_div.find('.data_alt_thumb7').html(),
																	data_div.find('.data_alt_large7').html(),
																	data_div.find('.data_alt_thumb8').html(),
																	data_div.find('.data_alt_large8').html(),
																	data_div.find('.data_alt_thumb9').html(),
																	data_div.find('.data_alt_large9').html(),
																	data_div.find('.data_alt_thumb10').html(),
																	data_div.find('.data_alt_large10').html(),
																	data_div.find('.data_alt_thumb11').html(),
																	data_div.find('.data_alt_large11').html(),
																	data_div.find('.data_alt_thumb12').html(),
																	data_div.find('.data_alt_large12').html(),
														 			data_div.find('.data_alt_thumb13').html(),
																	data_div.find('.data_alt_large13').html(),
																	data_div.find('.data_alt_thumb14').html(),
																	data_div.find('.data_alt_large14').html(),
																	data_div.find('.data_alt_thumb15').html(),
																	data_div.find('.data_alt_large15').html()
																	];
												for (var i = 0; i <= 35;i++) { 
													image_src[i] = image_src[i].replace(/&amp;/g,'&');
													};
												
												//Set each alt image to the correct src. Set their onclick events 
												var current_image_src ='';
												var current_lrg_img_src = '';
												for(var i = 1;i != 16;i++) {
													if(parseInt(alt_images[i-1])) {
														switch (true) {
															case (i<5):
																if(image_src[i*3-1] != '') {
																	current_image_src = image_src[i*3-1];
																}else{
																	current_image_src = image_src[(i*3)];
																}
																current_lrg_img_src =  image_src[(i*3)+1];
															break;
															case (i>4):
																current_image_src = image_src[(i+2)*2];
																current_lrg_img_src = image_src[(i+2.5)*2];
															break;
														}
															
														data_div.find('.alt_thumb_' + i).attr('src',current_image_src)
																						.data('lrg_src',current_lrg_img_src)
																						.show()
																						.click(function () {
																										 var temp_src = $(this).data('lrg_src');
																										 $(this).closest('div.image_gallery')
																										 		.find('img.large_img')
																												.attr('src','/images/graphics/bm_theme/Loader.gif')
																												.delay(1000)
																												.queue(function () {
																															$(this).attr('src',temp_src);
																															$(this).dequeue();
																																});
																										 });
													}
												}
											  data_div.find('img.access_gallery').each(function () {																				  
																			  $(this).bind('click',{img_src: image_src, tmpID: tempID},function (e) {
																									 var eY = e.pageY;
																									 var eX = (e.pageX - 300 > 150) ? e.pageX - 350 : 150;
																									 var temp_id = e.data.tmpID;
																									 var image_src_holder = e.data.img_src;
																									 $('div#image_gallery_'+temp_id).find('img.large_img')
																									 								.attr('src',image_src_holder[1]);
																									 $('div#image_gallery_'+temp_id).find('img.main_thumb')
																									 								.attr('src',image_src_holder[0])
																																	.data('lrg_src',image_src_holder[1])
																																	.show()
																																	.click(function () {
																																			 var temp_src = $(this).data('lrg_src');
																																			 $(this).closest('div.image_gallery')
																																			 		.find('img.large_img')
																																					.attr('src','')
																																					.attr('src',temp_src);
																																			 });
																									 
																									 $('div#image_gallery_'+temp_id).appendTo('body')
																											.fadeIn('fast')
																											.css({
																												 top : eY - 100 + 'px',
																												 left : eX + 'px'
																												 });
																											
																									 });
																			  });
											  $(this).find('div.image_gallery_close > p').click(function () {
																								   var temp_id = $(this).closest('.image_gallery').fadeOut('fast');
																								   });
											  });
			}
		//END DEPRECATED GALLERY FOR ITEM TEMPLATE
		
		//Accessory Cell Code
		if(configured_matrix){
			var matrix = new Object();
			matrix.selects = new Array(); //hold each matrix select option
			matrix.price_list = new Array(); //hold the list of prices from netsuite
			matrix.props = new Array(); //hold the index key for the price list from netsuite
			matrix.lowest_price = '';
			matrix.lp_count = 0; //holds the location lowest price in the matrix list
			matrix.current_price = 0;
			matrix.will_change = true;
			matrix.count = 0; //holds the length of the original netsuite matrix list
			matrix.prices_set = false; //have prices been processed at least once
			matrix.other_lps = new Array();//holds alternate minimum prices
			matrix.update_opts = function (){   //update the matrix control select fields
				if(matrix.will_change){
					//get the current selections
					var m_len = matrix.selects.length;
					$('.acc_cell').each(function(){
						var matrix_control = $(this).find('.data_matrix_control').html();
						var m_obj = '';
						for(var i=0;i<m_len;i++){
							if(matrix.selects[i].name == matrix_control){
								m_obj = matrix.selects[i];
								break;						
							}
						}
						if(matrix_control != "" && m_obj.matrix_field){
							len = m_obj.value.length;
							current_selection = $(".matrix_control",this).val();
							var current_text = $(".matrix_control option:selected",this).text();
							var new_opt = '';
							var temp_price;
							for(var i=0;i<len;i++){
								if(m_obj.value[i] != current_selection){
									if(i){
										new_opt = new_opt + '<option value="'+m_obj.value[i]+'">'+m_obj.text[i]+' : '+m_obj.change[i]+'</option>';
									}
									else{
										new_opt = new_opt + '<option value="'+m_obj.value[i]+'">'+m_obj.text[i]+'</option>';
										}
								}
								else{
									new_opt = new_opt + '<option selected="selected" value="'+m_obj.value[i]+'">'+current_text+'</option>';
									temp_price=m_obj.change[i];
								}
							}
							$(".matrix_control",this).html(new_opt);
							$(".matrix_control_price .acc_price_value",this).html(temp_price);
						}
					});
				}
			};
			matrix.update_prices = function (){ //update the pricing of the available options
				if(matrix.will_change){
					//get the current selections
					var m_len = matrix.selects.length;
					var selection = new Array();
					if(matrix.prices_set){
						/*
						for(i=0;m_len-i;i++){
							if(matrix.selects[i].matrix_field){
								if($('#'+matrix.selects[i].name).val() != ""){
									selection[i] = $('#'+matrix.selects[i].name).val();
								}else{
									var len = matrix.selects[i].value.length;
									for(j=0;j<len;j++){
										if(!isNaN(matrix.selects[i].value[j])){
											selection[i]=matrix.selects[i].value[j];
											break;
										}
									}
								}
							}
						}

						selection = selection.join('');
							// find the current lowest price
						for(i=0;i<matrix.count;i++){
							if(selection == matrix.props[i])break;
						}
						matrix.current_price = matrix.price_list[i];
						//*/
					//*/
					matrix.current_price = matrix.lowest_price;
					selection = matrix.props[matrix.lp_count];
					matrix.prices_set = true;
					//*
					}else{
						matrix.current_price = matrix.lowest_price;
						selection = matrix.props[matrix.lp_count];
						matrix.prices_set = true;
					}
						// calculate price change
					var pdlen;
					var t_sel;
					var t_price;
					var i_mod = 0; //account for shift in number due to non matrix selects
					for(i=0;i<m_len;i++){ 
						if(matrix.selects[i].matrix_field){//if it is a matrix field then continue else iterate i_mod
							pdlen = matrix.selects[i].value.length; // quantity of all available values for this matrix select
							for(j=0;j<pdlen;j++){
								if(!isNaN(matrix.selects[i].value[j])){ //if the value is a number else do nothing (skips of the -select-)
									t_sel = selection.slice(0);
									t_sel[i-i_mod] = matrix.selects[i].value[j];
									var test_sel = t_sel.join('');
									//check that this option exists
									var cop_out = 0;
									while (matrix.selects[i].price_diff[matrix.selects[i].value[j]][test_sel] == undefined && cop_out >= 8000) {
										cop_out++;
										for (var k = matrix.other_lps.length; k--;) {//check to see if a differnet lower price choice can give a hint
											for(var l=0;l<selection.length;l++)
											if(matrix.other_lps[k][l]!=selection[l]&&l!=i){//look one of the options can change without effecting the price
												t_sel[l]=matrix.other_lps[k][l];//change to that option
												test_sel = t_sel.join('');
											}
										}
									}
									if (cop_out < 8000) {
										t_sel = t_sel.join('');
										matrix.selects[i].change[j] = (matrix.selects[i].price_diff[matrix.selects[i].value[j]][t_sel] - matrix.current_price) / 100;
										matrix.selects[i].change[j] = (matrix.selects[i].change[j] < 0) ? 0 : matrix.selects[i].change[j];
										matrix.selects[i].change[j] = format_price(matrix.selects[i].change[j]);
									}else{matrix.selects[i].change[j] = format_price(0);}
								}
							}
						}else{
							i_mod++;
						}
					}
				}
			};
			matrix.fill_me = function(){	//retrieve the matrix select fields and their data
				$.each($('#main_item_matrix select'),function(order,el){ //for every select box create an object at that array index
					matrix.selects[order] = new Object;
					matrix.selects[order].name = $(el).attr('id'); //find each matrix option id
					matrix.selects[order].matrix_field = ($('#'+$(el).attr('id')).attr('onchange').toString().indexOf('optionOnChange') != -1)? true : false;
					//get all the matrix selects options
					matrix.selects[order].value = new Array();
					matrix.selects[order].text = new Array();
					matrix.selects[order].price_diff = new Array();
					matrix.selects[order].change = new Array();
					$.each($(el).find('option'),function(i,op_el){
						matrix.selects[order].value[i] = parseInt($(op_el).val());
						matrix.selects[order].text[i] = $(op_el).text();
						if(matrix.selects[order].matrix_field){
							if(!isNaN(parseInt(matrix.selects[order].value[i])))matrix.selects[order].price_diff[matrix.selects[order].value[i]]=new Object(); //create a price change object for each option
						}
					});
				});
			
						
				//retrieve the matrix price object from netsuite generated code
				var prices = window['Item'+internal_id+'_prices']; //find the matrix price list
				//process the matrix price object
				if (typeof(prices) != 'undefined'){
					for (var k in prices) { //traverse the object looking for each price property
					    if (prices.hasOwnProperty(k)) {
					        matrix.price_list[matrix.count] = prices[k];
					        matrix.price_list[matrix.count] = parseInt(parseFloat(matrix.price_list[matrix.count].replace('$','').replace(',',''))*100); //make integer
					        if(matrix.count){ //find the lowest price
					        	if(matrix.lowest_price > matrix.price_list[matrix.count]){
					        		matrix.lowest_price = matrix.price_list[matrix.count];
					        		matrix.lp_count = matrix.count;
					        		}
					        }else{
					        	matrix.lowest_price = matrix.price_list[matrix.count];
					        }
					        matrix.props[matrix.count] = k.split(':');//find the options selected for each price
					       ++matrix.count;
					    }
					}
					//compare the lowest price to the other options and find = choices
					for(i=0,q=matrix.price_list.length;i<q;i++){
						if(matrix.lowest_price == matrix.price_list[i] && i != matrix.lp_count){
							matrix.other_lps.push(matrix.props[i]);
						};
					}
					//for(i=0;i<matrix.count;i++) matrix.props[i]=matrix.props[i].join('');
					var m_len = matrix.selects.length;
					var curr_options;
					for(i=0;matrix.count-i;i++){
						curr_options = matrix.props[i].join('');
						var j_mod = 0; //j_mod accounts for shift in number when selects are not matrix options
						for(j=0;m_len-j;j++){
							if(matrix.selects[j].matrix_field){
								var test_exist = matrix.selects[j];
								var test_props = matrix.props[i][j-j_mod];
								if(test_exist.price_diff[test_props]){ //if matrix option is turned off (ie backordered then the option doesnt exist)
									test_exist.price_diff[test_props][curr_options] = matrix.price_list[i];
								}
							}else{
								j_mod++;
							}
						}
					}
					
				}else{
					matrix.will_change = false;
				};
			};
			//fill the object
			matrix.fill_me();	
			//initialize price differences
			matrix.update_prices();	
			
			$('.acc_cell').each(function(){
				var matrix_control = $(this).find('.data_matrix_control').html();
				var m_obj = '';
				var m_len = matrix.selects.length;
				for(i=0;i<m_len;i++){
					if(matrix.selects[i].name == matrix_control){
						m_obj = matrix.selects[i];
						break;						
					}
				}
				if(m_obj.matrix_field){
					$(".matrix_control_price",this).show();
				}
				if(matrix_control != "" && matrix_control != null){
					len = m_obj.value.length;
					var new_opt = '';
					for(i=0;i<len;i++){
						if(i && matrix.will_change && m_obj.matrix_field){
							new_opt = new_opt + '<option value="'+m_obj.value[i]+'">'+m_obj.text[i]+' : '+m_obj.change[i]+'</option>';
						}else if(i){
							new_opt = new_opt + '<option value="'+m_obj.value[i]+'">'+m_obj.text[i]+'</option>';
						}else{
							new_opt = new_opt + '<option selected="selected" value="'+m_obj.value[i]+'">'+m_obj.text[i]+'</option>';
						}
					}
					$(".matrix_control",this).html(new_opt).show().change(function(){
									if(!isNaN($(this).val())){
										
									}
									$("#"+m_obj.name).val($(this).val()).change();
									matrix.update_prices(); //update the list of potential price changes
									matrix.update_opts();	//display the updated prices in the options
									});
					$(".matrix_label span",this).html($("#"+matrix_control+"_fs_lbl a").html());
				}
				
			});
			if(matrix.will_change){
				var t_price = format_price(matrix.lowest_price/100);
				$('#alt_price span.low').html(t_price);
				$('#alt_price').show();
				$('#old_price').hide();
			}
		};
		$('.acc_cell').each(function(){
			var syncQty = ($(this).find('input.sync_qty').val() == 'Yes')? true:false;
			if($(this).find('input.display_step').length != 0){ //fix for ie9
				var displayStep = ($(this).find('input.display_step').val() == 'Yes')? true:false;
				if(!displayStep){
					if($(this).parent('tr').length == 0) { //another fix for ie9
						$(this).closest('tr').hide();
					}else{
						$(this).parent('tr').hide();
					}
				}
			}
			var cell_id = $(this).find('input.internal_id').val();
				if (syncQty) {
					//set up cell to display the correct linked qty
				$('#qtydiv' + cell_id).hide();
				$('#readout_area_' + cell_id).html('Qty: 1');
				$('#qtydiv' + cell_id).find('#c_selectqty').val(1).change();
				//link qty to main item qty
				$('#qty_change').change(function(){
					$('#qtydiv' + cell_id).find('#c_selectqty').val($(this).val()).change();
					$('#readout_area_' + cell_id).html('Qty: ' + $(this).val());
				});
			};
		});
	}else if($('#shell_item').length) {
		//phone number
		if (phonechange) {
			var technical = ($('.data_technical', this).html() == 'yes') ? true : false;
			if (!technical) {
				$(".phone_number").each(function(){
					$(this).html("877.919.1904");
				});
			}
			else {
				$(".phone_number").each(function(){
					$(this).html("800.919.1904");
				});
			}
		}
		//end phone number
		
	}else if($('#rfq_drilldown').length) {
		//phone number
		if (phonechange) {
			var technical = ($('.data_technical', this).html() == 'yes') ? true : false;
			if (!technical) {
				$(".phone_number").each(function(){
					$(this).html("877.919.1904");
				});
			}
			else {
				$(".phone_number").each(function(){
					$(this).html("800.919.1904");
				});
			}
		}
		//end phone number
		
	}else if($('#main_category').length) {
		$('tr#handle_itemMainPortlet td table tr td table tr td.medtext').each(function () {
																						if($(this).html().indexOf("Sort by Name") != -1) $(this).hide();
																						if($(this).html().indexOf("Sort by Price") != -1) $(this).hide();
																						});
		if($('#why_buy').html()) {$('#why_buy').click(function (e) {
															  normal_pop_up(this);
															  e.preventDefault();
															  });
															  }
		
		$('.dragme_customer').each(function () {
									$(this).draggable({
													  handle: '#drag_customer_handle',
													  containment: [0,0,2000,9999]
													  });
									});
//phonenumber
		if(phonechange)phonenumberchange();
//customer gallery
		$('#customer_gallery').bind('on_reveal',function () {
			var eY = 125;
			var eX = $(window).width()/2 - 445;
			$('div#customer_gallery').appendTo('body').css({
														 	top : eY + 'px',
														 	left : eX + 'px'
														 });
			var image_links = $('#customer_gallery_data li a');
			var image_links_len = image_links.length;
			var thumb_html = '';
			for (i=0;i<image_links_len;i++) {
				thumb_html += '<div class="thumb"><img src="'+$(image_links[i]).attr('href')+'" title="'+$(image_links[i]).html()+'"><div class="number">D'+(i+1)+'</div><h3>'+$(image_links[i]).html()+'</h3></div>';
			}
			$('.customer_gallery_nav').html(thumb_html);
						
			$('.customer_gallery_nav img').click(function () {
				var temp_src = $(this).attr('src').replace('.','-lg.');										  
				$('.large_img').attr('src',$('.large_img').attr('lowsrc'))
								.delay(1000)
								.queue(function () {
									$(this).attr('src',temp_src);
									$(this).dequeue();
								});
			});
			$('.customer_gallery_nav img:first').click();;
		});

	}else if($('#carttable').length) {
//phonenumber
		if(phonechange)phonenumberchange();
//control configured items
		var con_in_cart = $('td.bglttext:contains("Configured Item:")').closest('tr[id^="cart"]');
		var req_in_cart = $('td.bglttext:contains("Configured Part:")').closest('tr[id^="cart"]');
		var con_len = con_in_cart.length;
		var req_len = req_in_cart.length;
		var con_data ='';
		if(con_in_cart.length != 0) {
			var input_qty = '';
			var input = '';
			for (i=0;req_len > i;i++) {
				//hide the qty input, hide it, and display an un-editable qty for the customer
				input =  $(req_in_cart[i]).find('input');
				$(input).hide();
				input_qty = $(input).val();
				$(input).closest('td').append('<span>'+input_qty+'</span>');
				//hide the remove from cart button
				$(req_in_cart[i]).find('a img').hide();
				//get the configured ID and store is on the parent TR
				$(req_in_cart[i]).data('con_id', $(req_in_cart[i]).find('td.bglttext:contains("Configured")').html().replace('Configured Part:: ',''));
			}
			for (i=0;con_len > i;i++) {
				//hide the qty input, hide it, and display an un-editable qty for the customer
				input =  $(con_in_cart[i]).find('input');
				$(input).hide();
				input_qty = $(input).val();
				$(input).closest('td').append('<span>'+input_qty+'</span>');
				//get the configured ID and store is on the parent TR
				$(con_in_cart[i]).data('con_id', $(con_in_cart[i]).find('td.bglttext:contains("Configured")').html().replace('Configured Item:: ',''));
				//override the remove from cart button
				$(con_in_cart[i]).find('a img').removeAttr('onclick').click(function () {
					con_data = $(this).closest('tr[id^="cart"]').data('con_id');
					$(this).closest('tr[id^="cart"]').find('input').val(0);
					for(i=0;req_len > i;i++) {
						if(con_data == $(req_in_cart[i]).data('con_id')) {
							$(req_in_cart[i]).find('input').val(0);
						}
					}
					$('#recalc').click();
				});
			}
		}
		
	}else {
//phonenumber
		if(phonechange)phonenumberchange();
		$('tr#handle_itemMainPortlet td table tr td table tr td.medtext').each(function () {
																						if($(this).html().indexOf("Sort by Name") != -1) $(this).hide();
																						if($(this).html().indexOf("Sort by Price") != -1) $(this).hide();
																						});
	}
	if($('#breadcrumbs').length) {
		var crumbs = {
				hrefs: [],
				text: [],
				len: null
				};
		if(window.location.href.indexOf('checkout.netsuite') == -1) {
			var old_crumbs = $('#breadcrumbs a.crumb').remove();		//delete old crumbs and preserve tem in a variable
		
			crumbs.len = old_crumbs.length;
		
			for(i=crumbs.len;i--;) {
				crumbs.hrefs[i] = $(old_crumbs[i]).attr('href');
				crumbs.text[i] = $(old_crumbs[i]).html();
			}
			create_crumbs(crumbs.hrefs,crumbs.text,crumbs.len);
		}else{
			$('#old_crumbs').show();
			$('#new_crumbs').hide();
		}
	};
});

function create_crumbs(chrefs,ctext,clen) { //takes an object
	//new_crumbs
	//current_crumb
	var other_crumbs = '';
	var breadTextLen = 0;
	var MAX_BREAD_LEN = 113;
	for(i=0;i<clen;i++){
		breadTextLen += ctext[i].length;
	}
	breadTextLen = 113 - breadTextLen;
	if(clen > 0) {
		for(var i = 0;i<clen;i++) {
			other_crumbs += '<div><a href="'+chrefs[i]+'">'+ctext[i]+'</a>';
			//if its not the last crumb then use other to other else use other to current.
			other_crumbs += ((i+1)-clen)?'<img class="other_bread_img" src="/images/graphics/bm_theme/breadcrumbs/other-to-other-crumb.jpg"></div>':'<img class="current_bread_img" src="/images/graphics/bm_theme/breadcrumbs/other-to-current-crumb.jpg"></div>'; 			
		}
		ctext = window.location.pathname;
		ctext = ctext.substring(ctext.lastIndexOf('/')+1).replace(/-/g,' ');
		if(!$('#item_drilldown').length && !$('#rfq_drilldown').length && !$('#shell_item').length) {
			if($('#gridview').length){
				ctext = $('#gridview').find('span.url_comp').html();
				ctext = ctext.replace(/-/g,' ');
			}
			$('#current_crumb').prepend('<a>'+ctext+'</a>');
		}else if($('#shell_item').length){  //if it is a shell item then use the 
			if(breadTextLen < ctext.length){
				ctext = ctext.substring(0,breadTextLen-3);
				ctext = ctext + '...';
			}
			$('#current_crumb').prepend('<a>'+ctext+'</a>');
		}else{
			var namenumber = $('#namenumber').val();
			$('#current_crumb').prepend('<a>Item #: '+namenumber+'</a>');
		}
		$('#previous_crumbs').append(other_crumbs).show();
	}else{
		ctext = window.location.pathname.replace(/\//g,'').replace(/\-/g,' ');
		$('#current_crumb').prepend('<a>'+ctext+'</a>');
		$('#new_crumbs').prepend('<img style="float:left;" src="/images/graphics/bm_theme/breadcrumbs/current-crumb-bgn.jpg">');
	}
};
//phonenumber
function phonenumberchange(){
	var tech = $('#cat_technical').html();
	tech = (tech == 'Yes' || tech == 'YES' || tech == 'yes' || tech == 'y')?true:false;
	if(!tech){
			$(".phone_number").each(function(){
				$(this).html("877.919.1904");
			});
	}
	else {
			$(".phone_number").each(function(){
				$(this).html("800.919.1904");
			});
	}
		
}

