/*
No standard versions

Copyright Tuunix Oy, 2011
*/


var piiloaika;
piiloaika=1;

/*Tuotesivun popuppi */
function asetaaika(){
piiloaika=1;
}

/*Gallerian popuppi */
function galleriapop(sPicURL) { 
			gkuvapop=window.open("galleriapop.php?file="+sPicURL, "galleriapopname","resizable=1 toolbar=no, resizable=yes, scrollbars=yes, height=420,width=400, screenX=160,screenY=100,top=100,left=160");
			setTimeout("gkuvapop.focus()",1);
			return false;
			}

			
function popp() { 
			window.open("popup.php","title","resizable=1 toolbar=no, resizable=yes, scrollbars=yes, height=420,width=400, screenX=160,screenY=100,top=100,left=160");
			}

function ajpopup(sPicURL) { 
			window.open("ajkuva.php?file="+sPicURL, "", "resizable=1,height=250,width=250,screenX=150,screenY=100,top=100,left=150");
			}

/*Tuotesivun popuppi */
function tuotepopup(sPicURL) { 
			window.open("tkuva.php?file="+sPicURL, "","resizable=1 toolbar=no, resizable=yes, scrollbars=yes, height=420,width=400, screenX=160,screenY=100,top=100,left=160");
			}


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 
}


navani_status=0;
function navanioff()
	{
	navani_status=0; //if 0 do animation, if 1 do NOT
	//alert(navani_status);
	}



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





$('#nav li').hover( 
        function () { 
            //show its submenu 
			if(!navani_status)  
			{
			navani_status=1;
            $('ul', this).slideDown(100); 
			setTimeout("navanioff()",150);
			}
			else
				{
				setTimeout("navanioff()",90);
				}
  
        },  
        function () { 
            //hide its submenu 
			//$('ul', this).slideUp(100);
							
				$('ul', this).delay(200).slideUp(100);
				//setTimeout("navanioff()",150);
				
			
        } 
    ); 

if(typeof document.body.style.maxHeight === "undefined" ||  (navigator.userAgent.indexOf('Android') != -1)  ) {
        //alert('ie6'); //android
$('#slogan').css("display", "block");	   
$('#slogan').css("font-size", "16px");
$('#slogan').css("width", "auto");
}
else 
{
$('#slogan').delay(1500).fadeIn(500, function() {
        // Animation complete
			
// =	$('#slogan').show();
});

}


var newwidth;
newwidth=$(window).width(); 
if(newwidth > 1400 )
	{
	$('body').addClass("iso");
	}
else
	{
	$('body').addClass("pieni");
	}


var newheight;
newheight=$(window).height(); 
if(newheight < 800 )
	{
	//alert(newheight);
	$('#logopalkki').css("margin-top", "10px");
	$('#content').css("margin-top", "5px");
	$('#nav').css("margin-bottom", "5px");
	}
	
$('a.colorboxi').colorbox();

$(".picturelink a").attr("rel", "cslide");	

if($("[rel='csingle'], [rel='cfade'], [rel='cslide'], .colorbox, .youtube, .iframe").length)
{   
	
	$('#tekstialuepadding').find('.colorbox').each(function() 
		{
		//find a and add it's child img title to a title
		var imgtitle=$(this).find("img").attr("title");
		
		if(imgtitle=='' || imgtitle==null) //if img has no title, get alt
			{
			imgtitle=$(this).find("img").attr("alt");
			}
		
		if($(this).attr("title") == '')
			{
			$(this).attr("title", imgtitle);
			}
		});
		
	$(".colorbox").colorbox({
		maxWidth:"1200px",
		maxHeight:"850px",
		opacity: "0.7"                                 
		});
		
	$(".iframe").colorbox({
		width:"90%",
		height:"90%",
		iframe:true
		});
}



var colorboxohje=0;
	

var imageurlcolorbox;
var alkuteksticolorbox="<span class=\"firsttimehelp\">Avaa seuraava kuva klikaamalla kuvaa</span><br />\n";


$("a[rel='gallerybox']").colorbox({
href: function(){
var urlphp=$(this).attr('href'); //index.php?si=kuvat&tkuva=dsc06324_koira.jpg&nro=20#alas

urlphp = urlphp.split('='); //dsc06324_koira.jpg&nro
urlphp = urlphp[2].split('#'); //dsc06324_koira.jpg&nro=20

urlphp = urlphp[0].split('&'); //dsc06324_koira.jpg


urlphp[0]='galleria/img/'+urlphp[0];
//alert (urlphp[0]);
imageurlcolorbox=urlphp[0];
return urlphp[0];
}
,title: function(){
	//var url = $(this).attr('href');
	var nameurl = $(this).attr("title");
	if (colorboxohje<1)
		{
		nameurl = alkuteksticolorbox+nameurl;
		colorboxohje=1;
		}
	return nameurl+'<br /><a href="'+imageurlcolorbox+'" target="_blank" title="Avaa kuva uudessa ikkunassa" class="smallimglink">Linkki tähän kuvaan..</a>';
}
});









});
//ready loppu
