﻿/* ------ Jook ------ */
function JoookToolkit(){this.isDefined=function(testVar){if(typeof(testVar)!='undefined'){return true}else{return false}};this.addEvent=function(obj,evType,fn){if(obj.addEventListener){obj.addEventListener(evType,fn,false);return true}else if(obj.attachEvent){var r=obj.attachEvent("on"+evType,fn);return r}else{return false}};this.select=function(selector,parent){var parentEmt=document;var retval=new Array();if(this.isDefined(parent)){parentEmt=parent}if(this.isDefined(selector)&&selector!=''){var selectors=selector.split(",");for(var i=0;i<selectors.length;i++){var currentSelector=selectors[i].replace(/\s/,'');var selectionMode=-1;if(currentSelector.indexOf("#")==0){selectionMode=0}else if(currentSelector.indexOf(".")==0){selectionMode=1}else if(currentSelector.indexOf("*")==-1){selectionMode=2}else{selectionMode=3}switch(selectionMode){case 0:var emtId=currentSelector.substr(1);if(parentEmt.getElementById(emtId)&&parentEmt.getElementById(emtId)!=null)retval.push(parentEmt.getElementById(emtId));break;case 1:var children=parentEmt.childNodes;var matchingNodes=new Array();for(var j=0;j<children.length;j++){var classnames=children[j].className.split(" ");for(var k=0;k<classnames.length;k++){if(classnames[k]==currentSelector.substr(1)){retval.push(children[j]);break}}}break;case 2:var children=parentEmt.getElementsByTagName(currentSelector);for(var j=0;j<children.length;j++){retval.push(children[j])}break;case 3:var children=parentEmt.childNodes;for(var j=0;j<children.length;j++){retval.push(children[j])}break}}}return retval};this.getDimensions=function(obj){return{width:obj.offsetWidth,height:obj.offsetHeight}};this.getPosition=function(obj){var curleft=curtop=0;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop}}return{left:curleft,top:curtop}};this.setOpacity=function(obj,opa){var styleObj=obj.style;styleObj.opacity=(opa/100);styleObj.MozOpacity=(opa/100);styleObj.KhtmlOpacity=(opa/100);styleObj.filter="alpha(opacity="+opa+")"};this.replaceClass=function(obj,class1,class2){var classes=obj.className.split(" ");for(var i=0;i<classes.length;i++){if(classes[i]==class1){classes[i]=class2}}obj.className=classes.join(" ")}};function LazyComponent(){this.loaded=false;this.element=null;this.parentEmt=null;this.createCSSEmt=function(fileUrl){this.element=document.createElement("link");this.element.rel="stylesheet";this.element.type="text/css";this.element.href=fileUrl};this.createJSEmt=function(fileUrl){this.element=document.createElement("script");this.element.type="text/javascript";this.element.src=fileUrl};this.load=function(targetEmt,fileUrl,optionsObj){this.parentEmt=targetEmt;var emtType=1;var jtk=new JoookToolkit();if(jtk.isDefined(optionsObj)){if(jtk.isDefined(optionsObj.isCSS)&&optionsObj.isCSS==true){emtType=2}}if(emtType==2){this.createCSSEmt(fileUrl)}else{this.createJSEmt(fileUrl)}targetEmt.appendChild(this.element);this.loaded=true;if(jtk.isDefined(optionsObj)){if(jtk.isDefined(optionsObj.callBack)){optionsObj.callBack.call()}}};this.getElement=function(){return this.element};this.remove=function(){if(this.element!=null&&this.loaded==true){this.loaded=false;return this.parentEmt.removeChild(this.element)}else{return false}};this.replace=function(newUrl,optionsObj){if(this.element.nodeName=="link"){this.element.href=newUrl}else{this.element.src=newUrl}var jtk=new JoookToolkit();if(jtk.isDefined(optionsObj)&&jtk.isDefined(optionsObj.callBack)){optionsObj.callBack.call()}}};function JTKDelegate(){}JTKDelegate._defaultArgNum=2;JTKDelegate.create=function(obj,func){var argArr=new Array();for(var i=JTKDelegate._defaultArgNum;i<arguments.length;i++){argArr[i-JTKDelegate._defaultArgNum]=arguments[i]}return function(){func.apply(obj,argArr)}};
/* ------ Superfish ------ */
;(function($){$.fn.superfish=function(op){var sf=$.fn.superfish,c=sf.c,$arrow=$(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),over=function(){var $$=$(this),menu=getMenu($$);clearTimeout(menu.sfTimer);$$.showSuperfishUl().siblings().hideSuperfishUl()},out=function(){var $$=$(this),menu=getMenu($$),o=sf.op;clearTimeout(menu.sfTimer);menu.sfTimer=setTimeout(function(){o.retainPath=($.inArray($$[0],o.$path)>-1);$$.hideSuperfishUl();if(o.$path.length&&$$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path)}},o.delay)},getMenu=function($menu){var menu=$menu.parents(['ul.',c.menuClass,':first'].join(''))[0];sf.op=sf.o[menu.serial];return menu},addArrow=function($a){$a.addClass(c.anchorClass).append($arrow.clone())};return this.each(function(){var s=this.serial=sf.o.length;var o=$.extend({},sf.defaults,op);o.$path=$('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){$(this).addClass([o.hoverClass,c.bcClass].join(' ')).filter('li:has(ul)').removeClass(o.pathClass)});sf.o[s]=sf.op=o;$('li:has(ul)',this)[($.fn.hoverIntent&&!o.disableHI)?'hoverIntent':'hover'](over,out).each(function(){if(o.autoArrows)addArrow($('>a:first-child',this))}).not('.'+c.bcClass).hideSuperfishUl();var $a=$('a',this);$a.each(function(i){var $li=$a.eq(i).parents('li');$a.eq(i).focus(function(){over.call($li)}).blur(function(){out.call($li)})});o.onInit.call(this)}).each(function(){var menuClasses=[c.menuClass];if(sf.op.dropShadows&&!($.browser.msie&&$.browser.version<7))menuClasses.push(c.shadowClass);$(this).addClass(menuClasses.join(' '))})};var sf=$.fn.superfish;sf.o=[];sf.op={};sf.IE7fix=function(){var o=sf.op;if($.browser.msie&&$.browser.version>6&&o.dropShadows&&o.animation.opacity!=undefined)this.toggleClass(sf.c.shadowClass+'-off')};sf.c={bcClass:'sf-breadcrumb',menuClass:'sf-js-enabled',anchorClass:'sf-with-ul',arrowClass:'sf-sub-indicator',shadowClass:'sf-shadow'};sf.defaults={hoverClass:'sfHover',pathClass:'overideThisToUse',pathLevels:1,delay:800,animation:{opacity:'show'},speed:'normal',autoArrows:true,dropShadows:true,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};$.fn.extend({hideSuperfishUl:function(){var o=sf.op,not=(o.retainPath===true)?o.$path:'';o.retainPath=false;var $ul=$(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass).find('>ul').hide().css('visibility','hidden');o.onHide.call($ul);return this},showSuperfishUl:function(){var o=sf.op,sh=sf.c.shadowClass+'-off',$ul=this.addClass(o.hoverClass).find('>ul:hidden').css('visibility','visible');sf.IE7fix.call($ul);o.onBeforeShow.call($ul);$ul.animate(o.animation,o.speed,function(){sf.IE7fix.call($ul);o.onShow.call($ul)});return this}})})(jQuery);
/* ------ HoverIntent ------ */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode}catch(e){p=this}}if(p==this){return false}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.mouseover(handleHover).mouseout(handleHover)}})(jQuery);

/* ------ Jqueries ------ */

$(function() {

	/* ------ Remove pie if zoom != 1 ------ */
  
  if (oldie) {
      function removeBehavior() {
          if((screen.deviceXDPI / screen.logicalXDPI) != '1') {
              $("*").each(function(){
              $(this).css("behavior", "none");
          });
        }
      }
    removeBehavior();
    window.onresize = removeBehavior;
  }

	/* ------ Remove deprecated <font> elements ------ */
	/*
	var fontInner = $('font').text();
	$('font').replaceWith(fontInner);
	*/

	/* ------ Age menu ------ */

	$('#age_menu li').hover(
		function() {
			var tid = '#'+$(this).attr('id')+'_h';
			if (!oldie) $('#age_mouseover').stop().fadeTo(100, 1);
			else $('#age_mouseover').show();
			$(tid).show().siblings().hide();
		}
	);
	
	$('#age_container').mouseleave(function() {
		if (!oldie) $('#age_mouseover').stop().fadeTo(100, 0);
		else $('#age_mouseover').hide();
	});
	
	/* ------ Main menu ------ */
	
	$('.sf-menu li li:last-child > a').addClass('last');
	$('.sf-menu li li ul li:last-child > a').removeClass('last');
	$('.sf-menu li').last().children('a').addClass('s');
	$('.sf-menu li').last().prev().children('a').addClass('s');
	$('.sf-menu li').last().prev().prev().children('a').addClass('s');
	
	/* ------ "FormFader" ------ */
	
	function formFader(el) {
		$(el).focus(function() {
			$(this).val(($(this).val() == $(this)[0].title)?"":$(this).val());
		});

		$(el).blur(function() {
			$(this).val(($(this).val() == "")?$(this)[0].title:$(this).val());
		}); 	$(el).blur();
	}
	
	/* ------ Applying "FormFader" ------ */
	
	formFader('#submit_email'); 

	/* ------ Front Box Height ------ */
	
	var boxHeight = 0;
	
	$('.front_box').each(function() {
		if ($(this).height() > boxHeight) boxHeight = $(this).height();
	});	
	if (ie7) boxHeight += 30;
	$('.front_box').css('height', boxHeight+32+'px');
	
	/* ------ Left Menu ------ */
	$('.sub-sub-menu').each(function() {
	if($(this).children().length < 1) $(this).addClass('hidden');
	});
	/* ------ Product tables ------ */
	
	$('.u4-table-productinfo').first().each(function() {
		$(this).find('tr').first().each(function() {
			$(this).children().each(function() {
				$(this).css('background', '#ffffff');
			});
		});
	});
	
	$('.product_info_2 br').remove();


	/* ------ Add classes to form elements ------ */
	
	$('input:radio').addClass('radio');
	$('input:submit').addClass('submit');
	
	/* ------ Main banner z-index correction ------ */
	
		var mainImg = $('#main_banner_img img');
		var mainImgSrc = 'url('+mainImg.attr('src')+') no-repeat'
		$(mainImg).remove(); 
		$('#main_banner_img').css('background', mainImgSrc);
	
	/* ------ Submit button IE correction ------ */
	
	$('.navigo-poll .submit').wrap('<div id="input_wrapper"/>');
	
	
	/* ------ Pie ------ */
	
	$('.sf-menu li a, .sf-menu ul, .sf-menu ul li ul, .sf-menu li ul li:last-child, .sf-menu li li ul li:last-child, .sf-menu li li a, .navigo-poll #input_wrapper').addClass('pie');
	$('.sf-menu li ul li ul li, .sf-menu li ul li ul li a').removeClass('pie');
	
	if (ie7) $('#food_journey_info_box').removeClass('pie');
	
	/* ------ Google +1 Button ------*/
	
	window.___gcfg = {lang: 'fi'};
	(function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
	
});



