/**
 * BelVG LLC.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://shop.belvg.com/BelVG-LICENSE-COMMUNITY.txt
 *
 /*
 * @category   Belvg
 * @package    Belvg_StickerPro
 * @copyright  Copyright (c) 2010 - 2011 BelVG LLC. (http://www.belvg.com)
 * @license    http://shop.belvg.com/BelVG-LICENSE-COMMUNITY.txt
 */

$(document).ready(function(){
	
	if (productId == '')
	{		
		/* Product list */
		
		var ids = '';	
		$('ul#product_list li').each(function(){
			$(this).find('a.product_img_link').css('position','relative');
			ids += $(this).find('input[name=product_id]').val() + "_";
		});
		
		if (ids != '') 
		{
			ids = ids.replace(/_$/,'');
					
			$.ajax({
				type: "POST",
				url: baseUrl + "/modules/belvgstickerpro/ajax.php",
				data: "ids=" + ids,
				dataType: 'json',
				success: function(stickers){
					for (productId in stickers)
					{		
						$('ul#product_list li').each(function(){
							id = $(this).find('input[name=product_id]').val();
							
							if (id == productId)
							{							
								for (stiker in stickers[productId])
								{
									var image =  baseUrl + "/modules/belvgstickerpro/stickers/" + stickers[productId][stiker].image;
									var topCatalog = stickers[productId][stiker].top_catalog;
									var leftCatalog = stickers[productId][stiker].left_catalog;
									
									$(this).find('a.product_img_link').append('<span style="display: block; position: absolute; top: ' + topCatalog + 'px; left: ' + leftCatalog + 'px;" id="smallStiker"><img src="' + image + '" alt=""></span>');										
								}							
							}
							
						});
					}
				}
			});		
		}
	}	
	else
	{
		/* Product view */
		var ids = new Array();
		
		$('div#image-block').css('position','relative');
		ids[ids.length] = productId;
		
		$.ajax({
				type: "POST",
				url: baseUrl + "/modules/belvgstickerpro/ajax.php",
				data: "ids=" + ids,
				dataType: 'json',
				success: function(stickers){
					for (productId in stickers)
					{		
						
						for (stiker in stickers[productId])
						{
							var image =  baseUrl + "/modules/belvgstickerpro/stickers/" + stickers[productId][stiker].image;
							var topCatalog = stickers[productId][stiker].top_view;
							var leftCatalog = stickers[productId][stiker].left_view;
							
							$('div#image-block').append('<span style="display: block; position: absolute; top: ' + topCatalog + 'px; left: ' + leftCatalog + 'px;" id="smallStiker"><img src="' + image + '" alt=""></span>');										
						}							
						
					}
				}
			});		
	
		
	}
		
	

	
});	
	

