document.observe("dom:loaded", function() {
	popupLinks = $$(".popup");
	//alert("dom:loaded we have "+imgArray.length+" images to position");
	popupLinks.each(function(element) {
		element.observe('click', popupClick);
		//element.writeAttribute({'onclick':'return false;'});       
	});
	//if ($("catProductList") != null) resizeCatList();
}); 

function sizeChartTabs()
{       
	if (window.console) console.log("sizeChartTabs called");
	var tabs = new tabset('tab-content', {
	classNames: {
	  tab:        'tab',      // class name used to identify the tabs
	  panel:      'panel',    // class name used to identify the tab content
	  tabActive:  'current'  // class name added to the active tab
	},                        
	ids: {                    
	  tab:        'tab_',     // what to strip off the tab id to get the tab name
	  panel:      'panel_'    // what to strip off the tab content id to get the tab name
	},                        
	onEvent:      'click',    // perhaps you want to activate on mouseover? not recommended
	effects:      false        // set this to false if you do not want to include effects.js
	});
	tabs.autoActivate($('tab_data'));
}  

function navigateQuickView(theLink)
{
   	displayModal();
	new Ajax.Request(theLink, {
	   method: 'get',           
	   onSuccess : writeModal,
	   onFailure : writeModal
	});
}

function popupClick(event)
{
	var element = event.element();
	var isLink = element.hasAttribute('href'); 
	var parent = element.up(); 
	if (!isLink) element = (parent.hasAttribute('href')) ? parent : element;
	isLink = element.hasAttribute('href');
	var theLink = ""
	if (isLink) theLink = element.readAttribute('href'); 
	navigateQuickView(theLink);
   
}

function displayModal()
{
	var modal = $('modal-quickview');
	modal.setStyle({
		display: "block"
	}); 
	$('modal-content').update("<div class='loader'><img src='../images/ajax-loader.gif' alt='loading' /></div>");                        
	$('modal-bg').observe('click', closeModal); 
	var pageHeight = $(document.body).getHeight() + "px";
	$('modal-bg').setStyle({
		height: pageHeight
	});
	$('modal-close').observe('click', closeModal);
	//if(window.console) console.log("displayModal "+modal);
	
}  

function closeModal(event)
{
   	var modal = $('modal-quickview');
	modal.setStyle({
		display: "none"
	}); 
} 

function writeModal(transport)
{
	var modal_content = $('modal-content');
	modal_content.update(transport.responseText);
	if (window.console) console.log("writeModal  onSuccess calling createSelectBox if needed ("+($('qty_select'))+")");
	if ($('qty_select')) createSelectBox();
	if ($('topcategory')) createSelectBox('topcategory');
	if ($('charttype'))
	{   
		createSelectBox('charttype');
		sizeChartTabs();
	}   
	//if(window.console) console.log("writeModal "+modal_content);
} 

     
    //if(window.console) console.log("loadAJAX is "+loadAJAX);
	function loadAJAX(url, ele, callback, id){
	  new Ajax.Updater(
		ele, 
		url,
		{
			onComplete : function(transport){
				if (200 == transport.status)
				{
					if ((callback != undefined) && (callback != null))
						callback();
				}
			}
		});  
	}
                                              

