window.addEvent('domready', function(){
	init_links();
});

function init_links()
{
	var divs = $$('.product_summary');
	for(var i =0; i<divs.length; i++)
	{
		//get the anchors
		var anchors = divs[i].getElements('a');
		for(var v=0; v<anchors.length; v++)
		{
			if(!anchors[v].getAttribute('product_id')) continue;
			
			anchors[v].onclick = function(e){
				var product_id = this.getAttribute('product_id');
				
				//position the window
				show_preview_window(e)
				preview_on_product_id_change(product_id);
				
				return false;
			}.bind(anchors[v]);
		}
	}
}

function preview_on_product_id_change(product_id)
{
	preview_window.setHTML('<div class="loading">loading...</div>');
	new Ajax(site_url('products/details_window/'+product_id), {
		method			: 'get',
		onComplete		: function(resp){
			preview_window.setHTML(resp);
		}
	}).request();
}