//javascript Document

var $=jQuery.noConflict();

(function($){

	$.fn.facebookTrafficPop = function(options){

	

			/* Setup the options for the tooltip that can be

			   accessed from outside the plugin              */

			var defaults = {

				title: "Your Popup Title",

				message: "Your popup / call to action message!",

				url: url,

				showfaces: true,

				timeout: 25,

				closeable: false,

				wait: 0,

				lang: "en"

			};

			

			// Extend options and apply defaults if they are not set

			var options = $.extend(defaults, options);

			

			/* Create a function that builds the popup html

			   markup. Then, prepend the popup to the body */

			getPopHTML = function() {

				var tPop = '<div id="fblikebg"></div><div id="fblikepop"><span id="close" onclick="closePopup();"></span><div id="popup_head"><div id="closeable"></div><h1>'+defaults.title+'</h1></div><div id="popupMessage">'+defaults.message+'</div><div id="buttonArea"><div id="actionHolder"><fb:like id="fbLikeButton" href="'+defaults.url+'" show_faces="'+defaults.showfaces+'" width="450" send="false"></fb:like></div><div id="counter-display"> <span id="counter"> </span> </div> <div style="clear:both"></div></div></div></div>'

					

							

				// Return the pop up markup

				return tPop;

				

			}

			

			// Create a variable to hold the markup ( Needed For I.E 8 6 + 7 )

			var markup = getPopHTML();

			

			// Prepend the popup into the body of the page

			$('#fbtpdiv').html( markup );

			

			// Get cookie to see if they already clicked like

			var cook = readCookie('fblikepop');

			//alert(cook);

			//alert(url);

		

			// Get wait cookie

			

			// Only show the pop up if the user has not clicked like already

			if(cook != url){

										

				// Get window width and height to center the pop up

				var windowWidth = document.documentElement.clientWidth;

				var windowHeight = document.documentElement.clientHeight;

				var popupHeight = $("#fblikepop").height();

				var popupWidth = $("#fblikepop").width();

				var top=Math.abs(windowHeight / 2 - popupHeight / 2);

				var left=Math.abs(windowWidth/2-popupWidth/2);

				//alert('top='+top+' and left='+left);

				// Simple division will let us make sure the box is centered on all screen resolutions

				$("#fblikepop").css({"position": "absolute","top": top,"left": left});

				$("#fblikebg").css({"height": windowHeight});

				//$("#fblikepop").css({'padding-top':'100px'});

				

				// Check if the closeable is set to true

			

				// Set the background shadow active - higher opactity = darker background shadow

				$("#fblikebg").css({"opacity": "0.8"});

				

				// Fade in the background shadow

				$("#fblikebg").fadeIn("slow");

				

				// Fade in the popup box

				$("#fblikepop").fadeIn("slow");

				

								

				// Final parse check to ensure Like button appears on all browsers of all speeds

				FB.XFBML.parse();

				

			} // End if	

	}; // End Main Function

})(jQuery); // End Plugin


// This is our listener to check wether or not the user clicks the like button.

FB.Event.subscribe('edge.create', function(href) {	

	// If they did, close the pop up

	fbLikeDump(true);

});

// function to remove the pop up from the screen

function fbLikeDump(action){	

	// Check if the user completed the like or if the timer ran out

	if(action == true){	

	// Create the cookie to remember the user clicked like, 30 is the number of days it will expire in.

	createCookie('fblikepop', url, 30);

	manageLikes();			

	} // End if			

	// Fade out the background shadow

	$("#fblikebg").fadeOut("slow");			

	// Fade out the pop up itself

	$("#fblikepop").fadeOut("slow");	

}	

function closePopup(){

	$("#fblikebg").fadeOut("slow");			

	// Fade out the pop up itself

	$("#fblikepop").fadeOut("slow");

	}

function detect(){

	alert('like button clicked');

	}	

// Begin counter code - for documentation visit: http://keith-wood.name/countdownRef.html

 function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();} else var expires="";document.cookie=name+"="+value+expires+"; path=/";} function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);} return null;} function createWait(name,value,mins) { if (mins) { var date = new Date(); date.setTime(date.getTime()+(mins*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }
