	function preload(arrayOfImages) {
	    $(arrayOfImages).each(function(){
	        $('<img/>')[0].src = this;
	    });
	}


	preload([
	    //'/img_new/background_top_jump.jpg',
	    //'/img_new/background_top_yoga.jpg',
	    //'/img_new/background_top_siluett.jpg',
	    '/img_new/background_top_winter.jpg',
	    '/img_new/background_top_frost.jpg',
	    '/img_new/background_top_maple.jpg',
		'/img_new/background_banner_big.jpg',
	    '/img_new/steg-1-popup.jpg'
	]);

	function nl2br(str) {
	
		return  str.replace(/\n/g, "<br />\n")
	
	}
	
	function g_track(cat, action, label) {
	  
	  //var value = (value === undefined) ? '' : value;
	  
	  _gaq.push(['_trackEvent', cat, action, label]);
	  
	}
	
	function PopupBlocked(w) {
		
		try { w.focus(); return false; }
		catch(e) { return true; }
	}
	
	
  function tell(message, red, notimer) {
    
    if (red === undefined) {
      css_class = "green";
    } else {
      css_class = (red === 0) ? "green" : "red"; 
    }
    
    remover = (css_class=="green") ? "red" : "green";
    //
    
    if (notimer === undefined || notimer === 0) {
    
      try {
        clearTimeout(shush);            
      } catch(err) { 
        custErr = "shush not yet defined\n - carry on";
      }
      
      
      $("#returner").removeClass(remover).addClass(css_class);
      $("#returner").fadeIn('fast');
      $("#returner").html(message);
      shush = setTimeout(function(){
        $("#returner").fadeOut('fast');
      },6000);
    } else {
      
      try {
        clearTimeout(shush);            
      } catch(err) { 
        custErr = "shush not yet defined\n - carry on";
      }
      
      
      $("#returner").removeClass(remover).addClass(css_class);
      $("#returner").fadeIn('fast');
      $("#returner").html(message);
    }
  }

	
	function showGulaSidorna(adress) {
		url = "googlemaps.asp?address="+adress;
		popUp=window.open(url,"popUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600");
		
		var failure = 'För att visa kartan måste s.k. popupfönster vara tillåtna. Vänligen tillåt '+window.location.host+' och försök igen.';
		
		if (popUp == null || typeof(popUp)=='undefined') {  
		  alert(failure); 
		} 
		else {  
			if(PopupBlocked(popUp)) {
				alert(failure);		
			} else {
				popUp.focus();
			}
		  
		}
		
	
		
		
	}
	
	function populateTop() {
		
		
		for (i=0;i<topBgs.length;i++) {
			
			msgRef = i*2;
			
			initLink = "<a class=\"topLink_"+topStyles[i]+"\" href=\""
			
			if (topLinks[msgRef].length) 
				link1 = initLink+topLinks[msgRef]+".asp\">"+nl2br(topMsgs[msgRef])+"</a>";
			else 
				link1 = nl2br(topMsgs[msgRef]);
				
			if (topLinks[msgRef+1].length) 
				link2 = initLink+topLinks[msgRef+1]+".asp\">"+nl2br(topMsgs[msgRef+1])+"</a>";
			else 
				link2 = nl2br(topMsgs[msgRef+1]);
				
			inn(topBgs[i]+"_1", "<p class="+topStyles[i]+">"+link1+"</p>");			
			inn(topBgs[i]+"_2", "<p class="+topStyles[i]+">"+link2+"</p>");
			
			
			
			
		}
		
		
		$("#loader").css({
			"display" : "none"
		});
		$("#main_hider").css({
			"display" : "none"
		});
		
	}
	
	
	function contactLog(data) {
		
		
		$.post("contacter.php",data,function(returndata) {
			if (data.indexOf("newContact: ") != -1) {
				
				 alert(returndata);
				
				
			}
		});
		
	}
	
	
	
	function inn(div,conts) {
		
		if (document.getElementById(div))
			document.getElementById(div).innerHTML = conts;
		
	}
	
	
		// function onTop() { //(FOLDING ONLY)
	
	/* Top rotation 
	
	set up two arrays: bg-images and messages
	
	Two steps:
	1. rotate background-image every 6 seconds topRotate();
	2. rotate message every 3.5 seconds 
	
	*/
	
	var topBgs = new Array();
	
		topBgs[0] = "tb_one";
		topBgs[1] = "tb_two";
		topBgs[2] = "tb_three";
		
	var topStyles = new Array();
	
		topStyles[0] = "light"; //tb_one
		topStyles[1] = "light"; //tb_two
		topStyles[2] = "light"; //tb_three
 	
	var topMsgs = new Array();
		
		//for topBgs[0]
		topMsgs[0] = "Diplomerad Friskvårdsterapeut och Kostkonsult \n - Ansök nu till höstens utbildningar";
		topMsgs[1] = "Basutbildning i psykoterapi med psykodynamisk inriktning (Steg-1)\n Kursstart i Malmö den 3 februari 2012. ";
		
		//for topBgs[1]
		topMsgs[2] = "Utvecklas med oss!\n - Utbildning och kompetensutveckling inom \n hälsa och personlig utveckling";
		topMsgs[3] = "Avspännings- och Stressterapeut med kognitiv inriktning\n - Ansök nu till höstens utbildningar";
		
		//for topBgs[2]
		topMsgs[4] = "Ettårig utbildning i kognitiv beteendeterapi (KBT) \n Kursstarter hösten 2011 i Stockholm,\nMalmö, Kalmar och Göteborg";
		topMsgs[5] = "Kurs i kris och krishantering \n - För dig som möter människor i kris och sorg";
		
		msgLinks = "/utb/fsv,/utb/psykokbt_sthml,,/ubt/ass,/utb/kbt,/utb/kris";
		
		topLinks = msgLinks.split(",");
/*		
		}
*/
	
	// variables and functions for function topRotattion() { 
	uc = topBgs.length;
	var next, timer, continuer = null;

	
	function topRotate(x) {
		
		continuer = x+1;
		
		if (x == 0) { //if first is selected
			
			next = x + 1;
			$("#"+topBgs[x]).fadeIn(800);				
			
		} else {
		
			if (x == uc) {
				next = 0; //if last in array, restart
				for (i=1;i<uc-1;i++) 
					$("#"+topBgs[i]).fadeOut(0);
					
				$("#"+topBgs[x-1]).fadeOut(800, function() {
					clearTimeout(timerBg);
					topRotate(next);
				});				
				
			} else {
				next = x + 1; //normal: go to next, fade previous
				$("#"+topBgs[x]).fadeIn(800, function() {
					//$("#"+topBgs[x-1]).fadeOut(0);	
				});
			}
			
		
		}
		
		//initiate msgrotater
		msgRotate(x);
		
		timerBg = setTimeout(function() {
			topRotate(next)
			},8000);
		
		

    }


	function msgRotate(x) { 	//Rotate msgs
		
			//hide second msg if transition bug
			for (i=0;i<topBgs.length;i++)
				$("#"+topBgs[i]+" #"+topBgs[i]+"_2").css("display", "none");
		
			//rotate
			$("#"+topBgs[x]+" #"+topBgs[x]+"_1").fadeIn('fast', function() { //fadeIn first message
			timerMsgOne = setTimeout(function() {
				$("#"+topBgs[x]+" #"+topBgs[x]+"_1").fadeOut('fast', function() { //fadeOut first message after 3 seconds
					$("#"+topBgs[x]+" #"+topBgs[x]+"_2").fadeIn('fast', function(){//fadeIn second message first is faded out
						timerMsgTwo = setTimeout(function() {
							$("#"+topBgs[x]+" #"+topBgs[x]+"_2").fadeOut('fast'); //fadeOut second message
						},4000);
					});
				});
			},4000);
		});
	}



	/*  
	}
*/

	// function thumb_3() {//(FOLDING ONLY)
	
	/*  	randomize contents of thumb_3 (latest) 
		
		[i][0] = file name (no ending)
		[i][1] = header 
		[i][2] = text 
		[i][3] = image name (only file name with ending)
		
	*/
	
	numberOfEntries = 5;
	
	var latest = new Array(numberOfEntries);
	
	for (i=0;i<latest.length;i++) 
		latest[i] = new Array(4);
	
	//psykokbt_sthml
	latest[0][0] = "utb/psykokbt_sthml";
	latest[0][1] = "Psykoterapi (Steg-1 KBT)";
	latest[0][2] = "Basutbildning i psykoterapi med kognitiv beteendeterapeutisk inriktning (Steg-1 KBT) i Stockholm med start den 6 maj";
	latest[0][3] = "background_thumb_blue2.jpg";
	
	//kbt
	latest[1][0] = "utb/kbt";
	latest[1][1] = "Ettårig utbildning i KBT";
	latest[1][2] = "Ettårig utbildning i Kognitiv Beteendeterapi (KBT) på flera platser i landet.\n\nÖstersund 11/05\nStockholm 26/10\nMalmö 31/10";
	latest[1][3] = "background_thumb_blue2.jpg";
	
	/*Borlänge 16/03, Linköping 04/04, Malmö 16/03, Stockholm 06/04, Östersund 11/05 */
	latest[2][0] = "utb/kbt";
	latest[2][1] = "Ettårig utbildning i KBT";
	latest[2][2] =  "Ettårig utbildning i Kognitiv Beteendeterapi (KBT) på flera platser i landet.\n\nKalmar 21/11\nGöteborg 23/11";
	latest[2][3] = "background_thumb_blue2.jpg";
	
	//kris
	latest[3][0] = "utb/kris";
	latest[3][1] = "Kurs i Krishantering";
	latest[3][2] = "En unik utbildning för dig som effektivt och målinriktat vill arbeta med människor i kris.\nKursstarter:\nMalmö 14 november\nStockholm 8 november";
	latest[3][3] = "background_thumb_blue2.jpg";
	
	
	//stressad
	latest[4][0] = "utb/stressad";
	latest[4][1] = "Stressad? Hjälp, hur gör man?";
	latest[4][2] = "Välkommen till en endagskurs i stresshantering för er som vill ta kontroll över er stress!\n\nKursstarter:\nMalmö 11 och 14 maj";
	latest[4][3] = "background_thumb_blue2.jpg";
	
	/*
	Malmö:
	2011-02-16
	2011-02-17
	2011-04-15

	Stockholm;:
	2011-03-09
	2011-03-10
	2011-04-29
	}	
*/ 
	
	
	var next_inc;
	
	function getLatest(inc) {
		
		var delay = 5; //delay in seconds
		
		if (inc === undefined)
			inc = 0;
		
		if (inc == latest.length-1)
			next_inc = 0;
		else
			next_inc = inc+1;
		
		$("#thumb_3").click(function() {
			void(0);
		});
		$("#thumb_3 p").fadeOut(400, function() {
			//itsRandom = Math.floor(Math.random()*numberOfEntries);

			$("#thumb_3").click(function() {
				document.location.href= "/"+latest[inc][0]+".asp";
			});

			inn("t3_h2", latest[inc][1]);
			inn("t3_p", nl2br(latest[inc][2]+"\n\nKlicka för att läsa mer"));
			$("#thumb_3 p").fadeIn(400, function() {
				latestTimer = setTimeout(function() {
					getLatest(next_inc)
				}, delay*1000);
			});
		});
		
		
		
		$('#t3_p').addClass("transp_back");
		$('#t3_h2' ).addClass('thumb_noimage');
		
		$("#thumb_3").css("background-image", "url('img_new/"+latest[inc][3]+"')");
		$("#thumb_3").css("cursor", "pointer");
		
		
		
		
	}
	
	function hiliter(word, element) {
	    var rgxp = new RegExp(word, 'g');
	    var repl = '<span class="search_results">' + word + '</span>';
	
		$('#'+element).contents().each(function(){
		  if(this.nodeType === 3)
		     this.data = this.wholeText.replace(rgxp, repl);
		 });
	}
	
	
	
	function q(variable) { 
	  var query = window.location.search.substring(1); 
	  var vars = query.split("&"); 
		
	var returned = false;
	
	  for (var i=0;i<vars.length;i++) { 
	    var pair = vars[i].split("="); 
	    if (pair[0] == variable) { 
	      return pair[1]; 
	returned = true
	    }
	  } 
	   
		if (!returned) 
			return false
	
	}
	
	function searchLite() {
		
		var el = "maintext";
		
		var qu = q("hl");
		
		if (qu) {
			
			if (unescape(qu).indexOf(" ") == -1) 
				hiliter(qu, el);
			else {
				var ques = unescape(qu).split(" ");
				
				for (var i = 0; i < ques.length;i++) {
					hiliter(ques[i], el);
				}
				
			}
			
		}
		
	}
	
	function stopLatest() {
		
		try {
			clearTimeout(latestTimer);
		} catch(err) {
			latestTimerErr = "latestTimer not yet defined";
		}
		
	}
	
	//
	$("document").ready(function() {
	
			searchLite();
		
			timerBg = setTimeout(function() {
				topRotate(1);
			}, 7000);
			msgRotate(0);
		
			populateTop();
		
			$("#lector").css({
				"border-top-width":" 2px",
				"padding-left" : '5px',
				"background-color":" #ddd",
				"width" : "251px"
			});
			
			$("#side_menu h2").css({
				"font-size" : "12px"
			});
		
			//getLatest();
		
			//assign display none to all thumbs with onmouseover
			$(animatedThumbs).each(function() {
				$("#thumb_"+this+" p").css("display", "none");
			});	
		
			// } /initiators
		
		
		
			//function mouseoverevents() {
			var initMenu;		
			//#utb_menu animate
			$("#utb_menu").mouseover(function() {
			
			
				try {
					clearTimeout(initMenu);						
				} catch(err) { 
					custErr = "initMenu not yet defined\n - carry on";
				}
				initMenu = setTimeout( function() {
					$("#hidden_menu").fadeIn(400);
					$("#utb_menu").addClass("portalStay");
				}, 150);
			

			});

			$("#utb_menu").mouseout(function() {		
			
				try {
					clearTimeout(initMenu);						
				} catch(err) { 
					custErr = "initMenu not yet defined\n - carry on";
				}
			
				initMenu = setTimeout(function(){
					$("#hidden_menu").fadeOut(400);
					$("#utb_menu").removeClass("portalStay").addClass("portal");
				}, 300);

			});
		
			$("#hidden_menu").mouseover(function() {
			
			
				try {
					clearTimeout(initMenu);						
				} catch(err) { 
					custErr = "initMenu not yet defined\n - carry on";
				}

			});
		
			$("#hidden_menu").mouseout(function() {		

				initMenu = setTimeout(function(){
					$("#hidden_menu").fadeOut(400);
					$("#utb_menu").removeClass("portalStay").addClass("portal");
				}, 300);

			});
		
		
	
			//stop topRotate if mouseover
			$(".top_banner").mouseover(function() {
			
				
				try {
					clearTimeout(timerBg);
					clearTimeout(timerMsgOne);
					clearTimeout(timerMsgTwo);						
				} catch(err) { 
					custErr = "timers  not yet defined\n - carry on";
				}
				try {
					clearTimeout(stopper);						
				} catch(err) { 
					custErr = "stopper inactive\n - carry on";
				}
			
			});
		
			//resume topRotate
			$(".top_banner").mouseout(function() {		
			
				if (!continuer)
					stopper = setTimeout("topRotate(1)", 1500);
				else
				 	stopper = setTimeout("topRotate(continuer)", 1500);
			
			});
/*
			}
*/
		//function fallout() {
			
			
			fallout_positions_psyko = $("#fallout_psyko").position().top;
			fallout_positions_mindfulness = $("#fallout_mindfulness").position().top;
			if (document.location.pathname != "/" && document.location.pathname != "/default.asp") {
				fallout_positions_mindfulness += 10;
				fallout_positions_psyko += 10;
			}
			$("#fallout_menu_psyko").css("top", fallout_positions_psyko);
			$("#fallout_menu_mindfulness").css("top", fallout_positions_mindfulness);
			
			
			
			$("#fallout_psyko").hover(
				function() {
					try {
						clearTimeout(fallout_psyko_timer_out);
					} catch(err) {
						"fallout_psyko_timer_out not yet defined"
					}
					
					fallout_psyko_timer_in = setTimeout(function() {
						$("#fallout_menu_psyko").fadeIn('fast');
					}, 200);
					
					
				}, function() {
					try {
						clearTimeout(fallout_psyko_timer_in);
					} catch(err) {
						"fallout_psyko_timer_in not yet defined"
					}
					
					fallout_psyko_timer_out = setTimeout(function() {
						$("#fallout_menu_psyko").fadeOut('slow');
					}, 400);
				}
			);
			
			$("#fallout_menu_psyko").hover(
				function() {
					try {
						clearTimeout(fallout_psyko_timer_out);
					} catch(err) {
						"fallout_psyko_timer_out not yet defined"
					}
					
					
				}, function() {
					try {
						clearTimeout(fallout_psyko_timer_in);
					} catch(err) {
						"fallout_psyko_timer_in not yet defined"
					}
					
					fallout_psyko_timer_out = setTimeout(function() {
						$("#fallout_menu_psyko").fadeOut('slow');
					}, 500);
				}
			);

			$("#fallout_mindfulness").hover(
				function() {
					try {
						clearTimeout(fallout_mindfulness_timer_out);
					} catch(err) {
						"fallout_mindfulness_timer_out not yet defined"
					}
					
					fallout_mindfulness_timer_in = setTimeout(function() {
						$("#fallout_menu_mindfulness").fadeIn('fast');
					}, 200);
					
					
				}, function() {
					try {
						clearTimeout(fallout_mindfulness_timer_in);
					} catch(err) {
						"fallout_mindfulness_timer_in not yet defined"
					}
					
					fallout_mindfulness_timer_out = setTimeout(function() {
						$("#fallout_menu_mindfulness").fadeOut('slow');
					}, 400);
				}
			);
			
			$("#fallout_menu_mindfulness").hover(
				function() {
					try {
						clearTimeout(fallout_mindfulness_timer_out);
					} catch(err) {
						"fallout_mindfulness_timer_out not yet defined"
					}
					
					
				}, function() {
					try {
						clearTimeout(fallout_mindfulness_timer_in);
					} catch(err) {
						"fallout_mindfulness_timer_in not yet defined"
					}
					
					fallout_mindfulness_timer_out = setTimeout(function() {
						$("#fallout_menu_mindfulness").fadeOut('slow');
					}, 500);
				}
			);
			
/*			
		}
*/	
	
		
	});
	
	
