//--------------------------------------//
//		QuickView Javascript Source		//
//--------------------------------------//

// variable init
disableOD = false;

/*
 *	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;
}

/*
 *	opens the quickview window for the specific product
 */
function openQuickview(prod)
{
	// set up ajax manager
	var quickview = new sugar.ServerManager("/quickview/quickview_remote.php");
	quickview.startFunct = function(){document.getElementById("quickloading").style.display = "block";}
	quickview.endFunct = function(){document.getElementById("quickloading").style.display = "none";}
	
	// build vars
	var pairs = [];
	pairs['id'] = prod;
	quickview.initPairs = pairs;
	
	// reposition and display the quickview window
	if(typeof(window.pageYOffset) == 'number')
	{
		document.getElementById('quickview').style.top = window.pageYOffset+10;
	}
	else
	{
		document.getElementById('quickview').style.top = document.body.scrollTop+10;
	}
	
	document.getElementById('quickview').style.left = 150;
	document.getElementById('quickview').style.display = "block";
	
	// launch ajax request and populate results
	sugar.yonder(quickview,function(results){
		document.getElementById("quickresults").innerHTML = results;
		if (window.global_design_cat_id != undefined && document.getElementById("load_script")) {
			eval(document.getElementById("load_script").innerHTML);
		}
		return true;
	});
}

/*
 *	clear and close the quickview window
 */
function closeQuickview()
{
	document.getElementById('quickview').style.display = "none";
	document.getElementById('quickresults').innerHTML = "";
	return false;
}

/*
 *	changes the quickview blowup product image's color
 */
function qvColorChange(id,place,color,name,qv)
{
	/*
	document.getElementById('quickloading').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";
		}
		
		// throw in some underscores for non IE browsers
		setLastColor(color);
		name = name.replace(/ /g,"_");
		if(qv)
		{
			url = 'http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=' + place + '&color=' + color + '&colorname=' + name + '&quickview=1&designer_type=sign&quickview_set_color=1';
		}
		else
		{
			url = 'http://www.logosoftwear.com/personalize/functions_image/bgimage.php?placement_id=' + place + '&color=' + color + '&colorname=' + 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';
	}
	return false;
}

/*
 *	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 = $('qv_product_media');
	var lrg = $('alternateLargerViewsDiv');
	var img = $('alternateLargerViewsImg');
	var alt = $('alternateLargerViewsThumbs');
	var tog = lrg.style.display == 'block' ? false : true;
	var i = 1;
	while($('qv_pinfo_panel' + i))
	{
		$('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)
	{
		$('alternateLargerViewsImg').style.display = 'none';
		$('alternateSwatchImg').style.display = 'block';
	}
	else
	{
		$('alternateLargerViewsImg').style.display = 'block';
		$('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)
{
	$('qv_pinfo_panel' + tab).style.display = 'block';
	$('qv_pinfo_tab' + tab).className = 'qv_pinfo_tabs qv_hl';
	var i = 1;
	while($('qv_pinfo_panel' + i))
	{
		if(i != tab)
		{
			$('qv_pinfo_panel' + i).style.display = 'none';
			$('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
	}
}