/*
###############################################################################################################
###############################################################################################################
##	jQuery FB_like_Button v1.0
##	Copyright (c) 2010 Thomas Wernecke - grafikmaker.de
##	
##	based on 
##	jQuery OneFBLike v1.0 - http://onerutter.com/open-source/jquery-facebook-like-plugin.html
##	Copyright (c) 2010 Jake Rutter
##	
##	This plugin available for use in all personal or commercial projects under both MIT and GPL licenses.
###############################################################################################################
###############################################################################################################
*/


(function ($) {
	jQuery.fn.extend({
		FBLike: function(options) {

			var FBconfig = {  
            	appID: '134579849931710',	// hier die FacebookID eintragen
				buttonWidth: 450,
            	buttonHeight: 80,
            	show_faces: true, 			// Anzeige der Nutzer ( true o. false)
            	font: 'lucida grande',
            	layout: 'button_count', 	// Auswahl der Anzeige ( button_count o. box_count o. leer für standart )
            	action: 'like',				// Auswahl Like oder Kommendar-Button ( like o. recommend )
            	colorscheme: 'light',		// Layout ( light o. dark )
				language: 'de_DE',			// Sparachausgabe ( z.B. de_DE o. en_US )
				href: 'http://www.hundehalsband-030.de/'
            }  
			
			var options =  $.extend(FBconfig, options);
			
			return this.each(function () {
				var config = options;
				var obj = $(this);
				
				// Check ob #fb-root bereits existiert
				if ( jQuery('#fb-root').length > 0 ) {
					// alles ok nix muß gemacht werden
				} else {
					// #fb-root muß zwingend eingefügt werden
					jQuery('body').append('<div id="fb-root"></div>');
					jQuery('#fb-like iframe').css('height','35px !important');
				}                
                
                // setup FB Developers App Link - do not touch
                window.fbAsyncInit = function() {
					FB.init({appId: config.appID, status: true, cookie: true, xfbml: true});
				};
				(function() {
					var e = document.createElement('script'); e.async = true;
					//auslesen des Servers ob http o. https
					e.src = document.location.protocol + '//connect.facebook.net/'+config.language+'/all.js';
					//e.src = 'http://connect.facebook.net/'+config.language+'/all.js';
					jQuery('#fb-root').append(e);
				}());
				
				// aktuelle URL auslesen
				var dynUrl = document.location;
				//var dynUrl = 'http://www.grafikmaker.de/';
				var FBdiv = obj;
				
				if (config.action != 'recommend') {
					config.href = dynUrl;
					//alert ('LIKE');
				}
                
                // FACEBOOK Like-Button in das DIV einfügen
                // If no options are passed in from the page, the defaults will be applied 
				if ($.browser.msie && config.action != 'recommend') {           
					jQuery(FBdiv).html('<iframe src="http://www.facebook.com/plugins/like.php?href="'+config.href+'"&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>')
				} else {
					jQuery(FBdiv).html('<fb:like href="'+config.href+'" action="'+config.action+'" layout="'+config.layout+'" show_faces="'+config.show_faces+'" font="'+config.font+'" colorscheme="'+config.colorscheme+'" ></fb:like>')
				}
			});
		}
		
	});
	
})(jQuery);
