﻿		var sboxclicked = false;
		var sboxaliasclicked = false;

		function addConcepts(uri, label, url) {
		    label = label.replace(/%20/gi, " ");
		    label = label.replace(/%28/gi, "(");
		    label = label.replace(/%29/gi, ")");
		    label = label.replace(/%E4/gi, "ä");
		    label = label.replace(/%C4/gi, "Ä");
		    label = label.replace(/%F6/gi, "ö");
		    label = label.replace(/%D6/gi, "Ö");
		    label = label.replace(/%E5/gi, "å");
		    label = label.replace(/%C5/gi, "Å");

		    var inputFlds = document.getElementsByTagName('input');
		    for (var i = 0; i < inputFlds.length; i++) {
		        oInput = inputFlds[i];
		        if ((oInput.title == "Onki-asiasanat") || (oInput.title == "Onki Keywords")) {
		            var onkiFld = oInput;
		            if (onkiFld.value != "")
		            { onkiFld.value = onkiFld.value + ", " + label; }
		            else onkiFld.value = label;
		            return onkiFld;
		        }
		    }
		}

		function goHilight(keyword) {
		    $('ul.sitemap a').unhighlight();
		    $('ul.sitemap a').highlight(keyword);
		}

		//sivukartan haitarointi alkaa
		
		function accordion() {
		    var _d = 400;
		    var _holderClass = $('ul.accordion');
		    _holderClass.each(function () {
		        var _this = $(this);
		        var _el = $('li', _this);
		        var _opener = $('em', _this);
		        //laitetaan arvo active kaikille joilla on alinodeja ja arvo nochildren niille joilla ei ole
		        _el.each(function () {
		            if ($(this).find('li').size() > 0) {
		                $(this).addClass('active');
		            }
		            else $(this).addClass('nochildren');
		        });
		        _opener.click(function () {
		            var _link = $(this);
		            var _cur = _link.parent(); //_cur = nykyinen klikattu li jonka sisällä opener on
		            // jos on nochidren, ei tehdä klikissä mitään
		            if (!_cur.hasClass('nochildren')) {
		                //jos on auki eli active eli miinus niin suljetaan	
		                if (_cur.hasClass('active')) {
		                    _cur.removeClass('active');
		                    _cur.find('li').addClass('active');
		                    _cur.find('div:eq(0)').animate({ height: 0 }, _d, function () {
		                        _cur.find('div').css({ height: 0 });
		                    });
		                }

		                // ei ole auki eli ei active eli plus, avataan
		                else {
		                    var _slide = _cur.find('div:eq(0)');
		                    var _h = _slide.css('height', 'auto').height();
		                    _slide.css({ height: 0 });
		                    _cur.addClass('active');
		                    _cur.find('li').removeClass('active');
		                    _slide.animate({ height: _h }, _d, function () {
		                        $(this).css({ height: 'auto' });
		                    });
		                }
		            }
		            else // tällä ei ole lapsia
		            {
		                return;
		            }
		        });
		    });
		}
		
		//sivukartan haitarointi loppui

      function ChangeLocalUnitsContactLink() {
        var pathname = window.location.pathname;
		var pathnameArr = pathname.split('/');

		if(pathnameArr.length<3){
			return;
		}

		var lang = pathnameArr[1].toUpperCase();
		var site = pathnameArr[2].toUpperCase();
		var newlink = "";
		
		if(site=="TIKKURILA" || site=="HYVINKAA" || site=="LEPPAVAARA" || site=="OTANIEMI" || site=="KERAVA" || site=="PORVOO" || site=="LOHJA"){
			if(lang=="FI"){
				newlink="/fi/"+ pathnameArr[2] +"/Sivut/yhteystiedot.aspx";
			}
			else if(lang=="EN"){
				newlink="/en/"+ pathnameArr[2] +"/Contacts/Pages/default.aspx";
			}
		}

		if(newlink==""){
			return;
		}

		$('#yellowlinks a').each(function (index) {
			if ($(this).attr("class")=="contact") {
				$(this).attr("href",newlink);
			  
			}
		});

      }

		$(document).ready(function () {
			
		    accordion();
		
		    $('#contentarea a').has('img').addClass("nobg");
		    $('#column3 a').has('img').addClass("nobg");
		
	
			
			$('input[name="queryfield"]').wrap('<div class="sitemapsearchouter">').wrap('<div class="searchfieldbg">').css("border", "0px");
			
  		    $('#level3navi').has('.icm_level_4').css('display','block');

		    $('#fontsizer').jfontsizer({
		        applyTo: '#site',
		        changesmall: '1',
		        changelarge: '2',
		        expire: 30
		    });


		    $("#localunits").hover(
			  function () {
			      $(this).animate({ "height": "224px" }, {
			          duration: 1
			      });
			      $("#localunits h2").addClass("hover");
			  },
			  function () {
			      $(this).animate({ "height": "26px" });
			      $("#localunits h2").removeClass("hover");
			  }
			);

		    $("#shortcuts").hover(
			  function () {
			      $(this).animate({ "height": "100%" }, {
			          duration: 1
			      });

			  },
			  function () {
			      $(this).animate({ "height": "24px" });
			  }
			);



		    // imagewebpartin aktivointi
		    $(".ImageWebPart").colorbox({
		        onComplete: function () { $(".ImageWebPart").colorbox(); }
		    });
		    // palautelomakkeen aktivointi
		    //$(".feedback").colorbox({
		    //    onComplete: function () { $(".feedback").colorbox(); }
		    //});

		    // kenttien tekstien tyhjennys
		    $("#shoutbox-text").click(function () {
		        if (sboxclicked == false) { $("#shoutbox-text").val(""); } sboxclicked = true;
		    });
		    $("#shoutbox-alias").click(function () {
		        if (sboxaliasclicked == false) { $("#shoutbox-alias").val(""); } sboxaliasclicked = true;
		    });

		    ChangeLocalUnitsContactLink();
		}); 
	

			// set palsta2 same height as palsta3 (vertical line fix at sisältösivu)
		$(window).load(function() {
			
		  var palsta3height = $('#column3').height();
		  var palsta2height = $('#column2').height();
		  if (palsta3height > palsta2height)
		  {
			 $('#column2').css('height', palsta3height + 'px');
			 $('#column2-inner').css('height', palsta3height + 'px');
		  }
		
		var counter = 0;
		$('#shoutbox-text').keypress(function() {
		counter++;  		
  		$(".shoutbox-form div.counter").text(160-counter);
		});
		
		});
		
			
		

		function showFeedbackForm() {
		var options = 
		{ url: SP.Utilities.Utility.getLayoutsPageUrl('feedback/feedback.aspx?a='), width: 880, height: 685, title: '', 		allowMaximize: false, showClose: true };
		SP.UI.ModalDialog.showModalDialog(options); 	
		}
	
function showTrainingSearchForm() {
          var options = 
          { url: "/fi/opiskelu/Sivut/koulutushaku.aspx", width: 750, height:500, title: '', allowMaximize: false, showClose: true };
          SP.UI.ModalDialog.showModalDialog(options);                     
          }     	
