if (location.href.match("/sitecore/shell/") == null) {
/**
 * @author Cedric Michaux (Lbi) :: cedric.michaux@lbigroup.be
 */



(function($){
	$.fn.overlay = function(options){
		
		this.each(function(){
			this.$trigger = $(this);
			this.opt = {
				anim: {
					effect : {
						slide: (this.$trigger.hasClass("slide")) ? true : false,
						fade: (this.$trigger.hasClass("fade")) ? true : false
					},
					time: "fast"
				},
				triggers: {
					hover: (this.$trigger.hasClass("hover")) ? true : false,
					click: (this.$trigger.hasClass("click")) ? true : false
				},
				activeClass: "overlayDisplay",
				overlayBg: "#overlayBg",
				hideTimeout: 200
			};
			$.extend(this.opt, options);

			this.$over = $(this.rel)
			this.$overlayBg = $(this.opt.overlayBg)
			
			
			if(this.opt.triggers.hover)
				this.$trigger.hover(function(){
					//Mouse in
					
					
					if(this.opt.anim.effect.slide)
						$.fn.overlay.display.slide(this.$over, this.opt)
					else if(this.opt.anim.effect.fade)
						$.fn.overlay.display.fade(this.$over, this.opt)
						
					this.$trigger.addClass(this.opt.activeClass);
					
				}, function(){
					clearTimeout($.fn.overlay.overlayTimeOut[0]);
					if(this.opt.anim.effect.slide)
						anim = "slide"

					else if(this.opt.anim.effect.fade)
						anim = "fade"
					
					this.$over.attr("time", this.opt.anim.time);
					this.$over.attr("hideTimeout", this.opt.hideTimeout);
					this.$over.attr("cssClass", this.opt.activeClass);
					this.$over.attr("trigger", this.$trigger.attr("id"));
					
					this.$over[0].timeOut = setTimeout("jQuery.fn.overlay.hide."+anim+"(\"#"+this.$over.attr("id")+"\", \"" + this.opt.anim.time + "\", \"#"+this.$trigger.attr("id")+"\", \"" + this.opt.activeClass + "\")", this.opt.hideTimeout);
					
					this.$over.hover(function(){
						clearTimeout(this.timeOut);
					},function(){
						this.timeOut = setTimeout("jQuery.fn.overlay.hide."+anim+"(\"#"+this.id+"\", \"" + $(this).attr("time") + "\", \"#" + $(this).attr("trigger") + "\", \"" + $(this).attr("cssClass") + "\")", $(this).attr("hideTimeout"));
					})
				})
			
			else if(this.opt.triggers.click)
				this.$trigger.click(function(){
					
					if(this.opt.anim.effect.slide)
						$.fn.overlay.display.slide(this.$over, this.opt)
					else if(this.opt.anim.effect.fade)
						$.fn.overlay.display.fade(this.$over, this.opt)
					if(this.$overlayBg.length > 0)
						this.$overlayBg.show();
				});
				
		this.$overlayBg.click(function(){
			$("div.overlay:visible").hide();
			$(this).hide();
		})
		
		$(".overlay a.close").attr("rel", "#"+this.$overlayBg.attr("id"));
		$(".overlay a.close").click(function(){
			$(this.rel).hide();
			$(this).parents(".overlay").hide();
		})
	})
		
			
	}
	
	$.fn.overlay.overlayTimeOut = new Array();
	
	$.fn.overlay.display = {
		slide: function($over, opt){
			$over.slideDown(opt.anim.time);
		},
		
		fade: function($over, opt){
			$over.animate({opacity: 100}, opt.anim.time).show().css("opacity", 0);
		}
	}
	
	$.fn.overlay.hide = {
		slide: function(id, time, trigger, cssClass){
			$(id).slideUp($.fn.overlay.toTime(time))
			$(trigger).removeClass(cssClass);
		},
		
		fade: function(id, time, trigger, cssClass){
			$(id).animate({opacity: 0}, $.fn.overlay.toTime(time));
			$(trigger).removeClass(cssClass)
		}
	}
	
	$.fn.overlay.toTime = function(str){
		tTime = parseInt(str)
		if(!isNaN(tTime))
			str = tTime;
		return str;
	}
	
})(jQuery)
}
