function calcBackgroundPosition(obj, fix, obj2,split) {
	//alert(obj.length );
    if (obj.length != 0) {
        var height = obj.height();
        if(split) height = Math.round(height/2);
		//alert(height);
        var pos = obj.offset();
        //alert(pos.top+' '+height);
        var top = (height + Math.round(pos.top) + fix);
        obj2.css('height', top).show();
    }
}

function absolutize(obj, hfix, vfix, zind) {
    var pos = obj.offset();
    obj.css('position', 'absolute');
    obj.css('top', Math.round(pos.top + hfix) + 'px');
    obj.css('left', Math.round(pos.left + vfix) + 'px');
    obj.css('z-index', zind);
}

function calcBackgroundPositionNow() {
    calcBackgroundPosition($('#column_text p:first'), 10, $('#background2'));
    setTimeout("calcBackgroundPosition($('#column_text p:first'), 10, $('#background2'));", 50);
    calcBackgroundPosition($('#servContainer'), 80, $('#background3'));
    setTimeout("calcBackgroundPosition($('#servContainer'), 80, $('#background3'));", 50);        
}

$(document).ready(function() {
    // typekit
    try {
		Typekit.load({
			active: calcBackgroundPositionNow,
            inactive: calcBackgroundPositionNow
		});
	} catch(e) {}
    
    jQuery.fn.reverse = [].reverse;
        
    // BACKGROUND    
    if ($('#shadowright') != null && $('#shadowright').length != 0) {
        var width = 495;
        var xr = $(window).width() / 2 + width;
        var xl = $(window).width() / 2 - width - 213;
        var y = '308px'; // main page
        
        xr += 'px';
        xl += 'px';
        
        $('#shadowleft').css('left', xl).show();
        $('#shadowright').css('left', xr).show();
        
    }
    
    // NEWSLETTER
    $('.newsletteremail').focus(function() {
		ss.i18n.detectLocale();    	
    	// alert(ss.i18n._t('mysite.YOUREMAIL'));
    	//if ($(this).val() == 'Your email address') $(this).val('');
    	//if ($(this).val() == 'Sähköpostiosoitteesi') $(this).val('');
		if ($(this).val() == ss.i18n._t('mysite.YOUREMAIL')) $(this).val('');
    });
    
    $('.newsletteremail').blur(function() {
  		  ss.i18n.detectLocale();    	
        if ($(this).val() == '') $(this).val(ss.i18n._t('mysite.YOUREMAIL', 'Sähköpostiosoitteesi'));
    });

    $('#submitnewsletter').click(function(e) {
        $('#newsletter').hide();
        $('#wait').show();

    });
    
    // HILIGHT / HOVER
    /*
    $('.headeritem, .lang, .headercontent a').hover(function(){
        $(this).addClass("hilight");
    },function(){
        $(this).removeClass("hilight");
    });
    */
    $('.headermenuitem').hover(function(){
        $(this).addClass("white");
    },function(){
        $(this).removeClass("white");
    });
    
    $('.job').hover(function() {
        $(this).toggleClass('jobs_hover');
    },function() {
        $(this).toggleClass('jobs_hover');
    });
    
    $('.pressrelease').hover(function() {
        $(this).toggleClass('press_hover');
    },function() {
        $(this).toggleClass('press_hover');
    });
    
    $('.button').hover(function() {
        $(this).toggleClass('button_a');
    },function() {
        $(this).toggleClass('button_a');
    });
    
    // FOOTER CONTACT INFO
    /*$('.ContactBox:not(.open)').hover(function() {
            $(this).find('.ContactBoxContent').hide();
            $(this).find('.ContactBoxContentExpanded').show();
    },function() {
            $(this).find('.ContactBoxContent').show();
            $(this).find('.ContactBoxContentExpanded').hide();
    });*/
    $('.ContactBoxMiddle').click(function(){
        
        $(this).children('.ContactBoxContent').children('.ContactClosed').toggle();
        $(this).children('.ContactBoxContent').children('.additional').toggle();
        
         //calculate auto height
        var tmpH1 = $(this).children('.closed').height();
        $(this).children('.closed').css('height', 'auto');
        var tmpH2 = $(this).children('.closed').height();
        $(this).children('.closed').css('height', tmpH1+'px');

        $(this).children('div.closed').animate(
            {"height": tmpH2+"px"},
            {duration: "fast"},
            function(){
                $(this).children('div.closed').css('height', 'auto');
            });
    }/*,function(){
        var cur = 'dd';
        $(this).children('.closed').animate({'height': '23px'},{duration: "fast"});

        $(this).children('.ContactBoxContent').children('.ContactClosed').show();
        $(this).children('.ContactBoxContent').children('.additional').hide();
        
        
        
    }*/);
    
    // TWITTER
    /*$('.tweetbox_last').hover(function() {
        $(this).toggleClass('tweetbox_last_a');
    },function() {
        $(this).toggleClass('tweetbox_last_a');
    });
    $('.tweetbox').hover(function() {
        $(this).css('z-index: 99;');
        $(this).toggleClass('tweetbox_left_a');
    },function() {
        $(this).css('z-index: 0;');
        $(this).toggleClass('tweetbox_left_a');
    });
    $('.tweetboxr').hover(function() {
        $(this).css('z-index: 99;');
        $(this).toggleClass('tweetbox_right_a');
    },function() {
        $(this).css('z-index: 0;');
        $(this).toggleClass('tweetbox_right_a');
    });*/
    
    // DA BOX
    $('.navibox.1').hover(function() {
        var pos = $(this).offset();
        $('#infobox1').css('left', pos.left - 15);
        $('#infobox1').css('top', pos.top - 10);
        $('#infobox1').show(1, function(){
            $('#infobox1').children(".infobox_content").animate({"height": "toggle"}, {duration: "slow"});
        });
    },function() {
    });
    $('.navibox.2').hover(function() {
        var pos = $(this).offset();
        $('#infobox2').css('left', pos.left - 15);
        $('#infobox2').css('top', pos.top - 10);
        $('#infobox2').show(1, function(){
            $('#infobox2').children(".infobox_content").animate({"height": "toggle"}, {duration: "slow"});
        });
    },function() {
    });
    $('.navibox.3').hover(function() {
        var pos = $(this).offset();
        $('#infobox3').css('left', pos.left - 15);
        $('#infobox3').css('top', pos.top - 10);
        $('#infobox3').show(1, function(){
            $('#infobox3').children(".infobox_content").animate({"height": "toggle"}, {duration: "slow"});
        });
    },function() {
    });
    $('.navibox.4').hover(function() {
        var pos = $(this).offset();
        $('#infobox4').css('left', pos.left - 15);
        $('#infobox4').css('top', pos.top - 10);
        $('#infobox4').show(1, function(){
            $('#infobox4').children(".infobox_content").animate({"height": "toggle"}, {duration: "slow"});
        });
    },function() {
    });

    $('#infobox1').hover(function() {
    },function() {
        $('#infobox1').hide();
        $('#infobox1').children(".infobox_content").hide();
    });
    $('#infobox2').hover(function() {
    },function() {
        $('#infobox2').hide();
        $('#infobox2').children(".infobox_content").hide();
    });
    $('#infobox3').hover(function() {
    },function() {
        $('#infobox3').hide();
        $('#infobox3').children(".infobox_content").hide();
    });
    $('#infobox4').hover(function() {
    },function() {
        $('#infobox4').hide();
        $('#infobox4').children(".infobox_content").hide();
    });

    $('.customerbox').hover(function() {

	$(this).find('.off').hide();
	$(this).find('.on').show();

        $(this).find('.on').addClass('boxshadow_small');
        $(this).css('z-index', '99');
    },function() {

	$(this).find('.on').hide();
	$(this).find('.off').show();

	$(this).find('.on').removeClass('boxshadow_small');
        $(this).css('z-index', '0');
    });
});

