// mailmask

$.fn.noSpam = function() {
	at = '@';
	return this.each(function(){
		e = null;
		$(this).find('span').replaceWith(at);
		e = $(this).text();
		$(this).attr('href', 'mailto:' + e);
	});
};



// go to top

$.fn.topLink = function(settings) {
	settings = jQuery.extend({fadeSpeed: 200}, settings);
		var scroll_timer;
		var displayed = false;
		var $message = $(this);
		var $window = $(window);
		var top = $(document.body).children(0).position().top;
		$window.scroll(function () {
			window.clearTimeout(scroll_timer);
			scroll_timer = window.setTimeout(function () {
				if($window.scrollTop() <= top)
				{
					displayed = false;
					$message.fadeOut(settings.fadeSpeed);
				}
					else if(displayed == false) 
				{
					displayed = true;
					$message.stop(true, true).fadeIn(settings.fadeSpeed).click(function () { $message.fadeOut(settings.fadeSpeed); });
				}
			}, 100);
		});
};


 $(document).ready(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
	


// tooltip

(function($) {
	$.fn.easyTooltip = function(options){
		// default configuration properties
		var defaults = {	
			xOffset: -9,		
			yOffset: 39,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {  				
			var title = $(this).attr("title");
			$(this).hover(function(e){						 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")				
						.css("display","none")
						.fadeIn("normal")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	};
})(jQuery);


					
							
	$('a.escape').noSpam();
	$('.goToTop').topLink({fadeSpeed: 500});
	$("a[rel='lightbox']").colorbox({maxHeight:"90%"});
//	$('#screens').cycle({fx: 'fade',speed: 1500, timeout: 5500 });
	
//	$('#screens') .before('<div id="nav">') .cycle({ fx:     'fade', speed:  'fast', pager:  '#nav'});
	
	$('a#link1').easyTooltip({useElement: 'item1' });
	$('a#link2').easyTooltip({useElement: 'item2' });
	$('a#link3').easyTooltip({useElement: 'item3' });
	$('a#link4').easyTooltip({useElement: 'item4' });
	$('a#link5').easyTooltip({useElement: 'item5' });

});
 
 
