(function($) {
	$.fn.ilike = function(options) {
		var ilikeNav = this,
		ilikeAnchors = ilikeNav.children("li").children("a");

		var Init = function(){
			if(ilikeNav){
				$.each(ilikeAnchors, function() {
					var ulSubMenu = $(this).siblings();
					if(ulSubMenu.length > 0){
						$(this).bind('click', function() {
							ShowSubMenu(this);
							return false;
						});
					}
                });
				onmouseout = HideSubMenu;
			}
		}

		var ShowSubMenu = function(o){
			HideAllSubMenus();
			var ulSubMenu = $(o).siblings();
			if(ulSubMenu.length > 0){
				ulSubMenu.css({visibility: 'visible'});
				return false;
			}
		}

		var HideAllSubMenus = function(){
			var ilikeSubMenus = ilikeNav.find("ul");
			$.each(ilikeSubMenus, function() {
				$(this).css({visibility: 'hidden'});
			});
		}

		var HideSubMenu = function(e){
			if (!e) var e = window.event;
			var tg = (window.event) ? e.srcElement : e.target;
			if (tg.id != 'ilike-nav') return;
			var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
			if(reltg != null){
				while (reltg != tg && reltg.nodeName != 'BODY' && reltg.nodeName != 'HTML')
				reltg= reltg.parentNode
				if (reltg== tg) return;
				//mouse left layer
				HideAllSubMenus();	
			}
		}

		Init();
	}
	// Firstpage slideshow
	$.fn.slideshow = function(options) {
		
			var prevItem,
				interval,
				timer		= 5000,
				items 		= this,
				itemlength 	= items.size(),
				start		= 0;

			var fadeI = function(item) {
				clearTimeout(interval);

				//alert(itemlength);
				if($(prevItem).is(".slide")){
					$(prevItem).fadeOut(2000);
				}


				$(item).fadeIn(2000);
				interval = setTimeout(function (){
					start++;

					if(start > (itemlength-1)) {
						start = 0;
					}

					fadeI(items[start]);
				},timer);
				prevItem = item;
			}

			var fadeO = function(item) {
				$(item).fadeOut("slow");
			}

			if(itemlength > 1){
				fadeI(items[start]);
			}
		
	}
})(jQuery);

jQuery(function($) {
	$('.slideshow div.slide').slideshow();
	//$('#ilike-nav').ilike();
});

jQuery.noConflict();
jQuery(window).bind('unload', function() { jQuery('*').unbind(); });