/**
 * Compact labels plugin
 */
(function($){$.fn.compactize=function(){return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){label.hide();}).blur(function(){if(input.val()===''){label.show();}});window.setTimeout(function(){if(input.val()!==''){label.hide();}},50);});};})(jQuery);

/*
 * hrefID jQuery extention - returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		},
		forms : {
			labels : function(){
				$('#search label').compactize();
			}
		},
		ui : {
showcase : function(){
				var $root 		= $('#slider');
				var $slider 	= $root.find('#sliding-items');
				
				var pages 		= $slider.find('div.slide').length;
				var width 		= $root.find('div.slide').width();
				var current 	= 1;
				
				if(pages > 1) $root.append('<ul class="controls"><li class="prev"><a href="#prev">Previous<span></span></a></li><li class="next"><a href="#next">Next<span></span></a></li></ul>');
				var $controls 	= $root.find('ul.controls li a');

				var check = function(){
					if(current == 1){
						$root.find('ul.controls li.prev').hide();
					} else {
						$root.find('ul.controls li.prev').show();					
					}
					
					if(current == pages){
						$root.find('ul.controls li.next').hide();
					} else {
						$root.find('ul.controls li.next').show();					
					}
				}
				
				$controls.click(function(){
					var direction = $(this).parent().attr('class');
					if($slider.is(':animated') || (current == 1 && direction == 'prev') || (current == pages && direction == 'next')) return false;
					
					if(direction == 'next'){
						move = '-='+width+'px';
						current++;
					} else {
						move = '+='+width+'px';
						current--;
					}					
					
					$slider.animate({'marginLeft': move}, 500);
					check();
					
					return false;
				});
				
				check();
			}
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	Engine.forms.labels();
	Engine.ui.showcase();
	
	$('#post-8 table td:first').css('border', '1px solid #000');
	$('#post-8').prepend('<div id="tooltip"><div class="top"></div><div class="middle">&nbsp;</div><div class="bottom"></div></div>');
	
	$('table.calendar-b a.event-link').tooltip({tip: '#tooltip',  offset: [40,110],
	onShow: function() { 
		var tooltipContent = this.getTrigger().find('span.tooltip').html();
        $("#tooltip .middle").append(tooltipContent); 
    } ,
    
    onBeforeHide: function() { 
        $("#tooltip .middle").html(''); 
    }
}); 
	
});