(function($)
{

	$.fn.launchModalPopup = function()
	{
					
	/* not needed because DIVs are included in the detail page
	var bodyDIVs = "\
		<!--- Modal div window --->\
		<div id='productDetail_ModalWindow_Container'>\
		\
		<!--- close button is defined as close id --->\
		<div id='productDetail_ModalWindow_CloseButton'>\
			<img src='/images_bw/productdetail_new/btn_closebox.png' alt='Close Window'/>\
		</div>\
		\
		<!--- div mask here, this is the layer below the window that's popped up, don't remove! --->\
		<div id='productDetail_ModalWindow_Mask'></div>\
		</div>\
		<!--- End Modal div window --->\
	";
		
	$("body").prepend(bodyDIVs);
	*/
			
	var OS = navigator.platform.toLowerCase();
	
	if(OS == "iphone" || OS == "ipad")
	{
		OS = "mobile";	
	}
	else
	{
		OS = "desktop";	
	}
	
	//select all the a tag with name equal to modal
	$('a[name=modalWindow]').click(function(e) {
								  
		//hide any error box elements on the page									
		$('div[name=errorElement]').remove();
		
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('window');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		
	
		//Set height and width to mask to fill up the whole screen								
		$('#productDetail_ModalWindow_Mask').css({'width':maskWidth,'height':maskHeight});
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		var scrollPos = $(window).scrollTop();
			  
		//Set the popup window to center
		if($.browser.msie)
		{
			//$(id).css('top',  (winH/2-$(id).height()/2) + scrollPos);
			$(id).css('top', scrollPos + 20);
		}
		else
		{
			//$(id).css('top',  (winH/2-$(id).height()/2) + scrollPos);
			$(id).css('top', scrollPos + 20);
		}
		
		$(id).css('left', winW/2-$(id).width()/2);
		
		if(OS == "mobile")
		{
			if($(this).css('overflow') == 'scroll')
			{
				$(id).css('overflow', 'visible');  
			}
			
			
			if($(this).attr('type') == 'privacy')
			{
				$(id).css('height', '1775px');  
			}
		}
		else
		{
			if($(this).css('overflow') == 'scroll')
			{
				$(id).css('overflow', 'scroll');
			}
			
		}
		
	
		//transition effect		
		//$('#productDetail_ModalWindow_Mask').show();	
		$('#productDetail_ModalWindow_Mask').fadeTo("fast",0.5);
		
		//transition effect
		$(id).fadeIn(); 
		
		var posTop = $(id).position().top;
		var posLeft = $(id).position().left;
		
		$('#productDetail_ModalWindow_CloseButton').show();
		$('#productDetail_ModalWindow_CloseButton').css('top', posTop - 10);
		$('#productDetail_ModalWindow_CloseButton').css('left', posLeft - 10);
	
	});
	
	//if mask is clicked
	$('#productDetail_ModalWindow_Mask').click(function () {
		$(this).hide();
		$('.productDetail_ModalWindow, #productDetail_ModalWindow_CloseButton').hide();
	});		
	//if close button is clicked
	$('#productDetail_ModalWindow_CloseButton').click(function(e){
		e.preventDefault();
		
		$('#productDetail_ModalWindow_Mask, .productDetail_ModalWindow, #productDetail_ModalWindow_CloseButton').hide();
	});
	
	}
	
})(jQuery);
