$.fn.extend({
	lightBox : function(){
		
		var $target = $(this);
		var $wv = 420;
		var $hv = 315;
		var $bgLoader = function(){
			$("body").append('<div id="lightBox"><div class="loader"></div></div>');
		}
		var $clickVideo = function($e){
			$e.preventDefault();
			$($target).unbind("click");
			$("body").append('<div id="lightBox"><iframe width="'+$wv+'" height="'+$hv+'" src="'+$($e.target).parent().attr("href")+'" frameborder="0" allowfullscreen=""></iframe></div>');
			
			var $w = $wv/2;
			var $h = $hv/2;
			$("#lightBox iframe").css({margin:("-"+$w+"px 0 0 -"+$h+"px")});
			$("#lightBox").bind('click', function($e){
				$("#lightBox").unbind("click");
				$("#lightBox").remove();
				setTimeout(function(){
					$($target).bind('click',$clickVideo);
				}, 100);
			});
		}
		var $clickImage = function($e){
			$e.preventDefault();
			$($target).unbind("click");
			var $img = new Image();
			$("body").append('<div id="lightBox"><div class="loader"></div></div>');
			
			$($img).load(function(){
				$($img).css({opacity:0});
				$("#lightBox div.loader").append($($img));
				var from = {top:-100, left:-150, width:300, height:200};
				var $w = Number($($img).css("width").replace(/\D/gi, ""));
				var $h = Number($($img).css("height").replace(/\D/gi, ""));
				var $t = -($h/2);
				var $l = -($w/2);
				var to = {top:$t, left:$l, width:$w, height:$h};
				$(from).stop().animate(to, {
					duration: 200,
					complete:function(){
						$($img).animate({opacity:1}, 200, function(){
							$("#lightBox").bind('click', function($e){
								$("#lightBox").unbind("click");
								$("#lightBox").remove();
								setTimeout(function(){
									$($target).bind('click',$clickImage);
								}, 100);
							});
						});
					},
					step: function() {
						$("#lightBox div.loader").css({width:this.width, height:this.height, margin:(this.top+"px 0 0 "+this.left+"px")});
					}
				});
			});
			$($img).attr({src:$($e.target).parent().attr("href")});
			
		}
		return{
			video	: function($width, $height){
				$wv = ($width || 420);
				$hv = ($height || 315);
				$($target).bind('click',$clickVideo);
			},
			image	: function(){
				$($target).bind('click',$clickImage);
			}
		}
	}
});
	
