﻿function validateForm(fields, myform)
{
	var id = '';
	var errors = 0;
	var validate = fields.split(',');

	for(i = 0; i < validate.length; i++ )
	{
		id = validate[i];
		el = document.getElementById(id);
		
		/* Tarkistetaan tyhjät kentät*/
		if( el.value == '' ){
			el.style.border = 'solid 1px #d80000';
			errors++;
		}else{
			el.style.border = '';
		}
	}
	
	if(errors == 0)
	{
		document.forms[myform].submit();
	}
	else
	{
		document.getElementById('err').innerHTML = 'Täytä puuttuvat kentät!&nbsp;';
	}
}

function setValue(id, sourceId )
{
	document.getElementById(id).value = document.getElementById(sourceId).value
}

function GetXmlHttpObject() {
		var xmlhttp=null;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlhttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
					xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlhttp;
	}
	
function showAll() {
	$('#galleries').fadeIn(500, function () {});
	$('#selected_gallery').fadeOut(500, function () {});
}

function showGallery(id){
	document.getElementById('galiframe').src="gallery.php?galleryId="+id;
}

function getContent(site) {
	xmlhttp=GetXmlHttpObject();
	xmlhttp2=GetXmlHttpObject();
	if (xmlhttp==null || xmlhttp2==null ) {
		alert ("Selaimesi ei tue AJAXia!");
		return;
	}
	
	// Sivun keskiosan päivitys
	var url="context.php";
	url=url+"?content="+site;
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
		{
			document.getElementById('main_text').style.display="none";
			document.getElementById('main_text').innerHTML=xmlhttp.responseText;
			
			  // Attach slimbox to new content...
			  $('#main_text').find("a[rel^='lightbox']").slimbox({}, null, function(el) {
				   return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
				}); 
			$('#main_text').fadeIn(1500, function () {});
			loadSlideshow();
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

$(window).load(function() {
	$('#main_text').fadeIn(1500, function () {});
	 
	$('#slider').nivoSlider({
	effect:'boxRandom', // Specify sets like: 'fold,fade,sliceDown'
	pauseTime:3500, // How long each slide will show
	startSlide:0, // Set starting Slide (0 index)
	directionNav:false, // Next & Prev navigation
	directionNavHide:true, // Only show on hover
	controlNav:true, // 1,2,3... navigation
	controlNavThumbs:false, // Use thumbnails for Control Nav
	controlNavThumbsFromRel:false, // Use image rel for thumbs
	controlNavThumbsSearch: '.png', // Replace this with...
	controlNavThumbsReplace: '_thumb.png', // ...this in thumb Image src
	keyboardNav:true, // Use left & right arrows
	pauseOnHover:true, // Stop animation while hovering
	manualAdvance:false, // Force manual transitions
	captionOpacity:0.8, // Universal caption opacity
	prevText: 'Edellinen', // Prev directionNav text
	nextText: 'Seuraava', // Next directionNav text
	beforeChange: function(){}, // Triggers before a slide transition
	afterChange: function(){}, // Triggers after a slide transition
	slideshowEnd: function(){}, // Triggers after all slides have been shown
	lastSlide: function(){}, // Triggers when last slide is shown
	afterLoad: function(){} // Triggers when slider has loaded
	});		
});

function loadSlideshow(){
	var total = $('#slideshow img').length;
	var rand = Math.floor(Math.random()*total);
	 $('#slideshow').nivoSlider({
         effect:'sliceUpDownLeft',
		 pauseTime:4000, // How long each slide will show
		 startSlide:0, // Set starting Slide (0 index)
		 directionNav:false, // Next & Prev navigation
		 directionNavHide:true, // Only show on hover
		 controlNav:false, // 1,2,3... navigation
		 controlNavThumbs:false, // Use thumbnails for Control Nav
		 beforeChange: function(){}, // Triggers before a slide transition
		 afterChange: function(){}, // Triggers after a slide transition
		 slideshowEnd: function(){}, // Triggers after all slides have been shown
		 lastSlide: function(){}, // Triggers when last slide is shown
		 afterLoad: function(){} // Triggers when slider has loaded
		 
      });
}

function loadGallery() {
	 $('#galleryslides').spacegallery({loadingClass: 'loading'});
}


