document.write("<div id='f2loatingwindow'>");
document.write("<div style='position:relative'>");
document.write("<div id='c2ontent'><iframe id='f2ramecontent' width='800' height='500' frameborder='0' scrolling='auto' src='http://www.cafeidentity.com/loading.htm'>");
document.write("<p>Your browser does not support iframes.</p>");
document.write("</iframe></div>");
document.write("<div id='c2lose'><a href='javascript:void(0)' onClick='this.blur()' class='h2idewindow'><img alt='' class='i2mgclose' src='http://www.cafeidentity.com/floatingwindow/images/default.png' /></a></div>");
document.write("<div id='t2absr'>");
document.write("<div class='t2aborder' style='z-index:86;margin-top:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howorder'><img class='i2mgorder' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("<div class='t2abmenu' style='z-index:85;margin-top:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howmenu'><img class='i2mgmenu' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("<div class='t2ablocations' style='z-index:84;margin-top:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howlocation'><img class='i2mglocations' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("</div>");
document.write("<div id='t2abst'>");
document.write("<div class='t2ablocations' style='float:right;z-index:84;margin-right:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howlocation'><img class='i2mgtoplocations' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("<div class='t2abmenu' style='float:right;z-index:85;margin-right:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howmenu'><img class='i2mgtopmenu' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("<div class='t2aborder' style='float:right;z-index:86;margin-right:-20px;'><a href='javascript:void(0)' onClick='this.blur()' class='s2howorder'><img class='i2mgtoporder' src='http://www.cafeidentity.com/floatingwindow/images/default.png' alt='' /></a></div>");
document.write("</div>");
document.write("</div>");
document.write("</div>");

$(document).ready(function(){

var ismobile = "NO";
(function(a,b){if(/android|avantgo|blackberry|blazer|elaine|hiptop|ip(hone|od)|kindle|midp|mmp|mobile|o2|opera mini|palm( os)?|pda|plucker|pocket|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))ismobile="YES"})(navigator.userAgent||navigator.vendor||window.opera,'http://google.com');

	// floating window controls
	$.floatMenu = function(options) {
		// check the parameters passed from web page
		var defaults = {
			accountid: 1,
			accountkey: 123456789,
        		color: "orange",
	        	tabsize: "small",
        		tabtype: "right",
        		windowfloat: "ON",
	        	ordertab: "ON",
		        menutab: "ON",
	        	locationstab: "ON",
			hidetabsonclose: "OFF",
			basedomain: "www.cafeidentity.com"
		};
		var opts = $.extend(defaults, options);
		
		//References
		var floatingwindow = $("#f2loatingwindow");
		var content = $("#c2ontent");
		var accountid = opts.accountid;
		var windowcolor = opts.color;
		var tabsize = opts.tabsize;
		var tabtype = opts.tabtype;
		var windowfloat = opts.windowfloat;
		var ordertab = opts.ordertab;
		var menutab = opts.menutab;
		var locationstab = opts.locationstab;
		var hidetabsonclose = opts.hidetabsonclose;
		var topoffset;
		var topoffsettotal;
		var basedomain = opts.basedomain;

		// set the windowfloat depending on if this is a mobil browser or not
		if (ismobile == "YES") {
			var windowfloat = "OFF";
		};

		// check to see if they want to hide the tabs on close
		if (hidetabsonclose == "ON") {
			$("#f2loatingwindow").css({display:"none"});
		}
		
		// set some color variable references
		var urlclose;
		var urlbackgroundcolor;
		var urltabtoporder;
		var urltabtopmenu;
		var urltabtoplocations;
		var urltabtoporderbig;
		var urltabtopmenubig;
		var urltabtoplocationsbig;
		var urltaborder;
		var urltabmenu;
		var urltablocations;
		var urltaborderbig;
		var urltabmenubig;
		var urltablocationsbig;

		// check to see if they want to use a custom color
		if (windowcolor == "custom") {
			if (tabsize == "big") {
				urltaborder = "http://" + basedomain + "/image/fi-" + windowcolor + "-order-big.png";
				urltabmenu = "http://" + basedomain + "/image/fi-" + windowcolor + "-menu-big.png";
				urltablocations = "http://" + basedomain + "/image/fi-" + windowcolor + "-locations-big.png";
				urltabtoporder = "http://" + basedomain + "/image/fi-" + windowcolor + "-order-big-t.png";
				urltabtopmenu = "http://" + basedomain + "/image/fi-" + windowcolor + "-menu-big-t.png";
				urltabtoplocations = "http://" + basedomain + "/image/fi-" + windowcolor + "-locations-big-t.png";
			} else {
				urltaborder = "http://" + basedomain + "/image/fi-" + windowcolor + "-order.png";
				urltabmenu = "http://" + basedomain + "/image/fi-" + windowcolor + "-menu.png";
				urltablocations = "http://" + basedomain + "/image/fi-" + windowcolor + "-locations.png";
				urltabtoporder = "http://" + basedomain + "/image/fi-" + windowcolor + "-order-t.png";
				urltabtopmenu = "http://" + basedomain + "/image/fi-" + windowcolor + "-menu-t.png";
				urltabtoplocations = "http://" + basedomain + "/image/fi-" + windowcolor + "-locations-t.png";
			} 
			urlclose = "http://" + basedomain + "/image/fi-" + windowcolor + "-close.png";
			urlbackgroundcolor = "http://" + basedomain + "/image/fi-" + windowcolor + "-back.png";
			$("#f2loatingwindow").css('backgroundImage','url(' + urlbackgroundcolor + ')');
		} else {
			if (tabsize == "big") {
				urltaborder = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-order-big.png";
				urltabmenu = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-menu-big.png";
				urltablocations = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-locations-big.png";
				urltabtoporder = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-order-big-t.png";
				urltabtopmenu = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-menu-big-t.png";
				urltabtoplocations = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-locations-big-t.png";
			} else {
				urltaborder = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-order.png";
				urltabmenu = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-menu.png";
				urltablocations = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-locations.png";
				urltabtoporder = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-order-t.png";
				urltabtopmenu = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-menu-t.png";
				urltabtoplocations = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-locations-t.png";
			}
			urlclose = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-close.png";
			urlbackgroundcolor = "http://" + basedomain + "/floatingwindow/images/fi-" + windowcolor + "-back.png";
			$("#f2loatingwindow").css('backgroundImage','url(' + urlbackgroundcolor + ')');
		}
	
		// set the window color by loading the various images
		$('img.i2mgclose').attr('src', urlclose);
		$('img.i2mgclose').load(function() {
		//	callback(this);
		});

		$('img.i2mgtoplocations').attr('src', urltabtoplocations);
		$('img.i2mgtoplocations').load(function() {
		//	callback(this);
		});

		$('img.i2mgtopmenu').attr('src', urltabtopmenu);
		$('img.i2mgtopmenu').load(function() {
		//	callback(this);
		});

		$('img.i2mgtoporder').attr('src', urltabtoporder);
		$('img.i2mgtoporder').load(function() {
		//	callback(this);
		});

		$('img.i2mglocations').attr('src', urltablocations);
		$('img.i2mglocations').load(function() {
		//	callback(this);
		});

		$('img.i2mgmenu').attr('src', urltabmenu);
		$('img.i2mgmenu').load(function() {
		//	callback(this);
		});

		$('img.i2mgorder').attr('src', urltaborder);
		$('img.i2mgorder').load(function() {
		//	callback(this);
		});

		// check the window loction
		if (tabtype == "top") {
			$("#f2loatingwindow").css({right:"0"});
			$("#f2loatingwindow").css({top:"-550px"});
		} else {
			$("#f2loatingwindow").css({right:"0"});
			$("#f2loatingwindow").css({top:"0"});
			$("#f2loatingwindow").css({width:"40px"});
			$("#c2ontent").css({width:"0"});
			$("#c2ontent").css({display:"none"});
			$("#t2absr").css({right:"0"});
			$("#f2ramecontent").css({width:"0"});
			$("#c2lose").css({width:"0"});
			$("#c2lose").css({display:"none"});
		};
		
		// check to see if they want to lock the float window on the screen or allow it to scroll with the screen
		if (windowfloat == "ON") {
			$("#f2loatingwindow").makeFloat({x:"current",y:"current",speed:"normal"});
		};

		// set the overlay offset depending on what kind of tabs they would like to show
		if (tabsize == "big") {
			if (tabtype == "top") {
				$(".t2aborder").css({"margin-right":"-20px"});
				$(".t2abmenu").css({"margin-right":"-20px"});
				$(".t2ablocations").css({"margin-right":"-20px"});
			} else {
				$(".t2aborder").css({"margin-top":"-20px"});
				$(".t2abmenu").css({"margin-top":"-20px"});
				$(".t2ablocations").css({"margin-top":"-20px"});
			}
		} else {
			if (tabtype == "top") {
				$(".t2aborder").css({"margin-right":"-13px"});
				$(".t2abmenu").css({"margin-right":"-13px"});
				$(".t2ablocations").css({"margin-right":"-13px"});
			} else {
				$(".t2aborder").css({"margin-top":"-10px"});
				$(".t2abmenu").css({"margin-top":"-13px"});
				$(".t2ablocations").css({"margin-top":"-15px"});
			}
		};
		
		// check to see what tabs to show
		if (ordertab == "ON") {
			$(".t2aborder").css({display:"block"});
		} else {
			$(".t2aborder").css({display:"none"});
		};
		
		if (menutab == "ON") {
			$(".t2abmenu").css({display:"block"});
		} else {
			$(".t2abmenu").css({display:"none"});
		};

		if (locationstab == "ON") {
			$(".t2ablocations").css({display:"block"});
		} else {
			$(".t2ablocations").css({display:"none"});
		};
		
		// check the see what tabs to show - top or right
		if (tabtype == "top") {
			$("#t2abst").css({display:"block"});
			$("#t2absr").css({display:"none"});
		} else {
			$("#t2abst").css({display:"none"});
			$("#t2absr").css({display:"block"});
		}
		
		// create the show/hide functions for the tabs
	    $("a.s2howorder").click(function () {
		if (hidetabsonclose == "ON") {
			$("#f2loatingwindow").css({display:"block"});
		}
		    var url = "http://" + basedomain + "/order.php?a=" + opts.accountid + "&c=" + opts.accountkey;
		    $('iframe#f2ramecontent').attr('src', url);
			$('iframe#f2ramecontent').load(function() {
		        //	callback(this);
		        });
		    if (tabtype == "top") {
			$("#c2ontent").css({display:"block"});
			if (windowfloat == "ON") {
				$("#f2loatingwindow").makeFloat({x:"current",y:-10,speed:"normal"});
			} else {
				floatingwindow.css({top:"-10px"});
			}
		    } else {
			$("#f2loatingwindow").css({width:"870px"});
			$("#c2ontent").css({width:"800px"});
			$("#c2ontent").css({display:"block"});
			$("#t2absr").css({right:"830px"});
		    	floatingwindow.css({right:"5px"});
			$("#f2ramecontent").css({width:"800px"});
			$("#c2lose").css({width:"83px"});
			$("#c2lose").css({display:"block"});
		    }
	    });

	    $("a.s2howmenu").click(function () {
		if (hidetabsonclose == "ON") {
			$("#f2loatingwindow").css({display:"block"});
		}
		    var url = "http://" + basedomain + "/menu.php?a=" + opts.accountid + "&c=" + opts.accountkey;
		    $('iframe#f2ramecontent').attr('src', url);
			$('iframe#f2ramecontent').load(function() {
			 //       callback(this);
		        });
		    if (tabtype == "top") {
			$("#c2ontent").css({display:"block"});
			if (windowfloat == "ON") {
				$("#f2loatingwindow").makeFloat({x:"current",y:-10,speed:"normal"});
			} else {
		    		floatingwindow.css({top:"-10px"});
			}
		    } else {
			$("#f2loatingwindow").css({width:"870px"});
			$("#c2ontent").css({width:"800px"});
			$("#c2ontent").css({display:"block"});
			$("#t2absr").css({right:"830px"});
		    	floatingwindow.css({right:"5px"});
			$("#f2ramecontent").css({width:"800px"});
			$("#c2lose").css({width:"83px"});
			$("#c2lose").css({display:"block"});
		    }
  
		});

	    $("a.s2howlocation").click(function () {
		if (hidetabsonclose == "ON") {
			$("#f2loatingwindow").css({display:"block"});
		}
		    var url = "http://" + basedomain + "/locations.php?a=" + opts.accountid + "&c=" + opts.accountkey;
		    $('iframe#f2ramecontent').attr('src', url);
			$('iframe#f2ramecontent').load(function() {
		        //	callback(this);
		        });
		    if (tabtype == "top") {
			$("#c2ontent").css({display:"block"});
			if (windowfloat == "ON") {
				$("#f2loatingwindow").makeFloat({x:"current",y:-10,speed:"normal"});
			} else {
		    		floatingwindow.css({top:"-10px"});
			}
		    } else {
			$("#f2loatingwindow").css({width:"870px"});
			$("#c2ontent").css({width:"800px"});
			$("#c2ontent").css({display:"block"});
			$("#t2absr").css({right:"830px"});
		    	floatingwindow.css({right:"5px"});
			$("#f2ramecontent").css({width:"800px"});
			$("#c2lose").css({width:"83px"});
			$("#c2lose").css({display:"block"});
		    }   
		});
    
	    $("a.h2idewindow").click(function () {
		if (hidetabsonclose == "ON") {
			$("#f2loatingwindow").css({display:"none"});
		}
		    if (tabtype == "top") {
			$("#c2ontent").css({display:"none"});
			if (windowfloat == "ON") {
				$("#f2loatingwindow").makeFloat({x:"current",y:-550,speed:"normal"});
			} else {
			    	floatingwindow.animate({top:-550}, 'fast', function(){
			        });
			}
	        } else {
			$("#f2loatingwindow").css({width:"40px"});
			$("#c2ontent").css({width:"0"});
			$("#c2ontent").css({display:"none"});
			$("#t2absr").css({right:"0"});
			$("#f2ramecontent").css({width:"0"});
			$("#c2lose").css({width:"0"});
			$("#c2lose").css({display:"none"});
		    	floatingwindow.animate({right:0}, 'fast', function(){
		        });
	        }
	    });
    };	
});


(function($){
/*----------------------------------------------------------------------------------
Class: FloatObject
-------------------------------------------------------------------------------------*/
	function FloatObject(jqObj, params)
	{
		this.jqObj = jqObj;
		
		switch(params.speed)
		{
			case 'fast': this.steps = 5; break;
			case 'normal': this.steps = 10; break;
			case 'slow': this.steps = 20; break;
			default: this.steps = 10;
		};
		
		var offset = this.jqObj.offset();
		
		this.currentX = offset.right;
		this.currentY = offset.top;
		
		
		this.origX = typeof(params.x) == "string" ?  this.currentX : params.x;
		this.origY = typeof(params.y) == "string" ?  this.currentY : params.y;
		//if( params.y) this.origY = params.y;
		
		
		//now we make sure the object is in absolute positions.
		this.jqObj.css({'position':'absolute' , 'top':this.currentY ,'right':this.currentX});
	}
	
	FloatObject.prototype.updateLocation = function()
	{
		this.updatedX = $(window).scrollLeft() + this.origX;
		this.updatedY = $(window).scrollTop()+ this.origY;
		
		this.dx = Math.abs(this.updatedX - this.currentX );
		this.dy = Math.abs(this.updatedY - this.currentY );
		
		return this.dx || this.dy;
	}
	
	FloatObject.prototype.move = function()
	{
		if( this.jqObj.css("position") != "absolute" ) return;
		var cx = 0;
		var cy = 0;
		
		if( this.dx > 0 )
		{			
			if( this.dx < this.steps / 2 )
				cx = (this.dx >= 1) ? 1 : 0;
			else
				cx = Math.round(this.dx/this.steps);
			
			if( this.currentX < this.updatedX )
				this.currentX += cx;
			else
				this.currentX -= cx;
		}
		
		if( this.dy > 0 )
		{
			if( this.dy < this.steps / 2 )
				cy = (this.dy >= 1) ? 1 : 0;
			else
				cy = Math.round(this.dy/this.steps);
			
			if( this.currentY < this.updatedY )
				this.currentY += cy;
			else
				this.currentY -= cy;
		}
		
		this.jqObj.css({'right':this.currentX, 'top': this.currentY });			
	}

	
	
/*----------------------------------------------------------------------------------
Object: floatMgr
-------------------------------------------------------------------------------------*/		
	$.floatMgr = {
		
		FOArray: new Array() ,
		
		timer: null ,
		
		initializeFO: function(jqObj,params) 
		{
			var settings =  $.extend({
				x: 0 ,
				y: 0 ,
				speed: 'normal'	},params||{});
			var newFO = new FloatObject(jqObj,settings);
			
			$.floatMgr.FOArray.push(newFO);
			
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
			
			//now making sure we are registered to all required window events
			if( !$.floatMgr.registeredEvents ) 
			{
					$(window).bind("resize", $.floatMgr.onChange);
					$(window).bind("scroll", $.floatMgr.onChange);
					$.floatMgr.registeredEvents = true;
			}		
		} , 
		
		adjustFO: function() 
		{
			$.floatMgr.timer = null;
			
			var moveFO = false;
			
			for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
			{
				 FO = $.floatMgr.FOArray[i];
				 if( FO.updateLocation() )  moveFO = true;
			}
			
			if( moveFO )
			{
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					FO = $.floatMgr.FOArray[i];
					FO.move();
				}
				
				if( !$.floatMgr.timer ) $.floatMgr.timer = setTimeout($.floatMgr.adjustFO,50);
			}
		}	,
		
		onChange: function()
		{
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
		}
	};
	
/*----------------------------------------------------------------------------------
Function: makeFloat
-------------------------------------------------------------------------------------*/		
	$.fn.makeFloat = function(params) {
		var obj = this.eq(0); //we only operate on the first selected object;
		$.floatMgr.initializeFO(obj,params); 
		if( $.floatMgr.timer == null ) $.floatMgr.adjustFO();
		return obj;
	};
})(jQuery);

