jQuery.lbox = {

	build : function(options) {

		settings = jQuery.extend({

			 width: "500px",

			 height: "500px",

			 background: "#fff",

			 overlaybg: "#000",

			 button: "blue"

		  }, options);

		  

		var cssSrc = '/lbox.css';

		

		if ($.browser.msie) {

			cssSrc = '/lbox.ie.css';

		}

		

		$('<link>').appendTo('head').attr({

			rel: 'stylesheet',

			type: 'text/css',

			href: cssSrc

		});

		

		$(this).each(function() {

			var theID = $(this).attr('id');

			

			var theLightbox = $('<div id="lightbox-'+theID+'" class="lightbox"/>');

			var theShadow1 = $('<div id="lightbox-shadow1-'+theID+'" class="lightbox-shadow1"/>');

			var theShadow = $('<div id="lightbox-shadow-'+theID+'" class="lightbox-shadow"/>');

			$(theShadow).click(function(e){

				$.lbox.close();

			});

			$('body').append(theShadow);

			$('body').append(theShadow1);

			$('body').append(theLightbox);

		

		

			$(theLightbox).css('width',settings.width);

			$(theLightbox).css('height',settings.height);

			

			$(theShadow1).css('width',(parseInt(settings.width) + 20) + 'px');

			$(theShadow1).css('height',(parseInt(settings.height) + 20) + 'px');

			

			$(theLightbox).css('background',settings.background);

			$(theShadow).css('background',settings.overlaybg);

			

			

			

			

			$(theLightbox).append('<div style="text-align:right"><a href="javascript:$.lbox.close()"><img border="0" src="/images/close_'+settings.button+'.gif" height="19" width="19"/></a></div>');

			

			$(theLightbox).append($(this));

			

			//$(this).css('display','none');

		});

		

		$(window).bind("resize", function(){

				$.lbox.center();

			});



	},

	

	open : function(obj) {

		/*

		settings = jQuery.extend({

			 background: "#fff",

			 overlaybg: "#000"

		  }, options); */

		// remove any previously added content

		//$('#lightbox-'+obj).empty();

		

		// make it center :

		$.lbox.center(obj);

		

		if ($.browser.msie) {

				/*  uncomment if want to rounded corner

				if(typeof curvyCorners == 'function')  {

					 var settings_curvyCorners = {

						  tl: { radius: 11 },

						  tr: { radius: 11 },

						  bl: { radius: 11 },

						  br: { radius: 11 },

						  antiAlias: true

						}

						curvyCorners(settings_curvyCorners, "#lightbox-"+obj);

				} else {

					$.getScript('/js/curvycorners.js', function() {

						 var settings_curvyCorners = {

						  tl: { radius: 11 },

						  tr: { radius: 11 },

						  bl: { radius: 11 },

						  br: { radius: 11 },

						  antiAlias: true

						}

						curvyCorners(settings_curvyCorners, "#lightbox-"+obj);

					});

				}

				*/ 

		}

				

		// display the lightbox

		$('#lightbox-shadow-'+obj).show();

		$('#lightbox-shadow1-'+obj).show();

		$('#lightbox-'+obj).show();

	},

	close : function() {

		// hide lightbox/shadow <div/>'s

		$('.lightbox').hide();

		$('.lightbox-shadow1').hide();

		$('.lightbox-shadow').hide();
		
		//only for video close
		$('#videoSelect').children().children().css('background','#ffffff');
		if( $('#videoSelect').length > 0 ) {
			$('#video-popup').empty();
		}

		// remove contents of lightbox in case a video or other content is actively playing

		//$('#lightbox').empty();

	},

	

	center : function(obj) {

		var element = $("#lightbox-"+obj);

		var element2 = $("#lightbox-shadow1-"+obj);

		var imageHeight = $(element).height();

		var imageWidth = $(element).width();

		var windowWidth = $(window).width();

		var windowHeight = $(window).height();

		var boxTop = windowHeight /2 - imageHeight / 2 ;

		var boxTop2 = windowHeight /2 - $(element2).height() / 2 ;

		if ($.browser.msie) {

			boxTop = boxTop + $(window).scrollTop();

			boxTop2 = boxTop2 + $(window).scrollTop();

		}

		$(element).css({

			"left" : windowWidth / 2 - imageWidth / 2,

			"top" : boxTop

		});

		$(element2).css({

			"left" : windowWidth / 2 - $(element2).width() / 2,

			"top" : boxTop2

		});

	}

};

jQuery.fn.extend(

	{

		lbox : jQuery.lbox.build

	}

);
