(function( $ ){
    $.fn.extend({
		facebookLike:	function( options ) {

			var defaults = {
				color		: 	"blue",
				position	:	"left",
				top			:	"100px",
				fbkey		:	"105100776257949",
				path		:	"NULL"
			};
			var options = $.extend(defaults, options);
			return this.each(function() {
				var o = options;
				if(o.path == "NULL") {
					o.path = location.href.replace("/C:/" , "C://");
					o.path = o.path.replace(/([a-zA-Z0-9_-]+)\.html/g , "") + "fblike/";
				}
				$("body").append(FB.init({
					appId  : o.fbkey,
					status : true,
					cookie : true,
					xfbml  : true
				}));

				$("body").append('<div id="facebookLikeBox" style="display:block;position:absolute;height:300px;cursor:pointer;background-repeat:none;"><div style="margin-top:10px;margin-left:10px;" class="whiteBox"></div></div>');

				$(".whiteBox").append('<fb:fan profile_id="'+o.fbkey+'" stream="0" connections="8" logobar="0" width="240" height="245"></fb:fan><br/><center><a href="http://www.avatec.pl" style="display:block;background:white;color:black;text-decoration:none;font-family:arial;font-size:8pt" target="_blank" title="Dodaj Likebox na swoja strone !">Facebook Likebox - www.avatec.pl</a><script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang: "pl"}</script><g:plusone size="medium"></g:plusone></center>');

				var obj = $("div#facebookLikeBox");

				if(o.color == "blue") { 	var background = o.path + o.position + "_blue.png"; }
				if(o.color == "red") { 		var background = o.path + o.position + "_red.png"; }
				if(o.color == "orange") { 	var background = o.path + o.position + "_orange.png"; }
				if(o.color == "green") { 	var background = o.path + o.position + "_green.png"; }
				if(o.color == "black") { 	var background = o.path + o.position + "_black.png"; }
				if(o.color == "grey") { 	var background = o.path + o.position + "_grey.png"; }

				$(obj).css("top" , o.top);
				$(obj).css("background" , "url("+background+")");
				$(obj).css("margin-top" , "10px");

				$(obj).find("div.whiteBox").css("width" , "240px");
				$(obj).find("div.whiteBox").css("height" , "225px");
				$(obj).find("div.whiteBox").css("background" , "white");

				if(o.position=="left") {
					$(obj).css("width" , "300px");
					$(obj).css("left" , "-270px");

					$(obj).mouseenter(
						function() {
							if($(obj).css("left")>=270) {
								$(obj).css("left" , "270px");
							} else {
								$(obj).animate({ left: "0" },1000);

							}
						});
					$(obj).mouseleave( function() {
							if($(obj).css("left")<=-270) {
								$(obj).css("left" , "-270px");
							} else {
								$(obj).delay(500).animate({ left: "-=270" },1000);
							}
						}
					);
				}
				if(o.position=="right") {
					$(obj).css("width" , "270px");
					$(obj).css("right" , "-270px");
					$(obj).css("padding-left" , "30px");
					$(obj).hover(
						function() { $(obj).animate({ right: "+=250" },1000); }, function() { $(obj).delay(500).animate({ right: "-=250" },1000); }
					);
				}
            });
		}

    });
})( jQuery );

