
$(document).ready(function(){
	
	
	$("#top-menu li").each(function(){
		if($(this).hasClass("selected")) {
			$(this).parent().parent().attr("class","selected");	
		}
	})
	
	
	$("#top-menu ul li").hover(function(){
	
			var chld = $(this).find("ul").length;
	
			if (chld) {
				
				var linkWidth = parseInt($(this).width()); // 1px border
				var childMenu = $(this).find("ul:first");
				
				$(this).addClass("active");
				
				$(childMenu).css({
					"background-image" : "url(images/border-top-menu-long.gif)",
					"background-repeat" : "no-repeat",
					"background-position" : linkWidth+"px top"
				})
									
				$(this).find("ul:first").show();
			}		
		
		
	}, function(){
				
		$(this).find("ul:first").hide();
		$(this).removeClass("active");
	})
		
	/* OSX MENU */
	
	
	
	$(function(){
		var jqDockOpts = {align: 'left', duration: 200, labels: 'tc', size: 180, distance: 35, labels:false};
		$('#menu-banner').jqDock(jqDockOpts);
	});
	
	
	
	/* BANNER */
	
	if ($("#banner-images img").length > 1) { 
	
		$('#banner-images').cycle({ 
			fx:     'fade', 
			speed:  'slow', 
			timeout: 5000 
		});
		
	}

	/* NEWS */

	/* display open articles - all open if js switched off! */
	
	totalHeight = 0;
	
	if ($("#news .news-item").length > 0) {	
		$("#news .news-item").each(function(){
			totalHeight = totalHeight + $(this).height();
		})
		
		if (!totalHeight == 0) {
			$("#news").css("height", totalHeight+"px");
		}
	}
	
	
	$("#news .news-item .news-item-footer-right span").each(function(){
		if(!$(this).hasClass("open")) {
			$(this).parent().parent().parent().find(".news-item-content").css("display","none");
			$(this).parent().parent().find(".news-item-footer-right div.contact").hide();
		}
	})
	
	/* on click event - show/ hide article */
	$("#news .news-item .news-item-footer-right span").click(function(){
				
		if ($(this).hasClass("open")) {
			$(this).parent().parent().parent().find(".news-item-content").slideUp();
			$(this).parent().parent().find(".news-item-footer-right div.contact").hide();
			$(this).attr("class","closed");
			
			$(this).find(".news-item-content").slideUp();
			$(this).find(".news-item-footer-right div.contact").hide();
			$(this).find().attr("class","closed");
			
		} else if ($(this).hasClass("closed")) {
			$(this).parent().parent().parent().find(".news-item-content").slideDown();
			$(this).parent().parent().find(".news-item-footer-right div.contact").show();
			$(this).attr("class","open");
		}
	
	})
	
})