
		$(document).ready(function() {
			$('#hyvinvointi #nav_cat_archive li:first, #ruoka-ja-juoma #nav_cat_archive li:first').css('border',0);
			
			$('#nav_cat_archive li ul li').hover(function(){
				$(this).css('background-color','#FFFFFF');
			},function(){
				if( ! $(this).hasClass('active')){
					$(this).css('background-color','transparent');
				}
			});
			
			$('#toggle_rules').click(function(e){
				$('#rules').slideToggle(750);
				e.preventDefault();
			})
			
			$('#nav_cat_archive li ul li a.active').parent('li').addClass('active');
			
			$("#back_to_top").click(function(e){
				$('html,body').animate({scrollTop: 0}, 500);
				e.preventDefault();
			})
			
			if($("body").attr("id") == "home"){
			
			// two jquery selectors and a configuration given as an object literal
			$("#home ul.tabs").tabs("div.panes > div", {
				// configuration variables
				current: 'current',
				effect: 'fade',
				initialIndex: 0,
				rotate: true,
				onClick: function(event, tabIndex) {
					
					sIFR.replace(neutra, {
					  selector: '#home .hero-content h1 ',
					  css: '.sIFR-root {color:#16407b; background-color:#000000; leading:-20; font-weight:normal; font-style:italic; letter-spacing:-3 }',
					  tuneHeight: -15,
					  fitExactly: false,
					  offsetTop: -10,
					  wmode: 'transparent'
					});
					
					sIFR.replace(neutra, {
					  selector: '#home .hero-content h4',
					  css: '.sIFR-root {font-size:21px; color:#16407b; background-color:#FF0000; font-weight:normal; font-style:italic; margin-bottom:0; }',
					  tuneHeight: -5,
					  fitExactly: false,
					  offsetTop: -5,
					  wmode: 'transparent'
					});
					
					return true;
				}

			});
			
				// advance to the next tab
				setTimeout(function(){
					var api = $("#home ul.tabs").data("tabs");
					advanceTabs(api);
				}, 5000);
			}
			
			if($("body").attr("id") == "tuotteet"){
				sIFR.replace(neutra, {
				  selector: '#hero .hero-content h1',
				  css: '.sIFR-root {color:#16407b; background-color:#000000; leading:-20; font-weight:normal; font-style:italic; letter-spacing:-3 }',
				  tuneHeight: -15,
				  fitExactly: false,
				  offsetTop: -10,
				  wmode: 'transparent'
				});

				sIFR.replace(neutra, {
				  selector: '#hero .hero-content h2',
				  css: '.sIFR-root {font-size:30px; color:#16407b; background-color:#FF0000; font-weight:normal; font-style:italic; margin-bottom:0; }',
				  tuneHeight: -5,
				  fitExactly: false,
				  offsetTop: -8,
				  wmode: 'transparent'
				});
			
				// two jquery selectors and a configuration given as an object literal
				$("#tuotteet ul.tabs").tabs("div.panes > div", {
					// configuration variables
					current: 'current',
					effect: 'fade',
					initialIndex: null,
					onClick: function(event, tabIndex) {
						
						sIFR.replace(neutra, {
						  selector: '#hero .hero-content h1',
						  css: '.sIFR-root {color:#16407b; background-color:#000000; leading:-20; font-weight:normal; font-style:italic; letter-spacing:-3 }',
						  tuneHeight: -15,
						  fitExactly: false,
						  offsetTop: -10,
						  wmode: 'transparent'
						});

						sIFR.replace(neutra, {
						  selector: '#hero .hero-content h2',
						  css: '.sIFR-root {font-size:30px; color:#16407b; background-color:#FF0000; font-weight:normal; font-style:italic; margin-bottom:0; }',
						  tuneHeight: -5,
						  fitExactly: false,
						  offsetTop: -8,
						  wmode: 'transparent'
						});
						
						return true;
					}
					//fadeInSpeed: 1000,
					//fadeOutSpeed: 500,
				//	rotate: true
				});
			}
			
			$('.accordion .accordion-head').click(function() {
				$(this).next(".accordion-content").slideToggle('slow');
				return false;
			}).next().hide();
			
			$('#arvonta-form').submit(function(){
				var etunimi = $(this).find("#etunimi").val();
				var sukunimi = $(this).find("#sukunimi").val();
				var osoite = $(this).find("#osoite").val();
				var puhelinnumero = $(this).find("#puhelinnumero").val();
				var sahkoposti = $(this).find("#sahkoposti").val();
				
				if(etunimi == "" || sukunimi == "" || (sahkoposti == "" && puhelinnumero == "")){
					$(this).find("#error").css("color","#FF0000").html("Ole hyv&auml; ja t&auml;yt&auml; ainakin nimesi sek&auml; s&auml;hk&ouml;postiosoite tai puhelinnumerosi ja l&auml;het&auml; lomake uudelleen.").fadeIn("slow");
					return false;
				}
				
				if($(this).find("#hyvaksyn_saannot").is(":checked")){
					return true;
				}else {
					$(this).find("#error").css("color","#FF0000").html("Ole hyv&auml; ja hyv&auml;ksy arvonnan s&auml;&auml;nn&ouml;t osallistuaksesi").fadeIn("slow");
					return false;
				}
				
			});
			
		// Dropdown menu	
			var hideTimeout, showTimeout, panelVisible;

			// Funktiot
			function showPanel() {
				clearTimeout(showTimeout);
				$('#sub').fadeIn('fast');
				$('#trigger_sub').addClass('on');
				panelVisible = true;
			}

			function hidePanel() {
				clearTimeout(hideTimeout);
				$('#sub').fadeOut('fast');
				$('#trigger_sub').removeClass('on');
				panelVisible = false;
			}

			// Eventit
			$('#trigger_sub, #sub').mouseleave(function() {
			    hideTimeout = setTimeout(hidePanel, 500);
			});

			$('#trigger_sub, #sub').mouseenter(function() {
			    clearTimeout(hideTimeout);
			    showTimeout = setTimeout(showPanel, 100);
			});

			$('#trigger_sub').click(function(e) {
			    if (panelVisible) {
			        hidePanel();
			    }
			    else {
			        showPanel();
			    }
			    e.preventDefault();
			});
			
		});	

		function advanceTabs(api){
			api.next();
			setTimeout(function(){
				advanceTabs(api);
			}, 5000);
		}
