jQuery.fn.pgal = function(options){

	return this.each(function() {
		var bigphoto = jQuery(document.createElement('div'));
		bigphoto.insertBefore(this);
		bigphoto.addClass('pgallerywrapper');
		bigphoto.html("<img src="+$(this).children(1).children(1).attr('src')+">");

		$(this).children('li').each(function(i) {
			var el = $(this);
			el.addClass('pgalleryitem');
			el.hover(
				function () {
					$(this).css('cursor','pointer');
					$(this).removeClass('pgalleryitem');
					$(this).addClass('pgalleryitemactive');
				}, 
				function () {
					$(this).addClass('pgalleryitem');
					$(this).removeClass('pgalleryitemactive');
				}
			);
			el.click(
				function () {
					bigphoto.html("<img src="+el.children(1).attr('src')+">");
				}
			);
		});
		$(this).css('height',Math.ceil($(this).children('li').size()/4*90)+40);

		var cc=$(this).children('li').size();
		var jj=0;
		if(cc%4>0) {
			for(j=cc;;j++) {
				if(j%4==0) {jj=j; break;}
			}

			while (jj>cc){
				$(this).append("<li class=pgalleryitem style=\"background-color:#dddddd\">&nbsp;</li>");
				cc++;
			}

		}

		

  
	});
 
};