google.load("jquery", "1.7");
//google.load("jqueryui", "1.7");

google.setOnLoadCallback(function(){
	var $j = jQuery.noConflict();
	
	$j("div.loader:first").bind("ajaxSend", function(){
		   $j(this).fadeIn("fast");
		 }).bind("ajaxComplete", function(){
		   $j(this).fadeOut("fast");
	 });

	// fluid navigation
	/*
	$j.fn.fluidNavigation = function(options) {
		var settings = {
			exclude: null,
			minusWidth: 0,
			recursion: true
		};
		if ( options ) { 
	    	$j.extend(settings, options);
		}
		
		jQuery(this).each(function(){
			var navigation = $j(this);
			var items = navigation.find('ul:first > li:not(' + settings.exclude + ')');
			var itemCount = items.size();
			
			var totalWidth = navigation.innerWidth() - settings.minusWidth;
			var newLiWidth = Math.floor(totalWidth / itemCount);
			var leftOver = totalWidth % newLiWidth;
			
			// Loop through the main items
			items.each(function(index, element) {
				// Add the leftover to the last item
				if (index + 1 == itemCount) {
					newLiWidth += leftOver;
				}
				// Set the new width
				$j(this).width(newLiWidth);
				
				// Set width on children
				if (settings.recursion == true) {
					var mainItem = $j(this);
					mainItem.children('ul:first').width(newLiWidth);
				}
			});
		});
	};
	*/
	
	$j.fn.tooltip = function(options) {
		var defaults = {
//			position: 'left',
			content: '',
			timeout: 10 // Amount of second before the tooltip is hidden again
		}
		if (options) { 
	    	options = $j.extend({}, defaults, options);
		}
		
		var id = 'tooltip';
		var tooltip = jQuery('#' + id);
		if (tooltip.length == 0) {
			jQuery("body").append("<div id=\"" + id + "\"></div>");
			tooltip = jQuery('#' + id);

			tooltip.css({
				'position': 'absolute',
				'z-index': 99,
				'display': 'none'
			});
		}
		
		var baseElement = jQuery(this);
		var top = baseElement.offset().top + baseElement.height();
		var left = baseElement.offset().left; 

		tooltip.css({
			'top': top + 'px',
			'left': left + 'px'
		});
		tooltip.html(options.content);
		setTimeout(function(){
			tooltip.slideDown();
		}, 150);
		
		setTimeout(function(){
			tooltip.slideUp();
		}, options.timeout * 1000);
	}
	$j.fn.tooltipClose = function() {
		jQuery('#tooltip').hide();
	}
	
	$j(document).ready(function() { 
		// shop navigation
		// $j('div.nav-container:first').fluidNavigation({});
		
		// cycle slideshow
		$j('div.cycle').cycle({
			fx:					'fade',
			speed:				3000,
			timeout:			5000
		});
	});
});
