//You need an anonymous function to wrap around your function to avoid conflict
(function($){
 var shadow,panel,header,imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,
 isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest;
    //Attach this new method to jQuery
    $.lightboxInit = function()
	{
		$("body").append(
			shadow = $('<div class="lightboxShadow"><!-- --></div>'),
			panel = $('<div class="lightboxPanel"><!-- --></div>')
		);
		
		shadow.css("height",$(document).height());

		panel.css("width",800);
		panel.css("height",610);
		
		panel.append(
			header = $('<div class="lightboxHeader"><!-- --></div>'),
			content = $('<div class="lightboxContent"><!-- --></div>')
		);
		if (isIE6) {
			header.addClass("ieHeader");
		}
		
		
		header.append(headerRow = $('<div class="lightboxHeaderPanel"></div>'));
		headerRow.append(
			title = $('<div class="lightboxHeaderTitle"></div>'),
			closeContent = $('<div class="lightboxClose"></div>')
			);
		closeContent.append(closeBtn = $('<div class="close"></div>'));
				
		content.append(
			leftColumn = $('<div class="lightboxArrowColumn"></div>'),
			picCont = $('<div class="lightboxPictureContent"></div>'),
			rightColumn = $('<div class="lightboxArrowColumn"></div>')
		);
		
		picCont.append(
			pictureTable = $('<table cellpadding="0" cellspacing="0" border="0" class="lightboxTable"><tr><td id="picContent"></td></tr></table><div class="spacer">&nbsp;</div>')
		);
		
		leftColumn.append(
			leftArrow = $('<a href="#" title="previous" class="leftArrow">&nbsp;</a>')
		);
		
		rightColumn.append(
			rightArrow = $('<a href="#" title="previous" class="rightArrow">&nbsp;</a>')
		);
		
		shadow.click(function(){
			panel.fadeOut();
			shadow.fadeOut();			
		});
		
		closeBtn.click(function(){
			panel.fadeOut();
			shadow.fadeOut();
		});
		
		leftArrow.click(function(e){
			var href,name;
			e.preventDefault();
			if (0 < selectedIndex) 
			{
			selectedIndex = selectedIndex-1;
				href = selectedArray[ selectedIndex].href;
				name = selectedArray[ selectedIndex].title;
				$.loadPic(href,name);	
			}
			
		});
		
		rightArrow.click(function(e){
			var href,name;
			e.preventDefault();
			if ((selectedArray.length - 1) > selectedIndex) 
			{
			selectedIndex = selectedIndex+1;
				href = selectedArray[ selectedIndex].href;
				name = selectedArray[ selectedIndex].title;
				$.loadPic(href,name);
			}	
			
		});
	}
	
	$.lightboxShow = function()
	{
		shadow.fadeTo('fast',0.8);
		panel.fadeIn();
	}	
		
	
	$.resize = function()
	{
		var max_w,max_h,w=0,h=0;
		
		max_w = 646;
		max_h = 485;
		
		w = $('#picContent img').width();
		h = $('#picContent img').height();
		
		if (w > max_w)
			{
				var rate = max_w / w;
				w = Math.ceil(w * rate);
				h = Math.ceil(h * rate);
			}
		
		else if (h > max_h)
			{
				var rate = max_h / h;
				w = Math.ceil(w * rate);
				h = Math.ceil(h * rate);
			}
				
		$('#picContent img').css('width',w);
		$('#picContent img').css('height',h);	
	}
	
	$.loadPic = function(href,name)
	{

		$('.lightboxPanel').css("top",($(window).height()-$('.lightboxPanel').height())/2+$(window).scrollTop());
		$('.lightboxPanel').css("left",($("body").width()-$('.lightboxPanel').width())/2);		
		$('#picContent').html('');
		
		if (selectedIndex == 0)
		{
		leftArrow.css('display',"none");
		}
		else leftArrow.css("display","inline");
		
		
		if (selectedIndex == selectedArray.length-1)
		{
		rightArrow.css('display',"none");
		}
		else rightArrow.css("display","inline");
		
		if (typeof href !== 'undefined' && href.match(imgRegExp)) {
			var picture = new Image();
			picture.src = href;
			$('#picContent').append(picture);
		}	
		
		$(".lightboxHeaderTitle").html(name);
		$.lightboxShow();
		//$.resize();
	}
	
		
	$.fn.extend({
         
        //This is where you write your plugin's name
        lightbox: function() {
 
			$.lightboxInit();
            //Iterate over the current set of matched elements
            return this.each(function() {
             
				
			 
                selectedArray = [];
				selectedIndex = 0;

				var rel = $(this).attr('rel') || '';

				if (!rel || rel == '' || rel === 'nofollow') {
					selectedArray.push(this);

				} else {
					selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
					selectedIndex = selectedArray.index( this );
					$("<img>").attr("src", $(this).attr('href'));
				}
				
				$(this).click(function(e){
					selectedIndex = selectedArray.index(this);
					e.preventDefault();
					
					$.loadPic($(this).attr('href'),$(this).attr('title'));
				});
             
            });
        }
    });
     
//pass jQuery to the function,
//So that we will able to use any valid Javascript variable name
//to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )      
})(jQuery);
