/* 
 * JQuery - Product bonus overlay for mds
 *
 * @author Micha Horn <michael.horn@burda.com> <info@michahorn.de>
 * @version 1.0
 *
 */

function bds_bonusOverlay() {
	$(document).ready (		
		function() {
	    	$('[id^=jq_bds_bonusPageProduct_]').each (
				function() {				
					
					var x = false;
					var velocity = 200; 
					
					var id = '#'+this.id;
					var detailsId = id+' .bdi_bonusPageProductNoticeDetails';
					var selectId = detailsId+' select';
					var selOpt = false;
					
					$(detailsId).hide();	
					
					function bindMouseEnter() {
						$(id).bind ( 'mouseenter', function () { 
							$(detailsId).slideDown(velocity);
							bindMouseLeave();
						});
					};
					
					function bindMouseLeave() {
						$(id).bind ( 'mouseleave', function () { 
							$(detailsId).slideUp(velocity);	
						});
					}
	
					$(selectId).blur(function(){
						$(detailsId).slideUp(velocity);
					});								
					
					$(selectId).toggle(function(){
						$(id).unbind ('mouseleave');
						selOpt = $(selectId+' option:selected').val();
					}, function() {
						if(selOpt != $(selectId+' option:selected').val()) {
							bindMouseLeave();
						} else {
							$(id).unbind ('mouseleave');
						}
					});
					
					bindMouseEnter();
				}
			);
	    }
	);
}
