//--------------------------------------//
//		QuickView Javascript Source		//
//--------------------------------------//

// variable init
disableOD = false;

var current_qv_color = '';

var current_swatch_name = '';
var current_swatch_id = '';
var qv_window_active = false;
var lb = false;

/* lightbox */
var lightbox = {
	id: "",

	init: function(id) {
		this.id = id;
	
		if(!document.getElementById("lightbox_black_container")) {
			var elem = document.createElement('div');
				elem.id = "lightbox_black_container";
			var d = document.getElementsByTagName('div')[0];
				d.parentNode.insertBefore(elem, d);
		}
		
		if(document.getElementById(id).className.indexOf("lightbox_content") === -1) {
			document.getElementById(id).className += " lightbox_content";
		}
		
		document.getElementById(id).style.display = 'none';
	},
	
	show: function() {
		var elem1 = document.getElementById("lightbox_black_container");
		var elem2 = document.getElementById(this.id);
	
		if (document.body.scrollHeight) {
			the_height = document.body.scrollHeight;
			elem1.style.height = the_height;
		}

		if (document.body.scrollWidth) {
			the_width = document.body.scrollWidth;
			elem1.style.width = the_width;
		}


		elem1.style.display = 'block';
		elem2.style.display = 'block';
//		elem2.style.marginLeft = ((elem2.clientWidth / 2) * -1) + "px";
//		elem2.style.marginTop = ((elem2.clientHeight / 2) * -1) + "px";
	},
	
	hide: function() {
//		var elem1 = document.getElementById("lightbox_black_container");
		jQuery("#lightbox_black_container").remove();
		var elem2 = document.getElementById(this.id);
//		elem1.style.display = 'none';
		elem2.style.display = 'none';
	}
};

/*
 *	rollover function to show the quickview button
 */
function showQVButton(prod)
{
	// get the appropriate button
	var divid = arguments[2]?'qv_btn_'+arguments[2]+'_'+prod:'qv_btn_'+prod;
	var div = document.getElementById(divid);
	if(arguments[1] && document.getElementById('quickview').style.display != "block")
	{
		// find the location of the caller and move the button to the correct spot
		var thumbid = arguments[2]?'prod_thmb_'+arguments[2]+'_'+prod:'prod_thmb_'+prod;
		var thumb = document.getElementById(thumbid);
		var thumbpos = findPos(thumb);
		var divy = Math.ceil(thumb.offsetHeight * 0.50);
		if(typeof(window.pageXOffset) == 'number')
		{
			// non-IE browsers
			div.style.left = thumbpos[0];
			div.style.top = thumbpos[1]+divy;
		}
		else
		{
			// IE
			div.style.left = thumbpos[0]+10;
			div.style.top = thumbpos[1]+divy+10;
		}
		// show button
		div.style.display = "block";
	}
	else
	{
		// hide button
		div.style.display = "none";
	}
	return false;
}

var hl_cache = Array();
var hl_max = 2;
var hm_cache = Array();
var hm_max = 2;
var pq = Array();
var quickview_mode = ''

//keep caches within size
function trim_caches(prod) {
	var hl_count = 0;
	var hl_first = '';
	var hm_count = 0;
	var hm_first = '';
	for (k in hl_cache) {
		if (hl_first == '' && k != prod) {
			hl_first = k;
		}
		if (hl_cache[k] != '') {
			hl_count++;
			if (hl_count > hl_max && k != prod) {
				hl_cache[hl_first] = new String('');
				break;
			}
		}
	}
	for (k in hm_cache) {
		if (hm_first == '' && k != prod) {
			hm_first = k;
		}
		if (hm_cache[k] != '') {
			hm_count++;
			if (hm_count > hm_max && k != prod) {
				hm_cache[hm_first] = new String('');
				break;
			}
		}
	}
}

/*
 *	opens the quickview window for the specific product
 */
function openQuickview(prod, x, mode)
{
	closeDetailPopups();

	trim_caches(prod);

	var final_top = 25;
	var final_left = 150;
	
	// build vars
	var pairs = [];
	pairs['id'] = prod;

	var mode_secondary = '';
	
	var local_flag = (window.location.href.indexOf("http://logosoftwear/") != -1 || window.location.href.indexOf("http://teamsportswer/") != -1) ? true : false;

	if (document.getElementById('step_one_in_between') && document.getElementById('step_one_in_between').style.display == 'block') {
		pairs['global_cart_upsell'] = 1;
	} else if (window.global_cross_sell && window.global_cross_sell !=  undefined) {
		pairs['global_cross_sell'] = 1;
	} 
	
	if (window.global_uniform_package && window.global_uniform_package != undefined) {
		pairs['global_uniform_package'] = 1;
	}
	
	if (window.global_ss_product_dashboard && window.global_ss_product_dashboard != undefined) {
		pairs['global_ss_product_dashboard'] = 1;
		mode = 'ss_product_dashboard';
	}
	
	if (window.global_packs && window.global_packs != undefined && (mode == undefined || (mode != 'blank_pi_bu' && mode != 'blank_pi'))) {
		pairs['global_packs'] = 1;
		mode = 'global_packs';
		mode_secondary = 'global_packs';

		if (window.global_packs_type && window.global_packs_type != undefined) {
			pairs['global_packs_type'] = window.global_packs_type;
		}
	}

	if (mode != undefined) {
		quickview_mode = mode;
	}

	if (mode != undefined) {
		pairs['mode'] = mode;
	} else {
		mode = 0;
	}

//	if (window.global_current_color_bin != undefined) {
//		pairs['global_current_color_bin'] = window.global_current_color_bin;		
//	}

	// set up ajax manager
//	var quickview = new sugar.ServerManager("/quickview/quickview_remote.php");
	var quickview = new sugar.ServerManager("/quickview/quickview_cache_remote.php");

	if (mode != undefined && mode == 'blank_pi_bu') {
		document.getElementById('quickloading').className = "quickloading_mini";
	} else {
		document.getElementById('quickloading').className = "quickloading";
	}
	
	quickview.startFunct = function(){document.getElementById("quickloading").style.display = "block";}
	quickview.endFunct = function(){document.getElementById("quickloading").style.display = "none";}
	
	if (mode != undefined && (mode == 'blank_pi_bu' || mode == 'blank_pi')) {
		document.getElementById('quickbar').innerHTML = 'Buy Blank Product';
	} else {
		document.getElementById('quickbar').innerHTML = 'Product Details';
	}

	if(!document.getElementById("qv_blocker")){
		var q = document.getElementById("quickview"),
			iframe = document.createElement('iframe');
		iframe.src="about:blank";
		iframe.id="qv_blocker";
		q.appendChild(iframe);
	}

	quickview.initPairs = pairs;

	// calculate top/left
	var y_offset = (typeof(window.pageYOffset) == 'number') ? window.pageYOffset : document.body.scrollTop;

	document.getElementById('quickview').className = 'quickview';
	document.getElementById('quickbar').className = 'quickbar';

	if (window.location.href.indexOf("logoworks2") == -1 && mode != undefined && (mode != 'blank_pi_bu' && mode != 'ss_product_dashboard')) {
		lb = lightbox;
		lb.init("quickview");
		lb.show();
	} else {
		document.getElementById("quickview").style.display = "block";	
	}

	try
	{
		var qvW = document.getElementById('quickview').style.width ? document.getElementById('quickview').style.width : 888;

		//var qvH = document.getElementById('quickview').style.height ? document.getElementById('quickview').style.height : 590;
		if(document.body.offsetWidth != undefined)
		{
			dW = document.body.offsetWidth;
			//dH = document.body.offsetHeight;
		}
		else
		{
			dW = window.innerWidth;
			//dH = window.innerHeight;
		}
		//final_top = Math.round((dH - qvH) / 2);
		final_top = y_offset + 25;

		if (mode != undefined && mode == 'blank_pi_bu') {
			final_left = Math.round(dW / 2);
			document.getElementById("quickview").className = 'quickview_mini';
			document.getElementById("quickbar").className = 'quickbar_mini';
			document.getElementById('quickresults').className = "quickresults_mini";
		} else {
			final_left = Math.round((dW - qvW) / 2);
		}
	}
	catch(err)
	{
		final_left = 150;
		final_top = 25;
	}

	if(x != undefined && x != null) 
	{
		final_left = x;
	} 
	
	// actually set top/left


	document.getElementById('quickview').style.top = final_top;	
	document.getElementById('quickview').style.left = final_left;		
	
//document.getElementById('quickview').style.display = "block";
	
	// launch ajax request and populate results

	/*
		for IE - just assigning innerhtml with tables in it doesn't work
		need to do proper removal of previous nodes
		create new div, assign innerhtml of that, then append that node
	*/

	//option to deactivate dragging temporarily
	if (window.no_drag_flag != undefined) {
		if (mode != undefined && mode == 'blank_pi_bu') {
//dont use no drag mode, although it is available
//			 window.no_drag_flag = true;
		} else {
			window.no_drag_flag = false;	
		}
	}

	if (window.no_zoom_flag != undefined) {
		if (mode != undefined && mode == 'blank_pi_bu') {
			 window.no_zoom_flag = true;
		} else {
			window.no_zoom_flag = false;	
		}
	}

	if (!local_flag && ((mode != undefined && mode != 'ss_product_dashboard' && mode == 'blank_pi_bu' && hm_cache[prod]) || (hl_cache[prod] != undefined && hl_cache[prod] != ''))) {
		var cell = document.getElementById("quickresults");
		if ( cell.hasChildNodes() )
		{
		    while ( cell.childNodes.length >= 1 )
		    {
		        cell.removeChild( cell.firstChild );       
		    } 
		}

//		var newdiv = document.createElement("quickresults_innerdiv");
		var newdiv = document.createElement("div");
		newdiv.name = "quickresults_innerdiv";
		if (mode != undefined && mode == 'blank_pi_bu') {
			results = newdiv.innerHTML = hm_cache[prod];
		} else {
			results = newdiv.innerHTML = hl_cache[prod];
		}

		var container = document.getElementById("quickresults");
		container.appendChild(newdiv);

		var js = results.match(/<script.*?>([\s\S]*?)<\/script>/gmi);
		var first_element_flag = true;;
		for (k in js) {
			//we just want k = 0, 1, 2, etc. to eval the javascript
			if (k == 'input' || k == 'index' || k == 'lastIndex') {
				continue;
			}

			var txt = new String(js[k]);

			eval_str = txt.replace(/\<script[\w\W]+?\>/i,"");
			eval_str = eval_str.replace(/\<\/script\s*\>/i,"");
			
			eval(eval_str);
		}

		restore_blank_qtys(prod)

		qv_window_active = true;

		return true;
	} else {
		sugar.yonder(quickview,function(results){
//			prompt('', results);
			var cell = document.getElementById("quickresults");
			if ( cell.hasChildNodes() )
			{
			    while ( cell.childNodes.length >= 1 )
			    {
			        cell.removeChild( cell.firstChild );       
			    } 
			}

//			var newdiv = document.createElement("quickresults_innerdiv");
			var newdiv = document.createElement("div");
			newdiv.name = "quickresults_innerdiv";
			newdiv.innerHTML = new String(results);
			var container = document.getElementById("quickresults");
			container.appendChild(newdiv);

//			document.getElementById("quickresults").innerHTML = new String(results);
			if (mode != undefined && mode != 'ss_product_dashboard' && mode != 'global_packs') {
				if (mode != undefined && mode == 'blank_pi_bu') {
					hm_cache[prod] = new String(results);
				} else {
					hl_cache[prod] = new String(results);				
				}
			}

			if (mode == 'global_packs' || mode_secondary == 'global_packs') {
				if (document.getElementById('qv_full_prod_link')) {
					document.getElementById('qv_full_prod_link').innerHTML = '';
				}
			}

			
			var js = results.match(/<script.*?>([\s\S]*?)<\/script>/gmi);
			var first_element_flag = true;;
			for (k in js) {
				//we just want k = 0, 1, 2, etc. to eval the javascript
				if (k == 'input' || k == 'index' || k == 'lastIndex') {
					continue;
				}
	
				var txt = new String(js[k]);
	
				eval_str = txt.replace(/\<script[\w\W]+?\>/i,"");
				eval_str = eval_str.replace(/\<\/script\s*\>/i,"");
				
				if (mode != undefined && mode == 'ss_product_dashboard') {
					if(!eval_str.match(/(\s*)?(((\w.*)(\.)(prototype\.))|((function)(\s*)?\(\)))/gmi)) {
						try {
							eval(eval_str);
						} catch(e) {}
					} 
				} else {
					eval(eval_str);
				}
			}

//			accordion_initialize(true);
/*
		if (window.global_design_cat_id != undefined && document.getElementById("load_script")) {
			eval(document.getElementById("load_script").innerHTML);
		}

		if (window.global_current_color_bin != undefined && document.getElementById("auto_color_image_swap")) {
			eval(document.getElementById("auto_color_image_swap").innerHTML);
		}
		
		if (document.getElementById("color_lookup_script")) {
			if (window.execScript) {
				window.execScript(document.getElementById("color_lookup_script").innerHTML);
			} else {
				eval(document.getElementById("color_lookup_script").innerHTML);
			}
		} else {
		}
*/
			qv_window_active = true;

//			jQuery("body").html(jQuery("body").html() + '<div id="debugtestins"><div class="lightbox" style="background: black; width: 100%; height: 100%; z-index: 50000000; position: fixed; *position: absolute; top: 0px; left: 0px; opacity: 0.3; filter: alpha(opacity=30);"></div></div>');
//			jQuery("body").html(jQuery("body").html() + '<div class="lightbox" style="position: fixed; *position: absolute; top: 50%; left: 50%; z-index: 50000000002 !important; margin-top: -189px; margin-left: 292px; cursor: pointer;"><a href="javascript:hideLB();"><img src="http://www.logosoftwear.com/images_graphics/modals/yt_lightbox_close.png" border="0" width="32" height="32" /></a></div>');
//			jQuery(".lightbox").css('display', 'inline-block');

			return true;
		});
	}
}

/*
 *	clear and close the quickview window
 */
function closeQuickview()
{
	document.getElementById('quickview').style.display = "none";
	document.getElementById('quickresults').innerHTML = "";
	document.getElementById('quickresults').className = "quickresults";
	document.getElementById('quickloading').className = "quickloading";
		
	closeDetailPopups();
	
	//set blowup image back to default when closing blank_pi_bu and no color is selected
	if (quickview_mode == 'blank_pi_bu') {
		if (!window.garment_color || window.garment_color.value != '' || window.garment_color.selectedIndex > 0) {
			prodImageSwap('detailPage_image')
		}
	}

	quickview_mode = '';

	//activate dragging when closing quickview
	if (window.no_drag_flag != undefined) {
		 window.no_drag_flag = false;
	}

	if (window.no_zoom_flag != undefined) {
		 window.no_zoom_flag = false;
	}

	current_swatch_name = '';
	current_swatch_id = '';

//	current_qv_color = '';
	
	qv_window_active = false;
	
	try {
	lb.hide();
	}catch(e) {}

	jQuery(".quickview_button").each(function() {this.style.display = 'none';});
	jQuery(".quickview_button_over").each(function() {this.style.display = 'none';});
}
	
function disableLaunch(check, btn)
{
	if(check)
	{
		disableOD = true;
		btn.className = "quickview_button_over";
	}
	else
	{
		disableOD = false;
		btn.className = "quickview_button";
	}
	
	return false;
}

function closeDetailPopups() {
	if (document.getElementById('twill_details')) {
		document.getElementById('twill_details').style.display = 'none';
	}
	if (document.getElementById('monogram_details')) {
		document.getElementById('monogram_details').style.display = 'none';
	}

}

/*
 *	changes the quickview blowup product image's color
 */
function qvColorChange(id,place,color,name,qv,df,actual_swatch_num, the_element)
{
	var qv_swatch_clicked = (the_element != undefined && the_element.id != undefined && the_element.id.indexOf('qv_swatch_') > -1) ? true : false;

	/*
	document.getElementById('quickloading').style.display = "block";
	setTimeout(function(){
		document.getElementById('quickloading').style.display = "none";
	}, 2000);
	*/
	input_name = name;

	if(place == undefined)
	{
		return false;
	}
	else
	{
		if(color == undefined)
		{
			color = "ffffff";
			name = "white";
		}
		
		// throw in some underscores for non IE browsers

		setLastColor(color);

//		name = name.replace(/ /g,"_");
		name = name.replace(/ /g,"+");
		url_color_name = name.replace(/\(/g,"+");
		url_color_name = url_color_name.replace(/\)/g,"+");
		
		if(qv)
		{
			url = 'http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=' + place + '&color=' + color + '&colorname=' + url_color_name + '&quickview=1&designer_type=sign&height=250&quickview_set_color=1';
		}
		else
		{
			url = 'http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=' + place + '&color=' + color + '&colorname=' + url_color_name + '&designer_type=sign&height=250&quickview_set_color=1';
		}

		if(document.getElementById('qv_reverse_swatch_' + id))
		{
			document.getElementById('qv_reverse_swatch_' + id).src = '/quickview/quickview_reverse_swatch.php?c=' + color;
			document.getElementById('qv_reverse_swatch_' + id).style.display = 'block';
		}

		document.getElementById('product_blowup_'+id).style.background = 'url(' + url + ') no-repeat';
		document.getElementById('product_blowup_'+id).style.backgroundPosition = 'center';
		document.getElementById('product_blowup_'+id).style.backgroundColor = "#FFFFFF";
		//document.getElementById('product_enlarge_'+id).href = 'http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=' + place + '&color=' + color + 'colorname=' + name + '&designer_type=clipart';

//		alert(input_name + ' ' + color);

		if (document.getElementById('garment_color')) {
			set_dropdown_value('garment_color', input_name);
			set_swatch_hex('swatch_color', color); 						 

			if (quickview_mode != 'undefined' && quickview_mode == 'blank_pi_bu') {
				prodImageSwap('product_blowup_'+id);
			}
		}
	}

	//actual clicking on a swatch
	if (document.getElementById('current_color_name_div')) {
		document.getElementById('current_color_name_div').innerHTML = 'Current Color: ' + decodeURIComponent(name).replace(/\+/g," ");
		current_swatch_name = 'Current Color: ' + decodeURIComponent(name).replace(/\+/g," ");

		if (the_element != undefined && the_element.id != undefined && the_element.id != '') {
			if (current_swatch_id && current_swatch_id != the_element.id && document.getElementById(current_swatch_id)) {
				document.getElementById(current_swatch_id).className = 'qv_swatch';
			}
			current_swatch_id = the_element.id;
		} else {
			current_swatch_id = '';
		}

		if (the_element != undefined) {
			if (the_element.className == 'qv_swatch') {
				swatch_elements = getElementsByClassName('qv_swatch_selected_state');
				for (i = 0; i < swatch_elements.length; i++) {
					swatch_elements[i].className = 'qv_swatch';		
				}
				the_element.className == 'qv_swatch' + ' qv_swatch_selected_state';
			} else {
				swatch_elements = getElementsByClassName('qv_swatch');
				for (i = 0; i < swatch_elements.length; i++) {
					if (swatch_elements[i].title == decodeURIComponent(name).replace(/\+/g," ") && (!qv_swatch_clicked || swatch_elements[i].id.indexOf('qv_swatch_') > -1)) {
						swatch_elements[i].className = 'qv_swatch' + ' qv_swatch_selected_state';
						current_swatch_id = swatch_elements[i].id;
					} else {
						swatch_elements[i].className = 'qv_swatch';		
					}			
				}
			}
		} else {
			swatch_elements = getElementsByClassName('qv_swatch');
			for (i = 0; i < swatch_elements.length; i++) {
				if (swatch_elements[i].title == decodeURIComponent(name).replace(/\+/g," ")) {
					swatch_elements[i].className = 'qv_swatch' + ' qv_swatch_selected_state';
					current_swatch_id = swatch_elements[i].id;
				} else {
					swatch_elements[i].className = 'qv_swatch';		
				}			
			}
		}
	}

	return false;
}

function reset_qv_image(id) {
	if (document.getElementById('orig_bg_url')) {
		var bg_url = document.getElementById('orig_bg_url').value;
		var bg_position = document.getElementById('orig_bg_position').value;	
		var bg_color = document.getElementById('orig_bg_color').value;	
	
		document.getElementById('product_blowup_'+id).style.background = 'url(' + bg_url + ') no-repeat';
		document.getElementById('product_blowup_'+id).style.backgroundPosition = bg_position;
		document.getElementById('product_blowup_'+id).style.backgroundColor = bg_color;

		swatch_elements = getElementsByClassName('qv_swatch_selected_state');
		for (i = 0; i < swatch_elements.length; i++) {
			swatch_elements[i].className = 'qv_swatch';		
		}

		if (document.getElementById('current_color_name_div')) {
			document.getElementById('current_color_name_div').innerHTML = '&nbsp;';
			current_swatch_name = '';
		}
	}
		
	set_swatch_color('swatch_color', '');

	if (window.reset_current_swatch != undefined) {
		reset_current_swatch();	
	}
}

/*
 *	loads & unloads larger/alternate view area of quickview
 */

function showLargerImages(id)
{
	// check if large area is active, and disable or enable based on status
	var sml = document.getElementById('qv_product_media');
	var lrg = document.getElementById('alternateLargerViewsDiv');
	var img = document.getElementById('alternateLargerViewsImg');
	var alt = document.getElementById('alternateLargerViewsThumbs');
	var tog = lrg.style.display == 'block' ? false : true;

	var i = 1;
	while(document.getElementById('qv_pinfo_panel' + i))
	{
		document.getElementById('qv_pinfo_panel' + i).className = tog ? 'qv_pinfo_panels_minimized' : 'qv_pinfo_panels';
		i++;
	}
	
	if(!tog)
	{
		lrg.style.display = 'none';
		alt.style.display = 'none';
		sml.style.display = 'block';
	}
	else
	{
		sml.style.display = 'none';
		alt.style.display = 'block';
		lrg.style.display = 'block';
		img.style.background = 'url(http://www.logosoftwear.com/images_products2/' + id + '/' + id + '.large.jpg) no-repeat';
		swap_qv_pinfo_tabs(1);
	}
	return false;
}

/*
 *	this function disables the launch of the designer 
 *	when hooooovering over the quick view button
 */
function disableLaunch(check, btn)
{
	if(check)
	{
		disableOD = true;
		btn.className = "quickview_button_over";
	}
	else
	{
		disableOD = false;
		btn.className = "quickview_button";
	}
}

/* 
 *	this function works in conjuction with disable launch to launch 
 *	the appropriate designer at the appropriate time when quickview is enabled
 */
function launchDesigner(id)
{
	var mode = arguments[1] ? arguments[1] : 'clipart';	// designer type
	var piece = arguments[2] ? arguments[2] : 0;		// piece id for embroidery
	var design = arguments[3] ? arguments[3] : 0;		// design id
	var colorscheme = arguments[4] ? arguments[4] : 1;	// colorscheme of the design
	if(!disableOD)
	{
		if(piece)
		{
			clipart_window(id, 18160, 2, -1, 'embr', piece);
		}
		else if(design)
		{
			clipart_window(id, design, colorscheme, 0, mode); 
		}
		else
		{
			clipart_window(id, 0, 0, 1, mode); 
		}
	}
	return false;
}

function showSwatchImg(tog)
{
	if(tog)
	{
		document.getElementById('alternateLargerViewsImg').style.display = 'none';
		document.getElementById('alternateSwatchImg').style.display = 'block';
	}
	else
	{
		document.getElementById('alternateLargerViewsImg').style.display = 'block';
		document.getElementById('alternateSwatchImg').style.display = 'none';
	}
	return false;
}

function setLastColor(c)
{
	var r = '/global_files/remote_scripts/productpi_session_mgr.php?c=' + c;
	sugar.yonder(r, function(){});
	
	return false;
}

function swap_qv_pinfo_tabs(tab)
{
	document.getElementById('qv_pinfo_panel' + tab).style.display = 'block';
	document.getElementById('qv_pinfo_tab' + tab).className = 'qv_pinfo_tabs qv_hl';
	var i = 1;
	while(document.getElementById('qv_pinfo_panel' + i))
	{
		if(i != tab)
		{
			document.getElementById('qv_pinfo_panel' + i).style.display = 'none';
			document.getElementById('qv_pinfo_tab' + i).className = 'qv_pinfo_tabs';
		}
		i++;
	}
	return false;
}

function qvShopsiteButtonRollover(el) {
	var ext = ".gif"; //extension
	var over = "_over"+ext; //rollover string
	if(el.src.indexOf(over)!=-1) {
	  el.src = el.src.replace(over,ext); //replace ext with over
	} else {
 	  el.src = el.src.replace(ext,over); //replace over with ext
	}
}

function helpManager(el,help,qv){
	var $ = function(a){
  		return document.getElementById(a);
 	};
	
	var twill_key = 'twill';
	if(help.id == 'felt_details')
	{
		twill_key = 'felt';
	}
	
	var twill = $(twill_key + '_details'),
	twill_contents = $(twill_key + '_details_contents'),
  	monogram = $('monogram_details'),
  	monogram_contents = $('monogram_details_contents'),
  	screen = $('screen_details'),
  	screen_contents = $('screen_details_contents'),
  	content_class='bubble_details_contents_quickview',
  	bubble_class='bubble_details_quickview',
  	b_top=0,
  	b_left=0,
  	bubble;
 	if(qv || 1){
  		b_top-=230;
  		b_left-=310;
  		//if($('quickview')){
   		//	el=$('quickview');
  		//}
 	}else{
  		b_top-=232;
  		b_left+=2;
  		content_class='bubble_details_contents_blowup';
  		bubble_class='bubble_details_blowup';
 	}
 	var pos = findPos(el);
  	b_top += pos[1];
  	b_left += pos[0];
  	if(b_top<0){
   		b_top=0;
  	}
 	if(help == twill){
  		monogram.style.display='none';
  		monogram.className='';
  		screen.style.display='none';
  		screen.className='';
  		bubble=twill;
  		bubble_contents = twill_contents;
 	}else if(help == monogram){
  		twill.style.display='none';
  		twill.className='';
  		screen.style.display='none';
  		screen.className='';
  		bubble=monogram;
  		bubble_contents = monogram_contents;
 	}else if(help == screen){
  		monogram.style.display='none';
  		monogram.className='';
  		twill.style.display='none';
  		twill.className='';
  		bubble=screen;
  		bubble_contents = screen_contents;
 	}
 	if(bubble){
  		bubble.className=bubble_class;
  		bubble_contents.className = content_class;
  		bubble.style.top = b_top;
  		bubble.style.left = b_left;
  		bubble.style.display='block';
 	}
}

//used the cached pq array to reset the form, and recalculate
function restore_blank_qtys(prod) {
	if (pq[prod] != undefined && pq[prod] != '') {
		if (document.getElementById('size_charge_str')) {
			var size_charge_str = new String(pq[prod]);
			size_price_pairs = size_charge_str.split('||');
			for (i = 0; i < size_price_pairs.length; i++) {
				size_price_pair = size_price_pairs[i].split('|');
				document.getElementById('sizes['+size_price_pair[0]+']').value = size_price_pair[1];
			}

			calculate_blank_price();
		}
	}
}

function calculate_blank_price() {
	var size_charge = Array();
	var qty_price = Array();
	var total_qty = 0;
	var total_price = 0;
		
	var size_charge_str = document.getElementById('size_charge_str').value;

	//set the pq cache array from the form
	if (document.getElementById('product_id')) {
		var product_id = document.getElementById('product_id').value;
		size_charge_reset_array = size_charge_str.split('||');
	
		var all_size_qty_reset_array = new Array();
		for (i = 0; i < size_charge_reset_array.length; i++) {
			size_charge_reset = size_charge_reset_array[i].split('|');
			var size_qty_element = document.getElementById('sizes['+size_charge_reset[0]+']');
			if (size_qty_element) {
				qty = size_qty_element.value;
				all_size_qty_reset_array[i] = size_charge_reset[0] + '|' + Number(qty);
			} else {
				alert("Problem with a size");
				return;		
			}
		}
	
		pq[product_id] = all_size_qty_reset_array.join('||');
	}
	
	var size_price_pairs = size_charge_str.split('||');
	for (i = 0; i < size_price_pairs.length; i++) {
		size_price_pair = size_price_pairs[i].split('|');
		size_charge[size_price_pair[0]] = size_price_pair[1];
//		alert(size_price_pair[0] + ' ' + size_price_pair[1] + ' ' + size_charge[size_price_pair[0]]);
	}

	var qty_price_str = document.getElementById('qty_price_str').value;
	
	var qty_price_pairs = qty_price_str.split('||');
	for (i = 0; i < qty_price_pairs.length; i++) {
		qty_price_pair = qty_price_pairs[i].split('|');
		qty_price[qty_price_pair[0]] = qty_price_pair[1];
//		alert(qty_price[qty_price_pair[0]]);
	}

	var blank_unit_price = 0;
	var blank_total_upsize_charges = 0;
	var blank_upsize_charges = 0;
	var blank_quantity = 0;
	var blank_price_each = 0;
	var blank_total_price = 0;
	
	for (size in size_charge) {
		upsize_charge = size_charge[size];
		q_TMP = document.getElementById('sizes['+size+']').value;
		if(q_TMP != 'undefined')
		{
			q_TMP = 0 + Number(q_TMP.replace(/[^0-9]/gi, ""));
			if(!q_TMP || isNaN(q_TMP))
			{
				q_TMP = 0;
			}
			if(q_TMP != '')
			{
				 document.getElementById('sizes['+size+']').value = q_TMP;
			}
			
			blank_quantity += q_TMP;
			blank_total_upsize_charges += (q_TMP * upsize_charge);
		}
	}

	var lastBreak = 1;
	for(k in qty_price)
	{
		if(k <= blank_quantity)
		{
			lastBreak = k;
		}
		else
		{
			break;
		}
	}
	
	blank_upsize_charges = (blank_total_upsize_charges && blank_quantity) ? (blank_total_upsize_charges / blank_quantity) : 0;

	var minimum_quantity = Number(document.getElementById('minimum_quantity_str').value);

	if (Number(lastBreak) < minimum_quantity && qty_price[minimum_quantity]) {
		blank_unit_price = qty_price[minimum_quantity];
	} else {
		blank_unit_price = qty_price[lastBreak];
	}
		
//	alert(lastBreak + ' ' + qty_price[lastBreak] + ' ' + blank_upsize_charges);

	blank_price_each = Number(blank_unit_price) + Number(blank_upsize_charges);
	
	blank_total_price = blank_total_upsize_charges + (blank_quantity * blank_unit_price);

	document.getElementById('blank_unit_price').value = Number(blank_unit_price).toFixed(2);
	document.getElementById('d_blank_unit_price').innerHTML = '$' + Number(blank_unit_price).toFixed(2);
	document.getElementById('blank_upsize_charges').value = Number(blank_upsize_charges).toFixed(2);
	document.getElementById('d_blank_upsize_charges').innerHTML = '$' + Number(blank_upsize_charges).toFixed(2);
	document.getElementById('blank_quantity').value = blank_quantity;
	document.getElementById('d_blank_quantity').innerHTML = blank_quantity;
	document.getElementById('blank_price_each').value = Number(blank_price_each).toFixed(2);
	document.getElementById('d_blank_price_each').innerHTML = '$' + Number(blank_price_each).toFixed(2);
	document.getElementById('blank_total_price').value = Number(blank_total_price).toFixed(2);
	document.getElementById('d_blank_total_price').innerHTML = '$' + Number(blank_total_price).toFixed(2);
}

function submit_blank_to_cart() {
	calculate_blank_price();
	
	var minimum_quantity = Number(document.getElementById('minimum_quantity_str').value);

	if (isNaN(document.getElementById('blank_quantity').value)) {
		alert('Must enter valid quantities');
		return;
	} else if (Number(document.getElementById('blank_quantity').value) < minimum_quantity) {
		alert('Must enter at least minimum quantity of ' + minimum_quantity);
		return;
	}

	var garment_color = '';
	if(document.getElementById('garment_color')) {
		if (document.getElementById('garment_color').selectedIndex != undefined) {
			if (document.getElementById('garment_color').selectedIndex == 0) {
				alert("Please Choose a Color Before Proceeding");
				return;
			} else {
				var garment_color_element = document.getElementById('garment_color');
				garment_color = garment_color_element[garment_color_element.selectedIndex].value;
			}
		} else {
			garment_color = document.getElementById('garment_color').value;
		}
	}
	
	var size_charge_str_element = document.getElementById('size_charge_str');

	if (!size_charge_str) {
		alert("Problem with sizes");	
		return;
	}

	size_charge_array = size_charge_str_element.value.split('||');

	var all_size_qty_array = new Array();
	for (i = 0; i < size_charge_array.length; i++) {
		size_charge = size_charge_array[i].split('|');
		size = size_charge[0];
		var size_qty_element = document.getElementById('sizes['+size+']');
		if (size_qty_element) {
			qty = size_qty_element.value;
			all_size_qty_array[i] = size + '|' + Number(qty);
		} else {
			alert("Problem with a size");
			return;		
		}
	}
	
	var all_size_qty_str = all_size_qty_array.join('||');
	var total_qty = Number(document.getElementById('blank_quantity').value);
	var average_price =  Number(document.getElementById('blank_price_each').value);
	var product_id = document.getElementById('product_id').value;

	var url = 'http://www.logosoftwear.com/quickview/blank_shopping_cart_redirect.php';
	url += '?all_size_qty=' + encodeURIComponent(all_size_qty_str);
	url += '&average_price=' + encodeURIComponent(average_price);
	url += '&total_qty=' + encodeURIComponent(total_qty);
	url += '&product_id=' + encodeURIComponent(product_id);
	url += '&garment_color=' + encodeURIComponent(garment_color);
	
	if (document.getElementById('rgb')) {
		url += '&rgb=' + encodeURIComponent(document.getElementById('rgb').value);
	} else {
		url += '&rgb=';	
	}

	//common IE 6 hack
	setTimeout(function()
	{
    	window.location = url;
	}, 0);	
}

function set_dropdown_by_text(element_id, text) {
	var dropdown_element = document.getElementById(element_id);

	if (dropdown_element) {
		for (i = 0; i < dropdown_element.length; i++) {
			opt_text = dropdown_element[i].text;
			if (opt_text == text) {
				dropdown_element.selectedIndex = i;
				break;
			}
		} 
	}
}

function set_dropdown_value(element_id, val) {
	var dropdown_element = document.getElementById(element_id);

	if (dropdown_element) {
		for (i = 0; i < dropdown_element.length; i++) {
			opt_value = dropdown_element[i].value;
			if (opt_value == val) {
				dropdown_element.selectedIndex = i;
				break;
			}
		} 
	}
}
	
function set_text_value(element_id, val) {
	var text_element = document.getElementById(element_id);
	
	text_element.value = val;
}

function set_swatch_color(element_id, colors) {
	if (colors == '') {
		var div_element = document.getElementById(element_id);
		div_element.innerHTML = '';					
		if (document.getElementById('rgb')) {
			document.getElementById('rgb').value = '';
		}
	} else {
		if (color_hex_lookup[colors]) {
			set_swatch_hex(element_id, color_hex_lookup[colors]);			
			if (document.getElementById('rgb')) {
				document.getElementById('rgb').value = color_hex_lookup[colors];
			}
		} else if (color_hex_lookup) {			
			set_swatch_hex(element_id, 'FFFFFF');			
			if (document.getElementById('rgb')) {
				document.getElementById('rgb').value = '';
			}			
		}
	}

	if (window.reset_current_swatch != undefined) {
		reset_current_swatch();	
	}
}

function set_swatch_hex(element_id, hex_vals) {
	var div_element = document.getElementById(element_id);

	if (!div_element) {
		return;
	}

	if (hex_color_lookup && !hex_color_lookup[hex_vals]) {
		var hex_colors = new Array();
		hex_colors[0] = 'FFFFFF';
	} else {
		var hex_colors = hex_vals.split(',');
	}

	if (hex_vals == '') {
		div_element.innerHTML = '';
		if (document.getElementById('rgb')) {
			document.getElementById('rgb').value = '';
		}			
	} else if (hex_colors.length == 1) {
		div_element.innerHTML = '<div class="qv_swatch" style="float:left; background-color:#' + hex_colors[0] + '"></div>';					
		if (document.getElementById('rgb')) {
			document.getElementById('rgb').value = hex_colors[0];
		}			
	} else {
		div_element.innerHTML = '';

		var width_override = '';
		if (hex_colors.length == 3){
			width_override = ' width:17px;';
		} else if (hex_colors.length == 3){
			width_override = ' width:18px;';
		}
		width = Math.round((1 / hex_colors.length) * 100);

		var multi_swatches = '';
		for (var i = 0; i < hex_colors.length; i++) {
			multi_swatches += '<div style="width:' + width + '%;background-color:#'+hex_colors[i] + ';" class="qv_swatch_col"></div>';
		}	
		div_element.innerHTML = '<div class="qv_swatch" ' + ' style="float:left;'+width_override+'">' + multi_swatches + '</div>';					

		if (document.getElementById('rgb')) {
			document.getElementById('rgb').value = hex_colors.join(',');
		}			
	}				
}

// Change tab in tabbed detail info box
function change_prodTab(tName)
{
	var curPanel = document.getElementById(tName);
	var curTab = document.getElementById(tName + "_tab");
	var panelSet = document.getElementById("prodTab_panels");
	
	if(curPanel && curTab && panelSet)
	{
		var kid = panelSet.firstChild;
		curPanel.className = "prodTab_selectedPanel";
		curTab.className = "prodTab_selectedTab";
		
		while(kid)
		{
			if(kid.id)
			{
				if(kid.id != tName)
				{
					kid.className = "prodTab_unselectedPanel";
					document.getElementById(kid.id + "_tab").className = "prodTab_unselectedTab";
				}
			}
			
			kid = kid.nextSibling;
		}
	}
	
	return true;
}

//Change colors on the placement image
function detail_ColorChange(id, place, color, name, qv)
{
	input_name = name;

	//make firefox encoding compatible
	name = name.replace(/\s/i, "+");
	name = name.replace(/\(/, "%28");
	name = name.replace(/\)/, "%29");
	
	var canvas = document.getElementById(id);
//	var loading = document.getElementById("quickloading");
	var loading = false;
	
	if(canvas)
	{
		if(loading)
		{
			//don't show the quickloading div when swapping colors for buying blanks
			if (!document.getElementById("garment_color")) {
				loading.style.display = "block";
			}
			setTimeout(function(){
				document.getElementById("quickloading").style.display = "none";
			}, 2000);
		}
		
		if(place == undefined)
		{
			return false;
		}
		else
		{
			if(color == undefined)
			{
				color = "ffffff";
				name = "white";
			}
			else
			{
				// update form field for productPI
				try
				{
					var colHexSelected = document.getElementById('color_hex_selected');
					if(colHexSelected != null)
					{
						document.getElementById('color_hex_selected').value = color;
					}
				}
				catch(err){}
			}
			
			// throw in some underscores for non IE browsers
			setLastColor(color);
			if (window.current_qv_color != undefined) {
				current_qv_color = color;
			}
			name = name.replace(/ /g,"_");
			if(qv)
			{
				var params = "placement_id=" + place + "&color=" + color + "&colorname=" + name + "&quickview=1&designer_type=sign&height=250&quickview_set_color=1";
				url = "http://www.logosoftwear.com/personalize/functions_image/bgimage.php?" + params;
			}
			else
			{
				var params = "placement_id=" + place + "&color=" + color + "&colorname=" + name + "&designer_type=sign&height=250&quickview_set_color=1";
				url = "http://www.logosoftwear.com/personalize/functions_image/bgimage.php?" + params;
			}

			canvas.style.background = "url(" + url + ") no-repeat";
			canvas.style.backgroundPosition = "center";
			canvas.style.backgroundColor = "#FFFFFF";
			//document.getElementById(\'product_enlarge_\'+id).href = "http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=" + place + "&color=" + color + "colorname=" + name + "&designer_type=clipart";
		}

		if (document.getElementById('garment_color')) {
			set_dropdown_value('garment_color', input_name);
			set_swatch_hex('swatch_color', color); 						 
		}
	}
	return false;
}

// Change Image/(tab) in Lifestyle/color-changing section
function prodImageSwap(divID)
{
	document.getElementById('detailPage_origImgBtn').style.display = "";
	var img = document.getElementById(divID);
	var box = document.getElementById("prodImg_box");
	
	if(img && box)
	{
		var kid = box.firstChild;
		img.style.display = "block";
		
		while(kid)
		{
			if(kid.id)
			{
				if(kid.id != divID)
				{
					kid.style.display = "none";
				}
			}
			
			kid = kid.nextSibling;
		}
	}
	
	return true;
}

function setLastColor(c)
{
	var r = '/global_files/remote_scripts/productpi_session_mgr.php?c=' + c;
	sugar.yonder(r, function(){});

	window.current_qv_color = c;

	return false;
}

function initialize_color_selection(c)
{
	
	var box = document.getElementById("prodImg_box");
	if (!box) {
		return false;
	}

	var divs = document.getElementsByTagName("div");
	var sDiv = divs['prodImg_box'];
	while (sDiv.className != 'detailPage_swatchPanel')
	{
		sDiv = sDiv.nextSibling
	}
	
	c = c.toLowerCase();
	cDiv = sDiv.firstChild;
	while(cDiv.nextSibling != undefined)
	{
		var col = cDiv.onclick.toString().split('detail_ColorChange');
		col = col[1].indexOf('"') != -1 ? col[1].toLowerCase().split('",') : col[1].toLowerCase().split("',");
		col = col[2].substring(1);
		if(col.indexOf(c) != -1)
		{
			cDiv.onclick();
			break;
		}
		cDiv = cDiv.nextSibling;
	}
	
	return false;
}

function pz_info_scoll_anchor(elem_id, product_id)
{
	if (window.jQuery && jQuery != undefined) {
		try
		{
			var pz_scrl = jQuery(elem_id).position().top - jQuery('#prodTab_decor_'+product_id).position().top;
			jQuery('#prodTab_decor_'+product_id).scrollTop(pz_scrl - 30);
		} catch(err) {
			try {
				var pz_scrl = jQuery(elem_id).position().top - jQuery('#qv_pinfo_panel4').position().top;
				jQuery('#qv_pinfo_panel4').scrollTop(pz_scrl - 30);
			} catch(err2) {
	
			}
		}
	}
}

function set_panel_height(element_id, the_height) {
	if (document.getElementById(element_id)) {
		var str = document.getElementById(element_id).innerHTML;
		if (str.indexOf('Garment Measurements') >= 0) {
			document.getElementById(element_id).style.height = the_height;
		}
	}
}

function accordion_initialize(qv_mode, more_than_one) {
	if (qv_mode) {
		qv_append = '_qv';
	} else {
		qv_append = '';
	}

	if (window.jQuery != undefined) {
		if (qv_mode && more_than_one != undefined && more_than_one) {
			subs_collapse_all(qv_mode);
		} else {
			subs_collapse(1, qv_mode);
		}
		
		jQuery(".accordion_wrapper"+qv_append).hover(
			function() {
				var iter = (this.id).replace("accordion_wrapper_", "");
				iter = iter.replace("_qv", "");
				jQuery("#accordion_handle_inner_" + iter + qv_append + "").removeClass('accordion_handle_inner'+qv_append).addClass('accordion_handle_inner_hover'+qv_append);
			},
			function() {
				var iter = (this.id).replace("accordion_wrapper_", "");
				iter = iter.replace("_qv", "");
				jQuery("#accordion_handle_inner_" + iter + qv_append + "").addClass('accordion_handle_inner'+qv_append).removeClass('accordion_handle_inner_hover'+qv_append);
			}
		);
	}
}

var collapse_state = Array();
var collapse_open_count = Array();

function toggle_collapse(id, qv_mode, more_than_one) {
	if (qv_mode) {
		qv_append = '_qv';
		collapse_index = 'qv';

		if (0 && more_than_one != undefined && more_than_one) {
			if (collapse_state[collapse_index][id] != undefined) {
				if (collapse_state[collapse_index][id]) {
					if (collapse_open_count[collapse_index] > 0) {
						collapse_state[collapse_index][id] = 0;
						collapse_open_count[collapse_index]--;
						jQuery("#accordion_" + id + "_coll"+qv_append).slideUp(200, function() {
							jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
							jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
						});
					}
				} else {
					collapse_state[collapse_index][id] = 1;
					collapse_open_count[collapse_index]++;							
					jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
						jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
						jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
						});
				}
			} else {
				collapse_state[collapse_index][id] = 1;
				collapse_open_count[collapse_index]++;
				jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
					jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
					jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
					});
			}
		} else {
			expand_flag = true;
	
//			alert(collapse_index + ' ' + collapse_state[collapse_index].length);
			if (collapse_state[collapse_index][id] != undefined && collapse_state[collapse_index][id]) {
//				alert(id);
				collapse_state[collapse_index][id] = 0;
				collapse_open_count[collapse_index] = 0;
				jQuery("#accordion_" + id + "_coll"+qv_append).slideUp(200);
				jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
				jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
				expand_flag = false;
			}
	
			if (expand_flag) {
				jQuery(".collapsible"+qv_append).not("#accordion_" + id + "_coll"+qv_append).slideUp(200, function() {
					jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
						collapse_state[collapse_index] = Array();
					
						collapse_state[collapse_index][id] = 1;
						collapse_open_count[collapse_index] = 1;
						jQuery(".collapsible_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
						jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
					});
				});
				
				jQuery(".accordion_handle").css("cursor", "pointer");
				jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
			}
		}
	} else {
		qv_append = '';
		collapse_index = 'bu';

		if (collapse_state[collapse_index][id] != undefined) {
			if (collapse_state[collapse_index][id]) {
				if (collapse_open_count[collapse_index] > 0) {
					collapse_state[collapse_index][id] = 0;
					collapse_open_count[collapse_index]--;
					jQuery("#accordion_" + id + "_coll"+qv_append).slideUp(200, function() {
						jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
						jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
					});
				}
			} else {
				collapse_state[collapse_index][id] = 1;
				collapse_open_count[collapse_index]++;							
				jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
					jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
					jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
					});
			}
		} else {
			collapse_state[collapse_index][id] = 1;
			collapse_open_count[collapse_index]++;
			jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
				jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
				jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
				});
		}
	}
}

function subs_collapse_all(qv_mode) {
	if (qv_mode) {
		qv_append = '_qv';
		collapse_index = 'qv';
	} else {
		qv_append = '';
		collapse_index = 'bu';		
	}

	collapse_state[collapse_index] = Array();
	collapse_open_count[collapse_index] = 0;

	jQuery(".collapsible_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
	
	jQuery(".accordion_handle"+qv_append).css("cursor", "pointer");
}
	
function subs_collapse(id, qv_mode) {
	if (qv_mode) {
		qv_append = '_qv';
		collapse_index = 'qv';
	} else {
		qv_append = '';
		collapse_index = 'bu';		
	}

	collapse_state[collapse_index] = Array();
	collapse_open_count[collapse_index] = 0;

	collapse_open_count[collapse_index] = 1;
	collapse_state[collapse_index][id] = 1;

	jQuery(".collapsible"+qv_append).not("#accordion_" + id + "_coll"+qv_append).slideUp(500, function() {
		jQuery("#accordion_" + id + "_coll"+qv_append).slideDown(200, function() {
			jQuery(".collapsible_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/plus.png');
			jQuery("#accordion_" + id + "_coll_img"+qv_append).attr('src', 'http://www.logosoftwear.com/images_graphics/product-ab-test/minus.png');
		});
	});
	
	jQuery(".accordion_handle"+qv_append).css("cursor", "pointer");
//	jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "default");
	jQuery("#accordion_handle_" + id + qv_append + "").css("cursor", "pointer");
}

function swatch_mouseover(name, the_element) {
	if (document.getElementById('current_color_name_div')) {
		document.getElementById('current_color_name_div').innerHTML='Swatch Color: ' + name;
	} else {
		document.getElementById('current_color_name_div').innerHTML='&nbsp;';
	}

	the_element.className = 'qv_swatch ' + 'qv_swatch_hover_state';
}

function swatch_mouseout(name, the_element) {
	if (document.getElementById('current_color_name_div')) {
		if (current_swatch_name) {
			document.getElementById('current_color_name_div').innerHTML = current_swatch_name;			
			if (the_element.id != current_swatch_id) {
				the_element.className = 'qv_swatch';
			}
		} else {
			document.getElementById('current_color_name_div').innerHTML='&nbsp;';
			the_element.className = 'qv_swatch';
		}
	}
}

function altMatch_swatch_mouseover(name, the_element) {
	if (document.getElementById('current_altMatch_color_name_div')) {
		document.getElementById('current_altMatch_color_name_div').innerHTML='Swatch Color: ' + name;
	} 
}

function altMatch_swatch_mouseout(name, the_element) {
	if (document.getElementById('current_altMatch_color_name_div')) {
		document.getElementById('current_altMatch_color_name_div').innerHTML='&nbsp;';
	}
}

var toggle_icons_flag = true;
var toggle_stars_flag = true;
function toggle_view() {
	var elements = getElementsByClassName('output_icons_clickable');
		
	if (!toggle_icons_flag) {
		var display_style = 'none';
		toggle_icons_flag = true;
	} else {	
		var display_style = 'inline';
		toggle_icons_flag = false;
	}

	for (var i = 0; i < elements.length; i++) {
		elements[i].style.display = display_style;	
	}

	var elements = getElementsByClassName('output_icon');

	for (var i = 0; i < elements.length; i++) {
		elements[i].style.display = display_style;
	}

	var elements = getElementsByClassName('pr-snippet');
	for (var i = 0; i < elements.length; i++) {
		elements[i].style.display = display_style;
	}
}

function getElementsByClassName(findClass) {    
	if (document.getElementsByClassName) {
		return document.getElementsByClassName(findClass);
	}

	var elements = document.getElementsByTagName('*');   
	var matching = [];    
	for(var i = 0, elementsLength = elements.length; i < elementsLength; i++){      
		var elementClasses = elements[i].className.split(' ');
		for (var j = 0, elementClassesLength = elementClasses.length; j < elementClassesLength; j++) { 
			if (elementClasses[j] == findClass) {		
				matching.push(elements[i]);     
				break;
			}
		}
	}    

	return matching;  
} 

