(function($){

/**
 *  Empty Function
 *  @return false
 */
var emptyFn = function(){
	return false;
};

/**
 *  LightBox Defaults
 */
var lightBoxDefaults = {
	fixedNavigation: true,
	imageLoading: Site.info.url+'images/lightbox/lightbox-ico-loading.gif',
	imageBtnPrev: Site.info.url+'images/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: Site.info.url+'images/lightbox/lightbox-btn-next.gif',
	imageBtnClose: Site.info.url+'images/lightbox/lightbox-btn-close.gif',
	imageBlank: Site.info.url+'images/lightbox/lightbox-blank.gif'
};

/**
 *  Slides the sidebar to the Left
 *  @param handler jQuery The handler to be binded
 *  @param sidebar jQuery The sidebar to be animated
 */
var toggleSidebar = function(handler, sidebar){
	handler.click(function(){
		var left     = sidebar.css('left');
		var width    = sidebar.css('width');
		var animated = sidebar.is(':animated');
		
		// If it's been animated return false
		if (animated)
			return false;
		
		// Animate left or right depending in the current status
		if (parseInt(left) == 0)
			sidebar.animate({ left: '-'+width }, 'fast');
		else
			sidebar.animate({ left: 0 }, 'fast');
	});
};

/**
 *  Toggle tooltips
 *  @param handler jQuery The handler to be binded
 *  @param sidebar jQuery The tooltip to be animated
 */
var toggleTooltip = function(handler, tooltip){
	// flag to determine if we have to add a new hiding animation, so we don't have a long queue
	var isVisible = false;
	
	handler.bind('mouseenter', function(){
		// If it's been animated return false
		if (tooltip.is(':animated'))
			return false;
		
		// upgrade the z-index
		handler.css('z-index', 2).siblings().css('z-index', 1).end();
		
		// remove the display:none property in the tooltip so it can be animated again
		tooltip.show();
		
		// Animate the tooltip and activate the flag
		tooltip.animate({ top: '+25px', opacity: 1 }, 'fast');
		isVisible = true;
	});
	
	handler.bind('mouseleave', function(){
		// if tooltip is visible then animate it and then hide it
		if (isVisible) {
			tooltip.animate({ top: '-25px', opacity: 0 }, 'fast', function(){
				// hide the tooltip with display:none so the it's not triggered while it's invisible
				tooltip.hide();
			});
			isVisible = false;
		}
	});
};


/**
 *  Trigger scripts on Dom ready
 *  @param fn function The Whole script
 */
Site.init = function(){
	// Debug Mode: skips hrefs temporarily
	//$('a[rel=external]').click(emptyFn);
	
	$('#header-flash').flash({
		src: Site.info.url + 'media/' + Site.info.lang + '-header.swf',
		width: 729,
		height: 235,
		background: '#FFF',
		wmode: 'transparent',
		menu: false
	});
	
	$('#content-flash').flash({
		src: Site.info.url + 'media/bars.swf',
		width: 189,
		height: 94,
		background: '#FFF',
		menu: false
	});
	
	var $content = $('#content');
	$('script', $content).remove();
	$('*[style]', $content).removeAttr('style');
	$('font', $content).each(function(){
		var $font = $(this);
		var font = this;
		for (var i = font.attributes.length-1; i >= 0; i--) {
			$font.removeAttr(font.attributes[i].name);
		}
	});
	
	$('a[href=#backtotop]').remove();
}

})(jQuery);