/**
 * ---------------------------------------------------------------------------------------------------------------
 * Skrypt FacePlus BOX - Wersja 1.5
 * Autor: Grzegorz Mikiewicz
 * Copyright (c) 2011 Avatec.pl. Wszystkie prawa zastrzeżone
 *
 * KOPIOWANIE I ROZPOWSZECHNIANIE SKRYPTU, BEZ ZGODY AUTORA JEST ZABRONIONE
 * ---------------------------------------------------------------------------------------------------------------
 * www.avatec.pl
 * biuro@avatec.pl
 * ---------------------------------------------------------------------------------------------------------------
 * W przypadku jakichkolwiek problemów z uruchomieniem skryptu prosimy o kontakt:
 * EMail: biuro@avatec.pl
 * Tel: 603-942-561 (Plus GSM)
 * GG: 7819895
 * ---------------------------------------------------------------------------------------------------------------
 **/
 
(function( $ ){
    $.fn.extend({ 
		FacePlusBOX: function( options ) {
		
			var defaults = {
				fbkey		:	"205660766117058"	,
				theme		:	""					,
				color		: 	"blue"				,
				position	:	"left"				,
				top			:	"100px"				,
				fadeSpeed	:	1000				,
				pathname	:	""
			};
			
			var options = $.extend(defaults, options);
			return this.each(function() {
				var o = options;
				
				if(o.theme) { o.theme = o.theme + "_"; 	}
				
				if(o.pathname == "") {
					o.pathname = location.href.replace("/C:/" , "C://");
					o.pathname = o.pathname.replace(/([a-zA-Z0-9_-]+)\.html/g , "") + "faceplusbox/";
				}
				$("body").append(FB.init({
					appId  : o.fbkey,
					status : true, 
					cookie : true, 
					xfbml  : true  
				}));
				
				$("body").append('<div id="avatec_faceplusbox" style="display:block;position:fixed;height:335px;cursor:pointer;background-repeat:none;"><div style="margin-top:10px;margin-left:6px;border:none;" class="whiteBox"></div></div>');
				
				$(".whiteBox").append('<fb:fan profile_id="'+o.fbkey+'" stream="0" connections="8" logobar="0" width="242" height="245" border=0></fb:fan><br/><center><div style="margin: 10px 0px 10px 30px;"><script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang: "pl"}</script><g:plusone size="medium"></g:plusone></div><p><a href="http://www.avatec.pl/faceplus-demo/" style="display:block;background:white;color:black;text-decoration:none;font-family:arial;font-size:8pt" target="_blank" title="Dodaj FacePlus BOX na swoja strone !">FacePlus BOX - www.avatec.pl</a></p></center>');
				
				var obj = $("div#avatec_faceplusbox");

				if(o.color == "blue") { 	var background = o.pathname + o.theme + "blue_" 	+ o.position + ".png" ; }
				if(o.color == "yellow") { 	var background = o.pathname + o.theme + "yellow_" 		+ o.position + ".png"; }
				if(o.color == "orange") { 	var background = o.pathname + o.theme + "orange_" 	+ o.position + ".png"; }
				if(o.color == "green") { 	var background = o.pathname + o.theme + "green_" 	+ o.position + ".png"; }
				if(o.color == "black") { 	var background = o.pathname + o.theme + "black_" 	+ o.position + ".png"; }
				if(o.color == "silver") { 	var background = o.pathname + o.theme + "silver_" 	+ o.position + ".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");
				
				var hideDelay		= 300;
				var hideDelayTimer	= null;
				
				if(o.position=="left") { 
					$(obj).css("width" , "300px");
					$(obj).css("left" , "-256px");
					
					$(obj).hover(function(){
						if(hideDelayTimer)	clearTimeout(hideDelayTimer);
						$(obj).animate( {left:'0'},o.fadeSpeed );
					}, function() {
						if(hideDelayTimer)	clearTimeout(hideDelayTimer);
						hideDelayTimer=setTimeout(function() {
							hideDelayTimer=null;
							$(obj).animate( {left:'-=256'},o.fadeSpeed);
						},hideDelay);
					});
				}
				
				if(o.position=="right") {
					var winWidth = $(window).width()-50;
					$(obj).css("width" , "250px");
					$(obj).css("left" , winWidth);
					$(obj).css("padding-left" , "50px");
					
					var leftPosition = $(obj).css("left");
					$("#counter").val( "AKTUALNIE: " + $(obj).css("left") );
					$(obj).hover(function(){
						if(hideDelayTimer)	clearTimeout(hideDelayTimer);
						$(obj).animate( {left:'-=250'},o.fadeSpeed );
					}, function() {
						if(hideDelayTimer)	clearTimeout(hideDelayTimer);
						hideDelayTimer=setTimeout(function() {
							hideDelayTimer=null; 
							$(obj).animate( {left:'+=250'},o.fadeSpeed);
						},hideDelay);
					});
				}
            });
		}
 
    });
})( jQuery );
