// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,clear,count,debug,dir,dirxml,error,exception,firebug,group,groupCollapsed,groupEnd,info,log,memoryProfile,memoryProfileEnd,profile,profileEnd,table,time,timeEnd,timeStamp,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


var etusivunVaihtoInt;
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});


mainSliderPause = false;
var _d = {};

if($.browser.msie) {
var ie = $.browser.version;
} else {
var ie = false;
}

function urlencode(s) {
	return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}
   
function urldecode(s) {
	return decodeURIComponent( s.replace( /\+/g, '%20' ).replace( /\%21/g, '!' ).replace( /\%27/g, "'" ).replace( /\%28/g, '(' ).replace( /\%29/g, ')' ).replace( /\%2A/g, '*' ).replace( /\%7E/g, '~' ) );
}

function popupper(theurl,winname,features) {
	if (!features) {
		features = "toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no,height=600, width=800";
	}
        
	msgWindow = window.open(theurl,winname,features);
	if(msgWindow != null && msgWindow.opener != null) msgWindow.opener=window;
	msgWindow.focus();
}

function popDic() {
	URL = "/terminology";
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=550');");
}

function checkfields() {
	var check = true;
	$('input.required, textarea.required').each(function(i, el) {
		if($(el).hasClass('required-email')) { 
                      var val = $(el).attr('value');
			pattern = /^([a-zA-ZáéíóäëiöúàèììùüÜÁÉÍÓÄËIÖÚÀÈÌÌÙ0-9_.-]){2,32}@(([a-zA-Z0-9-]){2,32}.)+([a-zA-Z0-9]{2,4})+$/;
                        if(pattern.test(val) && val.length > 0) {
			     $(el).removeClass('field_notify');
		        }
		}

		var val = $(el).attr('value');

		if(val.length > 0) {
			$(el).removeClass('field_notify');
		} else {
			$(el).addClass('field_notify');
			check = false;
		}
	});

	return check;
}

function etusivunVaihto() {
	if($('#slidepreviews li.active').hasClass('last')) {
		$('#slidepreviews li:eq(0) .holder').trigger('click');
	} else {
		$('#slidepreviews li.active').next('li').children('.holder').trigger('click');
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"").replace(/^\n+|\n+$/g,"").replace(/^\r+|\r+$/g,"").replace(/^\t+|\t+$/g,"");
}
var suffix = '';
$(document).ready(function() {




/* remove empty tag clouds */

if($.trim($("#subpage-tagcloud").text()) == "") {
  $("#subpage-tagcloud").remove();
}


jQuery.easing.def = "easeOutQuad";

/* hidden field population for software download form */


$('#software').live('submit', function(){
    var text = '';
    var fillField = $('#download-names');
    var ele = $(this);

    fillField.attr('value', '');
    ele.find('input:checked').each(function(index) {
         text += $(this).attr('data-software-id') +', ';
    });
    fillField.attr('value', text);
});

/* set location suffix variable from html data */

	if(typeof $('html').attr('data-local') != 'undefined') {
		suffix = $('html').attr('data-local');
	}

	$('.product-popover .contact_sales').live('click', function() {
		$('#contact-accordion, #ask_peikko-accordion').trigger('click');
		var scrollTo = $('#contact-accordion').parents('.accordion').offset();
		$('html, body').animate({
			scrollTop : (scrollTo.top-10)
		},500);
	});

	$('.subpage-product-greenbox a').each(function(i, el) {
		var ah = (55-Math.floor($(this).height()))/2;
		$(el).css({
			'padding-top' : ah,
			'padding-bottom' : ah
		});
	});
	
	$('#search-link').live('click', function() {
		$('#header-search form').trigger('submit');
	});

	$('#header-search-field').blur(function() {
		$('#search-preview').fadeOut(250, function() {
			$('#search-preview').detach();
		});
	});

	$('#header-search-field').focus(function() {
		$(this).trigger('keyup');
	});


	$('#header-search-field').keyup(function(e) {
		var v = trim($(this).attr('value'));
		if(v.length>0) {
			$.ajax({
				url : '/search-preview' + suffix,
				data : 'search=' + v,
				cache: false,
				success: function(html){
					$('#search-preview').detach();
					if($(html).find('li').length>1) {
						$("#header-search").append(html);
						$('#header-search li:eq(0)').addClass('first');
						$('#header-search li:eq(' + ($('#header-search li').length-1) + ')').addClass('last');
						Cufon.refresh();
					}
				}
			});
		}
	});

	$('#search-preview li:not(.title)').live('mouseenter', function() {
		$(this).addClass('hover');
	});
	$('#search-preview li:not(.title)').live('mouseleave', function() {
		$(this).removeClass('hover');
	});

	$('#collection_pages .attachments input').live('change', function() {
		var pid = $(this).parents('.collection_page').attr('data-id');
		var id = readCookie('collectionID');
		var content = '';
		$(this).parents('.collection_page').find('.attachments input:checked').each(function(i, el) {
			content += $(el).attr('value') + '\n';
		});
		$.ajax({
			url : '/collection-maker-attachments',
			type : 'post',
			data : 'cm_action=set&id=' + id + '&pid=' + pid + '&attachments=' + urlencode(content),
			dataType : 'html',
			success : function(html) {

			}
		});
	});

	$('#clear_collection').click(function(e) {
		e.preventDefault();
		$('#collection_pages .remove').each(function(i, el) {
			$(el).trigger('click');
		});
	});

	$('.collection_page .remove').live('click', function(e) {
		e.preventDefault();
		var that = $(this);
		var pid = $(this).parents('.collection_page').attr('data-id');
		var id = readCookie('collectionID');
		$.ajax({
			type: "POST",
			url: "/collection-maker-db/collection-maker-remove",
			data: 'id=' + id + '&pid=' + pid + '&cm_action=removePage',
			success: function(data){
				if(data == 'OK') {
					$(that).parents('.collection_page').fadeOut(100, function(){
						$(that).parents('.collection_page').remove();
						$('.moveUp:eq(0)').hide();
						$('.moveDown:eq(' + ($('.moveDown').length-1) + ')').hide();
					});
					$.ajax({
						url: "/collection-maker" +suffix,
						cache: false,
						success: function(html){
							$("#subpage-collector").replaceWith(html);

							$('#collection-share').colorbox({
                                                                    iframe:true, 
                                                                    innerWidth:500, 
                                                                    innerHeight:450
                                                                 });
							
							Cufon.refresh();
						}
					});
				}
			}
		});
	});

	$('.moveDown').live('click', function(e) {
		e.preventDefault();
		var that = $(this).parents('.collection_page');
		var next = $(that).next('.collection_page');
		var copy = $(that).clone();
		var incpid = $(that).attr('data-id');
		var decpid = $(next).attr('data-id');
		$.ajax({
			type: "POST",
			url: "/ajax-sort-collection",
			data: "cm_action=colinc&inc=" + incpid + "&dec=" + decpid + "&uid=" + uid
		});
		$(that).detach();
		$(next).after(copy);
		$(next).next('.collection_page').find('h2').html($(next).next('.collection_page').find('h2').attr('data-name'));
		$('.moveDown').show();
		$('.moveUp').show();
		$('.moveDown:eq(' + ($('.moveDown').length-1) + ')').hide();
		$('.moveUp:eq(0)').hide();
		Cufon.refresh();
	});

	$('.moveUp').live('click', function(e) {
		e.preventDefault();
		var that = $(this).parents('.collection_page');
		var copy = $(that).clone();
		var prev = $(that).prev('.collection_page');
		var decpid = $(that).attr('data-id');
		var incpid = $(prev).attr('data-id');
		$.ajax({
			type: "POST",
			url: "/ajax-sort-collection",
			data: "cm_action=colinc&inc=" + incpid + "&dec=" + decpid + "&uid=" + uid
		});
		$(that).detach();
		$(prev).before(copy);
		$(prev).prev('.collection_page').find('h2').html($(prev).prev('.collection_page').find('h2').attr('data-name'));
		$('.moveDown').show();
		$('.moveUp').show();
		$('.moveDown:eq(' + ($('.moveDown').length-1) + ')').hide();
		$('.moveUp:eq(0)').hide();
		Cufon.refresh();
	});

	var col_unique = readCookie('collectionID');
	var col_id = $('#col_id').attr('value');
        var collectionAjaxUrl = '/collection-maker';
        if(suffix != undefined) {
             collectionAjaxUrl = '/collection-maker' +suffix;
        }
	$('#collect').live('click', function(e) {
		e.preventDefault();
		
		if($(this).hasClass('add')) {
			$.ajax({
				type: "POST",
				url: "/collection-maker-db",
				data: 'unique=' + col_unique + '&col_id=' + col_id,
				success: function(data){
					$.ajax({
						url: collectionAjaxUrl +"?opid=" + col_id + "&p=true",
						cache: false,
						success: function(html){
							$("#subpage-collector").replaceWith(html);
                                                 //       var ajaxCollectionUrl = $('#collection-share').attr('href');
						//	$.colorbox({href:ajaxCollectionUrl,iframe:true, innerWidth:500, innerHeight:450});
							Cufon.refresh();
						}
					});
				}
			});
		} else {
			$.ajax({
				type: "POST",
				url: "/collection-maker-db/collection-maker-remove",
				data: 'cm_action=removePage&id=' + col_unique + '&pid=' + col_id,
				success: function(data){
					$.ajax({
						url: collectionAjaxUrl +"?opid=" + col_id + "&p=true",
						cache: false,
						success: function(html){
							$("#subpage-collector").replaceWith(html);
//							$('#collection-share').colorbox({iframe:true, innerWidth:500, innerHeight:450});
							Cufon.refresh();
						}
					});
				}
			});
		}
		
	});

	$('#collection-share').live('click', function(e) {
		e.preventDefault();
                var ajaxCollectionUrl = $('#collection-share').attr('href');
		$.colorbox({href: ajaxCollectionUrl, iframe:true, innerWidth:500, innerHeight:450});
	});

	$('#main-solutions-list li a').mouseenter(function() {
		$('#main-solutions-list li a').css('background', 'rgb(228,228,228)');
		$('#main-solutions-list li a').css('color', 'rgb(0,0,0) !important');
		$('#main-solutions-list li.active').removeClass('active');

		$(this).css('background', 'rgb(156,189,29)');
		$(this).css('color', 'rgb(255,255,255) !important');
		$(this).parent('li').addClass('active');

		var top = $(this).parent('li').attr('offsetTop');
		var plus = ($(this).height() / 2);

		$('#main-solutions-showcase-arrow').stop().css({
			'top' : (top + plus - 10)
		}, 200);

		var rel = $(this).attr('rel');

		$('#main-solutions-showcase .active').hide().removeClass('active');
		$('#main-solutions-showcase .rel' + rel).show().addClass('active');
	});

	$('#main-solutions-list li:not(.active) a').live('mouseleave', function() {
		$(this).css('background', 'rgb(228,228,228)');
		$(this).css('color', 'rgb(0,0,0)');
	});

	$('#subpage-left-navi > ul > li:not(.active) a').mouseenter(function() {
		$(this).css('background', 'rgb(156,189,29)');
		$(this).css('color', 'rgb(255,255,255)');
	});

	$('#subpage-left-navi > ul > li:not(.active) a').mouseleave(function() {
		$(this).css('background', 'rgb(228,228,228)');
		$(this).css('color', 'rgb(0,0,0)');
	});

	$('#right .arrow').click(function() {
		$(this).toggleClass('active');
		$(this).parent('div').toggleClass('open');
		$(this).nextAll('.toggle').stop().slideToggle(200);
		var opens = new Array();
		$('.open').each(function(i, el) {
			opens[i] = $(el).attr('id');
		});
		if(opens=='') {
			opens = 'none';
		}
		createCookie('opens',opens,0);
	});

	$('#right .exp').click(function() {
		if($(this).hasClass('passive')) {
			$(this).addClass('exp-open');
		} else {
			$(this).removeClass('exp-open');
		}
		var opens = '';
		$('.exp-open').each(function(i, el) {
			opens = opens + ',' + $(el).attr('rel');
		});
		createCookie('opens2',opens,0);
	});

	$('#right h2').click(function() {
		$(this).parent('div').next('.arrow').trigger('click');
	});

	$('#right h2').click(function() {
		$(this).parent('div').parent('div').next('.arrow').trigger('click');
	});

	$('.accordion h4').click(function() {
		$(this).children('.bigarrow').toggleClass('bigactive');
		$(this).next('.toggle').stop().slideToggle(200);
		if($(this).parent('.accordion').hasClass('googlemaps')&&googlemapsdone==false) {
			initialize();
			codeAddress($(this).parent('.accordion').find('.addr').attr('rel'));
		}
	});



/* open accordion by id if hash is set on url */

if($('.accordion-contact').length > 0 && window.location.hash) {
    var ele = $(window.location.hash);
       
    if(ele.length > 0) {
        ele.find('h4').trigger('click');
     };
}
	$('#gallery-smalls ul:eq(0)').addClass('first');
	$('#gallery-smalls ul:eq(' + ($('#gallery-smalls ul').length-1) + ')').addClass('last');
	$('#gallery-browser-next').click(function(e) {
		e.preventDefault();
		var curul = $('#gallery-smalls ul.cur');
		if($(curul).hasClass('last')) {
			$('#gallery-smalls-browser').fadeTo(100, 0.5);
			$('#gallery-smalls-browser').fadeTo(100, 1);
		} else {
			$(curul).next('ul').addClass('cur').end().removeClass('cur');
			$('#gallery-smalls-browser').animate({
				'left' : ($('#gallery-smalls-browser').attr('offsetLeft') - $('#gallery-smalls ul:eq(0)').width()) + 'px'
			}, 400);
			if($('#gallery-smalls ul.cur').hasClass('last')) {
				$('#gallery-browser-next').fadeTo(100, 0.5);
			} else {
				$('#gallery-browser-next').fadeTo(100, 1);
			}

		}
		$('#gallery-browser-prev').fadeTo(100, 1);
	});
	$('#gallery-browser-prev').click(function(e) {
		e.preventDefault();
		var curul = $('#gallery-smalls ul.cur');
		if($(curul).hasClass('first')) {
			$('#gallery-smalls-browser').fadeTo(100, 0.5);
			$('#gallery-smalls-browser').fadeTo(100, 1);
		} else {
			$(curul).prev('ul').addClass('cur').end().removeClass('cur');
			$('#gallery-smalls-browser').animate({
				'left' : ($('#gallery-smalls-browser').attr('offsetLeft') + $('#gallery-smalls ul:eq(0)').width()) + 'px'
			}, 400);
			if($('#gallery-smalls ul.cur').hasClass('first')) {
				$('#gallery-browser-prev').fadeTo(100, 0.5);
			} else {
				$('#gallery-browser-prev').fadeTo(100, 1);
			}

		}
		$('#gallery-browser-next').fadeTo(100, 1);
	});

	if($('#gallery-smalls').length>0) {
		$('#gallery-browser-prev').fadeTo(100, 0.5);
		if($('#gallery-smalls ul').length==1) {
			$('#gallery-browser-prev').fadeTo(100, 0.5).unbind('click');
			$('#gallery-browser-next').fadeTo(100, 0.5).unbind('click');
		}
		$('#gallery-smalls li > a:eq(0)').trigger('click');
	}

	$("#gallery-image").colorbox();

	$('#gallery-smalls img').mouseenter(function() {
		$(this).stop().fadeTo(100, 0.7);
	});
	$('#gallery-smalls img').mouseleave(function() {
		$(this).stop().fadeTo(100, 1);
	});
	$('#gallery-smalls li > a').click(function(e) {
		e.preventDefault();
		var large = $(this).children('.gallery-link-large').html();
		var medium = $(this).children('.gallery-link-medium').html();
		if($(this).attr('rel')=='image') {
			$('#gallery-bigpicture').html('<div style="display:none"><img src="' + large + '" id="gallery-bigpicture-img" /></div><a href="#" id="gallery-image"><img src="' + medium + '" /></a>');
			$("#gallery-image").colorbox({inline:true, href:'#gallery-bigpicture-img'});
		} else if($(this).attr('rel')=='video') {
			var ref = $(this).attr('href');
			$('#gallery-bigpicture').html('<a href="" id="gallery-video"></a>');
			$('#gallery-video').attr('href', ref);
			flowplayer('gallery-video', {src: '/files/peikko/swf/flowplayer-3.2.3.swf', wmode: 'transparent'}, {clip:{autoPlay:false,autoBuffering:true,bufferLength:3}});
		} else {
			var ref = $(this).attr('href');
			$('#gallery-bigpicture').html('<object id="gallery-video" width="328" height="193"><param name="movie" value="' + ref + '"><embed src="' + ref + '" width="328" height="193"></embed></object>');
		}
	});

	$('#gallery-smalls li:eq(0) > a').trigger('click');

	$('.subpage-product-greenbox > p > a').mouseenter(function() {
		var that = $(this).parent('p').parent('.subpage-product-greenbox');
		var popleft = (Math.floor($(that).attr('offsetLeft') - 15)*-1);
		if(ie&&ie<8) {
			var poptop = (Math.floor(242-$(that).parent('.floatl').attr('offsetTop'))*-1);
		} else {
			var poptop = (Math.floor(242-$(that).parent('.floatl').attr('offsetTop')+5)*-1);
		}
		var arrleft = Math.floor($(that).parent('.floatl').attr('offsetLeft') + 46);
		$(that).find('.product-popover').css({'top': poptop});
		$(that).find('.product-popover-arrow').css('left', arrleft);
		$(that).find('.product-popover').show();
	});
	$('.subpage-product-greenbox').mouseleave(function() {
		var rel = $(this).children('p').children('a').attr('rel');
		$(this).find('.product-popover').hide();
	});

	$('#siteselect').change(function() {
		var url = $(this).val();
		window.location = url;
	});

	$('#subpage-bignews li').mouseenter(function() {
		$('.newsbg-top', this).show();
		$('.newsbg-btm', this).show();
		$(this).children('.newsbody').css('background', 'url(/files/peikko/img/newsbg.png) repeat-y');
		if($(this).index()!=0) {
			//$(this).css('border', '0px');
			//$(this).css('margin-top', '1px');
		}
		//$(this).next('li').css('border', '0px');
		//$(this).next('li').css('margin-top', '1px');
	});

	$('#subpage-bignews li').mouseleave(function() {
		$('.newsbg-top', this).hide();
		$('.newsbg-btm', this).hide();
		$(this).children('.newsbody').css('background', '');
		if($(this).index()!=0) {
			//$(this).css('border-top', '1px solid rgb(203,203,203)');
			//$(this).css('margin-top', '0px');
		}
		//$(this).next('li').css('border-top', '1px solid rgb(203,203,203)');
		//$(this).next('li').css('margin-top', '0px');
	});

	
	if($('.accordion').length!=0 && !window.location.hash) {
		$('.accordion:visible:eq(0):not(.force-closed) h4').trigger('click');
	}

	$('#right-expertise li > a').click(function() {
		var rel = $(this).attr('rel');
		$(this).toggleClass('passive');
		$('#right-expertise .rel-' + rel).slideToggle();
	});

	$('.content-title').each(function(i, el) {
		titlew = 134*$('#items-holder .' + $(el).attr('id')).length;
		titlew < 200 ? titlew = 200 : titlew = titlew;
		if($('#items-holder .' + $(el).attr('id')).length==1) {
			$('#items-holder .' + $(el).attr('id')).css('width', titlew + 'px');
		}
		$(el).css('width', titlew + 'px');
		var titlew = 0;
	});

	$('.solutions-item').mouseenter(function() {
		$(this).children('.solutions-item-hover').show();
		var h = 50-($(this).find('a').height()/2);
		$(this).find('a').css('padding-top', h + 'px');
	});

	$('.solutions-item').mouseleave(function() {
		$(this).children('.solutions-item-hover').hide();
	});

	$('#scroll-right').click(function() {
		if($('#titles-holder .active')!=$('.content-title:eq(' + ($('.content-title').length-1) + ')')) {
			$('#titles-holder .active').next('.content-title').trigger('click');
		}
	});

	$('#scroll-left').click(function() {
		if($('#titles-holder .active')!=$('.content-title:eq(0)')) {
			$('#titles-holder .active').prev('.content-title').trigger('click');
		}
	});

	$('#solutions-inside-count span').html('1 / ' + $('.content-title').length);
if($('#scrollbar').length) {
	_d.handle = document.getElementById('scrollbar');
	_d.scrolla = document.getElementById('titles-holder');
	_d.scrollb = document.getElementById('items-holder');
	_d.handleW = $('#scrollbar').width();
	_d.scrollbar = $('#scrollbar-holder').offset();
	_d.l = _d.scrollbar.left;
	_d.maxHandleLeft = $('#scrollbar-holder').width()-$('#scrollbar').width(); // Handlen suurin mahdollinen left
	_d.totalW = 0;
	_d.spots = [];
	$('.solutions-item').each(function(i, el) {
		_d.totalW = _d.totalW+$(el).width();
	});
	$('.content-title').each(function(i, el) {
		_d.spots.push($(el).attr('offsetLeft'));
	});
	_d.totalW = _d.totalW-$('#scrollbar-holder').width();
	_d.itemW = $('.solutions-item:eq(0)').width();
	_d.itemHalfW = Math.floor(_d.itemW/2);
	_d.p = 0;
	_d.active = 0;
	$('#scrollbar').mousedown(function(e) {
		e.preventDefault();
		$(document).bind('mousemove', function(e) {
			e.preventDefault();
			$(_d.scrollb).stop();
			$(_d.scrolla).stop();
			$(_d.handle).stop();

			_d.x = (e.pageX-_d.l)-(_d.handleW/2);
			_d.x < 0 ? _d.x = 0 : _d.x = _d.x;
			_d.x > _d.maxHandleLeft ? _d.x = _d.maxHandleLeft : _d.x = _d.x;
			_d.handle.style.left = _d.x + 'px';
			_d.p = (_d.x / _d.maxHandleLeft);
			_d.sl = _d.totalW * _d.p;
			_d.scrolla.style.left = '-' + _d.sl + 'px';
			_d.scrollb.style.left = '-' + _d.sl + 'px';
			if(!ie) {
				for(i=0,l=_d.spots.length;i<l;i++) {
					if((_d.spots[i] > Math.floor(_d.sl-(_d.itemW+_d.itemHalfW))) && (_d.spots[i] < Math.floor(_d.sl+(_d.itemW+_d.itemHalfW)))) {
						_d.active = i;
					}
				}
				$('.content-title').removeClass('active');
				$('.content-title:eq(' + _d.active + ')').addClass('active');
				$('#solutions-inside-count span').html($('.content-title:eq(' + _d.active + ')').index()+1 + ' / ' + $('.content-title').length);
			}
		});
		$(document).bind('mouseup', function(e) {
			$(document).unbind('mousemove');
			if(ie) {
				for(i=0,l=_d.spots.length;i<l;i++) {
					if((_d.spots[i] > Math.floor(_d.sl-(_d.itemW+_d.itemHalfW))) && (_d.spots[i] < Math.floor(_d.sl+(_d.itemW+_d.itemHalfW)))) {
						_d.active = i;
					}
				}
				$('.content-title').removeClass('active');
				$('.content-title:eq(' + _d.active + ')').addClass('active');
				$('#solutions-inside-count span').html($('.content-title:eq(' + _d.active + ')').index()+1 + ' / ' + $('.content-title').length);
			}
		});
	});

	$('.content-title').click(function(e) {
		e.preventDefault();
		$('.content-title').removeClass('active');
		$(this).addClass('active');
		$('#solutions-inside-count span').html($(this).index()+1 + ' / ' + $('.content-title').length);

		_d.p = ($(this).attr('offsetLeft')/_d.totalW);
		_d.p < 0 ? _d.p = 0 : _d.p = _d.p;
		_d.p > 1 ? _d.p = 1 : _d.p = _d.p;
		_d.sl = (_d.totalW * _d.p);
		_d.x = _d.maxHandleLeft * _d.p;
		_d.x < 0 ? _d.x = 0 : _d.x = _d.x;
		_d.x > _d.maxHandleLeft ? _d.x = _d.maxHandleLeft : _d.x = _d.x;

		$(_d.scrolla).stop().animate({
			'left' : '-' + _d.sl + 'px'
		}, {duration: 1000, easing : 'easeOutExpo'});
		$(_d.scrollb).stop().animate({
			'left' : '-' + _d.sl + 'px'
		}, {duration: 1000, easing : 'easeOutExpo'});
		$(_d.handle).stop().animate({
			'left' : _d.x + 'px'
		}, {duration: 1000, easing : 'easeOutExpo'});
	});
}//excluded slider stuff from scrollbar
	$('#slidepreviews li .holder').append('<div class="top"></div><div class="bottom"></div><div class="left"></div><div class="right"></div>');

	$('#slides li:eq(0)').addClass('active');
	$('#slidepreviews li:eq(0)').addClass('active');
	$('#slidepreviews li:eq(' + ($('#slidepreviews li').length-1) + ')').addClass('last');

	var dur = 1000;
	function moveSlides(dir, index) {
		clearTimeout(etusivunVaihtoInt);
		etusivunVaihtoInt = setTimeout(function() { etusivunVaihto(); }, 8000);
		if(typeof index !== 'number') {
			var index = $('#slidepreviews li.active').index();
			if(dir == 'left') {
				index > 0 ? index = index-1 : index = $('#slidepreviews li').length-1;
			} else {
				index < ($('#slidepreviews li').length-1) ? index = index+1 : index = 0;
			}
		}
		var left = $('#slides li:eq(' + index + ')').attr('offsetLeft');

		$('#slidepreviews li.active .holder div').hide();
		$('#slidepreviews li.active').removeClass('active')
		$('#slidepreviews li:eq(' + index + ')').addClass('active');
		$('#slidepreviews li.active .holder div').show();
	
		$('#slides').stop().animate({
			'left' : left*-1
		}, {duration: dur, easing : 'easeOutExpo'});
		mainSliderPause = true;
	}
//} why was slider stuff inside scrollbar-if?
$('#main-slides-left').click(function() {
	moveSlides('left');
});

$('#main-slides-right').click(function() {
	moveSlides('right');
});

$('#slidepreviews li:not(.active) .holder').live('click', function() {
	var index = $(this).parent('li').index();
	moveSlides('none', index);
});

$('#slidepreviews li .holder').live('mouseenter', function() {
	$(this).children('div').show();
if(ie) {
	$(this).children('.top').stop().css({
		'top' : '0px'
	}, 200);
	$(this).children('.bottom').stop().css({
		'top' : '56px'
	}, 200);
	$(this).children('.left').stop().css({
		'left' : '0px'
	}, 200);
	$(this).children('.right').stop().css({
		'right' : '0px'
	}, 200);
} else {
	$(this).children('.top').stop().animate({
		'top' : '0px'
	}, 200);
	$(this).children('.bottom').stop().animate({
		'top' : '56px'
	}, 200);
	$(this).children('.left').stop().animate({
		'left' : '0px'
	}, 200);
	$(this).children('.right').stop().animate({
		'right' : '0px'
	}, 200);
}
});

$('#slidepreviews li:not(.active) .holder').live('mouseleave', function() {
	$(this).children('div').hide();
if(! ie) {
	$(this).children('.top').stop().animate({
		'top' : '-5px'
	}, 200, function() { $(this).attr('style', '') });
	$(this).children('.bottom').stop().animate({
		'top' : '61px'
	}, 200, function() { $(this).attr('style', '') });
	$(this).children('.left').stop().animate({
		'left' : '-5px'
	}, 200, function() { $(this).attr('style', '') });
	$(this).children('.right').stop().animate({
		'right' : '-5px'
	}, 200, function() { $(this).attr('style', '') });
}
});

$('#main-top-content').mouseenter(function() {
	clearTimeout(etusivunVaihtoInt);
});

$('#main-top-content').mouseleave(function() {
	etusivunVaihtoInt = setTimeout(function() { etusivunVaihto(); }, 8000);
});

etusivunVaihtoInt = setTimeout(function() { etusivunVaihto(); }, 8000);

var cookie = readCookie('opens');
if(cookie!=null) {
	var cookie = cookie.split(',');
	if(cookie.length>0) {
		for(i=0;i<cookie.length;i++) {
			if($('#' + cookie[i]).hasClass('open')) { } else {
				$('#' + cookie[i]).addClass('open');
				$('#' + cookie[i]).find('.arrow').addClass('active');
				$('#' + cookie[i]).find('.toggle').show();
			}
		}
	}
} else {
	$('#right-products,#right-news,#right-events').addClass('open');
	$('#right-products,#right-news,#right-events').find('.arrow').addClass('active');
	$('#right-products,#right-news,#right-events').find('.toggle').show();
	createCookie('opens','right-products,right-news,right-events',7);
}
var opens2 = readCookie('opens2');
if(opens2!=null) {
	var opens2 = opens2.split(',');
	if(opens2.length>0) {
		for(i=0,l=opens2.length;i<l;i++) {
			$('#right .rel-' + opens2[i]).show();
			$('#right .exp[rel="' + opens2[i] + '"]').removeClass('passive').addClass('exp-open');
		}
	}
}

	$('a.colorbox-img').click(function(e) {
		e.preventDefault();
var link = $(this).attr('rel');
		$(this).colorbox({inline:true, href:'#' + link});
	});

	$('.content-title strong').each(function(i, el) {
		if($(el).height()=='24') {
			w = $(el).width();
			id = $(el).parent('.content-title').attr('id');
			$(el).css('width', w*2);
			$(el).parent('.content-title').css('width', $(el).parent('.content-title').width()+w);
			$('#items-holder .' + id + ':eq(' + ($('#items-holder .' + id).length-1) + ')').css('width', $('#items-holder .' + id + ':eq(' + ($('#items-holder .' + id).length-1) + ')').width()+w);
		}
	});

	var maxSize = 0;
	$('.solutions-item').each(function(i, el) {
		maxSize = maxSize+$(el).width();
	});
	maxSize = maxSize-968;

});

if(navigator.userAgent.toLowerCase().search('symbian') == -1) {
Cufon.replace('#slides li h2', { fontFamily: 'eurostar', color: '-linear-gradient(rgb(255,255,255), rgb(215,215,215))', textShadow: '#666666 0px 1px' });
Cufon.replace('#main-solutions-header h2', { fontFamily: 'eurostar' });
Cufon.replace('#search-preview li.title', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center h1', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center h2', { fontFamily: 'eurostar' });
//Cufon.replace('#subpage-center h3', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center h4', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center h5', { fontFamily: 'eurostar' });
Cufon.replace('#solutions-inside-title', { fontFamily: 'eurostar' });
Cufon.replace('#right-expertise h2, #right-products h2, #right-solutions h2, #right-news h2, #right-events h2', { fontFamily: 'eurostar' });
Cufon.replace('#main-newsletter h3', { fontFamily: 'helvetica-lt' });
Cufon.replace('#main-newsletter #main-newsletter-date', { fontFamily: 'helvetica-lt' });
Cufon.replace('#main-newsletter #main-bottom-share h3', { fontFamily: 'helvetica-lt' });
Cufon.replace('#main-newsletter #main-newsletter-link span', { fontFamily: 'helvetica-lt' });

Cufon.replace('#main-newsletter #main-blog p span', { fontFamily: 'helvetica-lt' });
Cufon.replace('#main-tagcloud p', { fontFamily: 'helvetica-lt' });

Cufon.replace('#solutions-inside h2', { fontFamily: 'eurostar' });
Cufon.replace('#solutions-inside li a', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-header h2', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-expertise-navi h2', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-products-navi h2', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-solutions-navi h2', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-news h2, #subpage-events h2', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-newsletter h3', { fontFamily: 'helvetica-lt' });
Cufon.replace('#subpage-collector h3', { fontFamily: 'helvetica-lt' });
Cufon.replace('#subpage-center-gallery > p, #subpage-center-gallery > a, #subpage-center-gallery > p, #gallery-smalls p, #gallery-text, #gallery-title', { fontFamily: 'helvetica-lt' });
Cufon.replace('.accordion h4, .dummyaccordion h4', { fontFamily: 'helvetica-lt' });
Cufon.replace('.popover-title', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center-gallery h3, #subpage-center-gallery strong, #subpage-center-gallery h4, #subpage-center-gallery h5', { fontFamily: 'eurostar' });
Cufon.replace('#subpage-center-gallery #gallery-title h3', { fontFamily: 'helvetica-lt' });
}



$(document).ready(function() {
	$('a[href]').each(function() {
		if($(this).attr('href').indexOf('/materials/extloader') != -1 && $(this).text().match(/\S/)) {
			$(this).mousedown(function() {
				snoobi.trackPageView('/media/articles/pdf/'+$(this).text()); 
			});
		}
	});

	$('img[src^="file:"]').each(function() {
	     var currentSrc = $(this).attr('src').split('#', 2);
             $(this).attr('src', currentSrc[1]);
	});
	$('a[href^="file:"]').each(function() {
	     var currentSrc = $(this).attr('href').split('#', 2);
             $(this).attr('href', currentSrc[1]);
	});

    $("table.tblstyle1 tbody tr:nth-child(odd)").addClass("odd");

});
