/* --------------------------------------------------------------
   GMProductImages.js 2008-08-10 gambio
   Gambio OHG
   http://www.gambio.de
   Copyright (c) 2008 Gambio OHG
   --------------------------------------------------------------
   Released under the GNU General Public License
   --------------------------------------------------------------
*/


function GMProductImages()
{
	
	this.open_images = function(products_id, image_number)
	{
//		$('.wrap_site').append('<div id="product_images_layer"></div>');
		$('body').append('<div id="product_images_layer"></div>');
		$('#product_images_layer').css(
		{
			position: 	'absolute',
			left: 			'0px',
			top: 				'50px',
			width: 			'100%',
			height: 		'100%'
		});
		
		var test_products_id 	= 95;
		var test_image_nr 		= 0;
		
		var user_agent = navigator.userAgent.toLowerCase();
		if(user_agent.indexOf("msie") > -1 && user_agent.indexOf("opera") == -1){
			var msie_index = user_agent.indexOf("msie") + 5;
			if(user_agent.substr(msie_index,1) < 7){
				$('.lightbox_visibility_hidden').css(
				{
					visibility: 	'hidden'
				});
			}
		}
		
		$('#product_images_layer').load('gm_ajax.php?module=product_images&pID='+ products_id +'&image_nr='+ image_number, 
																			{}, 
																			function(){
																				gmProductImages.bind_fn();
																				gmProductImages.activate_image(image_number);
																				window.scrollTo(1, 1);
																			});
		gmLightBox.load_box('#product_images_layer');

		// BOF MOD by PT
		$('#menubox_gm_scroller').css({
			display: 'none'
		});

		if($(document).height() > $('#product_images_box').height()) {			
			var pt_height = $(document).height();
		} else {
			var pt_height = $('#product_images_box').height()+ 200;
		}
		$('#__dimScreen').css({ height: pt_height + 'px'});
		// EOF MOD by PT

	}
	
	
	this.activate_image = function(image_number) 
	{
		var active_li 			= '#image_' + image_number;
		var active_img_name = $(active_li).find('a').attr('href');
		
		//IE6 patch:
		active_img_name = active_img_name.split('/');
		active_img_name = active_img_name[active_img_name.length - 1];
		
		$('#product_images_box li').removeClass('active');
		$(active_li).addClass('active');
		
		$('#active_image').find('img').attr('src', 'images/product_images/popup_images/' + active_img_name);
	}
	
	this.bind_fn = function() 
	{
		$('#product_images_box li').click(function(e) 
		{
			var li_id 		= $(this).attr('id');
			
			var image_nr	= li_id.split('_');
			image_nr			= image_nr[1];
			
			gmProductImages.activate_image(image_nr);
		});
	}
	
}
