	function hexFromRGB (r, g, b) {
		var hex = [
			r.toString(16),
			g.toString(16),
			b.toString(16)
		];
		$.each(hex, function (nr, val) {
			if (val.length == 1) {
				hex[nr] = '0' + val;
			}
		});
		return hex.join('').toUpperCase();
	}
	function refreshSwatch() {
		var red = $("#red").slider("value")
			,green = $("#green").slider("value")
			,blue = $("#blue").slider("value")
			,hex = hexFromRGB(red, green, blue);
			$("#color").html(hex);
			$("body").css("background-color",hex);
			$("html").css("background-color",hex);
			$("#nav_level_3_border_right").css("color",hex);
			


			$("#main_frame a:link").css("color",hex);
			$("#main_frame a:visited").css("color",hex);
			$("#main_frame a:link").css("color",hex);
					$("#nav_level_1_content a:link").css("color","FFF");
			$("#nav_level_1_content a:visited").css("color","FFF");
			$("#nav_level_1_content a:link").css("color","FFF");	
	}

$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}
		var slideCurrentToShow = new Array();			
	  var slideDivs = new Array();
	  
	  
		function ShowNextParagraph(divname) {				
				var width = $("#" + divname ).outerWidth();
				
				$("#" + divname + " table").each(function(i){					
						if (i!=slideCurrentToShow[divname]) {				
							$(this).fadeOut(100);
							$('#entry_'+divname+'_'+(i)).css("text-decoration","none");									
						} else if (i==slideCurrentToShow[divname]) {
							$(this).delay(300).fadeIn(300);							
							$('#entry_'+divname+'_'+(i)).fadeOut(150).fadeIn(150);
							$('#entry_'+divname+'_'+(i)).css("text-decoration","underline");						
						}
						});
				
				slideCurrentToShow[divname] = slideCurrentToShow[divname] + 1;
				if (slideCurrentToShow[divname]>$("#" + divname + " table").size()-1) 
					slideCurrentToShow[divname]=0;
		}
				
		function CreateAutoSlideListFromDiv(listDiv) {								 
			  $("#" + listDiv + " table").hide();
				var newscountText="";
				var count = $("#" + listDiv + " table").size();
				for (m=1; m<=count;m++) {
					newscountText+='<a id="entry_'+listDiv+'_'+(m-1)+'">' + m + "</a>";
					if (m<count) newscountText+= " | ";
				}
			
				$("#" + listDiv).append('<div class="autoSlideListNav">' + newscountText + '</div>');
			
				for (m=0; m<count;m++) {
						$("#entry_"+listDiv+"_"+m).mouseenter(function(){
											var vals = this.id.split("_");
											slideCurrentToShow[vals[1]] = vals[2];
											ShowNextParagraph(vals[1]);
										});
				}
				
				slideCurrentToShow[listDiv]=0;
				
				var width = $("#" + listDiv ).outerWidth();
				var maxPHeight = 0;
				$("#" + listDiv + " table").each(function(){		
					$(this).width(width-20);
					if ($(this).height()>maxPHeight) maxPHeight=$(this).height();				
			  });				  
				$("#" + listDiv ).height(maxPHeight+10);
								
				
				$("#" + listDiv).mouseenter(function(){
														StopAutoSlide();														
													});
				$("#" + listDiv).mouseleave(function(){
														StartAutoSlide();														
													});
			
		}
		
		function CreateAutoSlides() {
			for (n=0; n<slideDivs.length;n++) {
				CreateAutoSlideListFromDiv(slideDivs[n]);
			}
	
		}
		function SetSameHeight(divs) {				
			var maxHeight = 0;
			for (n=0; n<divs.length;n++) {			
				var curHeight = $("#"+divs[n]).height();
				if (maxHeight<curHeight) maxHeight = curHeight;
			}
			for (n=0; n<divs.length;n++) {	
				$("#"+divs[n]).height(maxHeight);
			}
			
		}
		var slideTimer;
		function StopAutoSlide() {

			clearInterval(slideTimer);
		} 
		
		function StartAutoSlide() {

			slideTimer=setInterval("ShowNextSlide()",5000);
		}
		
		var currentSlideListNr = 0;
		function ShowNextSlide() {			
			ShowNextParagraph(slideDivs[currentSlideListNr]);
			currentSlideListNr++;
			if (currentSlideListNr>slideDivs.length-1) currentSlideListNr=0;
		}
		
$(document).ready(function() {
	

	function hideAll_Nav_Level_2_AndShowCurrent() {  
		$("#nav_level_2_content ul").each( function( intIndex ){ 
			if ( $(this).hasClass("nav_level2_current") )
 			   $(this).show();
			else 
			   $(this).hide();
		});  
		$("#nav_level_1_content .nav_level1_entry_current").each( function(intIndex) {
			Set_Nav_Level1_HoverToElement($(this).attr('id'));
		});
	//	$("#topnav-bottom-hover").hide();
	}
	function Set_Nav_Level1_HoverToElement(ele_id) {			
		$("#nav_level_1_hover").animate({ 
			width: $("#" + ele_id).width()+30,
			left: $("#" + ele_id).position().left-15
		}, 150 );
	}	
	
	$("#nav_level_1_content a").mouseenter(function(){		
		$("#nav_level_2_content ul").hide();
		//$("#nav_level_2_hover").hide();
		Set_Nav_Level1_HoverToElement(this.id);		 
		$("#subnav"+this.id).show();	
	});
	

	$("#nav_frame").mouseleave(function(){
		hideAll_Nav_Level_2_AndShowCurrent();			
	});
						
	hideAll_Nav_Level_2_AndShowCurrent();  


		
	if ($("#newslist").length) {
	
		slideDivs = new Array("newslist","servicelist","presslist","customerlist");
		CreateAutoSlides();
		SetSameHeight(new Array("newslist","servicelist"));
		SetSameHeight(new Array("presslist","customerlist"));
		
	
			for (n=0; n<slideDivs.length;n++) {
				ShowNextParagraph(slideDivs[n]);
			}
			
			StartAutoSlide();
		
	}
 });


 
