/*
Tuunix Oy, Copyright 2011
*/

/* PERUS OSIO GLOBAALIT */
var piiloaika;
piiloaika=1;
/*Tuotesivun popuppi */
function asetaaika(){piiloaika=1;}
function toggle_visibility(id) {
       var e = document.getElementById(id);
	   if(piiloaika)
	   {
	   piiloaika=0;
       if(e.style.display == 'block' || e.style.display =='')
          e.style.display = 'none';
       else
          e.style.display = 'block';
	   
	   setTimeout("asetaaika()",250);
	   }
    return false;
	}
function sendText(e, text) {   e.value = text }

function prospiilo(divname, piilo) /* kotitalousvählaskuri*/
{
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++)
{ 
if(divs[i].className==divname)
	{
	if(piilo)divs[i].style.display="none"; 
	else divs[i].style.display="block";
	}
}
}

$(window).bind("load", function() { 

var footerHeight = 90,
footerTop = 0,
$footer = $("#bottomfooter");

positionFooter();

function positionFooter() {

                footerHeight = $footer.height();
                footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
				
				//jos matala sivu
               // Ei tätä koska footeri ei abs, vaan static -- if ( ($(document.body).height()+footerHeight) < $(window).height()) {
               if ( ($(document.body).height()) < $(window).height()) {
                   
					if (!window.XMLHttpRequest) {
					//IE6- stuff;
					$footer.css({
						position: "absolute",
						left: "0px", 
						top: footerTop
						})
					return;
					}
				   
				   $footer.css({
                        position: "absolute",
						top: footerTop
                   })

               } else {
                   $footer.css({
                        position: "static"
                   })

               }

       }

       $(window)
               .scroll(positionFooter)
               .resize(positionFooter)



});



// wait for the DOM to be loaded 
$(document).ready(function() {

$('#imagecontainer').innerfade({
		speed: 1000,
		timeout: 7000,
		type: 'random_start',
		containerheight: '190px'
});


$('.innerref').hover(
  function () {
	//$(this).addClass("innerref2");
		$(this).find('img:first').stop();
	    $(this).find('img:first').animate({"margin-top": "-178px"}, "slow");
		//animate.css('margin-top', '-178px'); /* margin:-178px */
  },
   function () {
    //$(this).find('img:first').stop();
    $(this).find('img:first').animate({"margin-top": "0px"}, "fast");
	//animate.css('margin-top', '0px'); /* margin:-178px */
	//$(this).removeClass("innerref2");
	//$(this).css('right', '-5px');
  }

);



$('#textcontainer').find("td,p").each(function() 
{
NumOfLinks = $(this).children('a').size();
//alert (NumOfLinks);

if(NumOfLinks == 1)
	{
	//if($(this).children('a').hasClass('colorbox'))
	
	if($(this).children('a').is('.colorbox, .youtube, .iframe, .cboxElement'))
		{
		//alert('colobox found');
		return; // no colorbox
		}	
	if($(this).children('a').attr("target")=="_blank") 
		{
		//alert('blank found');
		return; // no colorbox
		}
	
	$(this).addClass("handcursor hoverbg"); 
	
	$(this).bind('click', (function()
		{	
		var towhere=$(this).find("a").attr("href");
		 window.location=towhere;
		 return;
		}));
	 }
});
//each


$(".textfield").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    });
    
    $(".textfield").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });
    
$(".textfield").blur();     

var textcontainerheight=$("#textcontainer").height();
//alert(textcontainerheight);
if(textcontainerheight < 430)
	{
	$("#textcontainer").height(430);
	}

	
$("img.lazyload").each(function()  // use title= instead of image href= and href=small image
{

if($(this).attr("title").length > 5) //no emptying
	{
	$(this).attr("src", $(this).attr("title"));
	$(this).removeAttr("title");
	}
});
	
$("#whitemiddle").find('a').each(function()  // automaattinen titletagi linkkeihin
{
if($(this).attr("target")=="_blank") 
	{
	if($(this).attr("title").length < 2)
		{
		$(this).attr("title", "Avautuu uudessa ikkunassa");
		}
	}
});
	
	

	
});
/* ready loppu */

