﻿

jQuery.fn.extend({

    lightBox: function(options){
        var options = jQuery.extend({
            position: "",
			x:0,
			y:0,
			isClose:{alpha:false,cutom:""},
			callback:function(){},
            hiddenElement:".hide-light"
        }, options);
        
        var uiDialog = jQuery(this);
        if (!document.getElementById("bg-alpha")) 
            jQuery('body').append('<div id="bg-alpha" ></div><div class="detailviewer" ></div>');
        jQuery("#bg-alpha").css({
            height: jQuery(document).height()
        });
        jQuery(".detailviewer").html(this);
        
        if (jQuery.browser.msie && jQuery.browser.version < 7) { // fix bug  Select alway show on top in ie6
            jQuery('select').css({visibility: "hidden"});
        }
        jQuery(options.hiddenElement).css({visibility: "hidden"});
        
		function closeme(){
			jQuery(".detailviewer").fadeOut("normal");
                jQuery("#bg-alpha").fadeOut("normal", function(){
                    if (jQuery.browser.msie && jQuery.browser.version < 7) { // fix bug  Select alway show on top in ie6
                        jQuery('select').css({
                            visibility: "visible"
                        });
                    }
                     jQuery(options.hiddenElement).css({visibility:"visible"});
                });
				jQuery("#fla_vdo").remove();
		}
		
        jQuery("#bg-alpha").fadeTo("normal", 0.75, function(){
        jQuery(".detailviewer").show();           
		
		var wnd = jQuery(window), doc = jQuery(document), _top = doc.scrollTop(), _left = doc.scrollLeft();
		
				switch (options.position) {
					case 'center':
						_top += (wnd.height() / 2) - (uiDialog.height() / 2);
						_left += (wnd.width() / 2) - (uiDialog.width() / 2);
						break;
					case 'top':
						_top += 0 +options.x ;
						_left += (wnd.width() / 2) - (uiDialog.width() / 2);
						break;
					case 'right':
						_top += (wnd.height() / 2) - (uiDialog.height() / 2);
						_left += (wnd.width()) - (uiDialog.width());
						break;
					case 'bottom':
						_top += (wnd.height()) - (uiDialog.height());
						_left += (wnd.width() / 2) - (uiDialog.width() / 2);
						break;
					case 'left':
						_top += (wnd.height() / 2) - (uiDialog.height() / 2);
						_left += 0;
						break;
					default:
						//center
						_top += (wnd.height() / 2) - (uiDialog.height() / 2);
						_left += (wnd.width() / 2) - (uiDialog.width() / 2);
				}
			
			_top = _top < doc.scrollTop() ? doc.scrollTop() : _top;
			
			jQuery(".detailviewer").css({top:_top}).animate({
				opacity:"show",display:"block"
			},400,"swing",options.callback);
			
			 jQuery(".lb-btn-close").click(function(){closeme();});
			 if(options.isClose.custom){
				jQuery(options.isClose.custom).click(function(){closeme();});
			 }
	           
            jQuery("#bg-alpha,.detailviewer").click(function(){
				if(options.isClose.alpha){
					closeme();
                }
            });
        });
    }
	
});