
/* toggle test 
window.addEvent('domready', function() {
	var mySlide = new Fx.Slide('content');

	$('toggle').addEvent('click', function(e){
		e = new Event(e);
		mySlide.toggle();
		e.stop();
	});
});
*/

function really_empty(element) {
	element.value = '';
	element.onclick = null;
}


/* groups (innovatiiviset toteutukset) */

window.addEvent('domready', function(){

    
    
	$$('.groupContent').setStyle('display', 'block');
	
	var selected = $('groupSelected');

	var current = (selected) ? selected.getParent() : false;
	
	$$('div.group').each(function(div){
		
		var link = div.getElement('a');
		var block = link.getNext();
		
		
		
		var fx = new Fx.Slide(block);
		
		
		//nappaa ankkuri urlista
		var anchor=location.hash;
		if ("#"+link.name != anchor) {
			if (block != current) fx.hide();
		}
		
		link.addEvent('click', function(){
			fx.toggle();
			// Tähän löytyy varmasti fiksumpi tapa! -Jaana
			// pitäs vain lisätä class="open", ei vaihtaa kokonaan
			// lisäksi olis kiva jos suljettaessa vaihtais vasta oncomplete
			if(link.className == "groupHeader") {
				link.className = "groupHeaderOpen";
			}
			else {
				link.className = "groupHeader";
			}
		});
		
	});
	
	/*
	$$('.groupContent').each(function(){
	
	  alert(this.id);
		
	});*/
	/*
	$$('.CTitle').each(function(heading){
		new Element('a', {
			'href': '#mainTopic',
			'class': 'toTop'
		}).setHTML('top').injectBefore(heading.getFirst());
	});*/
	
	new SmoothScroll();
	
});

document.write('<style type="text/css" media="screen">div.groupContent{display: none}</style>');


var mySlide = null;

/* Ajax (cases) */

window.addEvent('domready', function(){

    //hae galleriakuvan sijainti nimestä
    
    function getImagePosition(url) {
    
    var imgSize = url.split("_");
		var imgSize2 = imgSize[3].split(".");
		
		topPos = imgSize[2];
		leftPos = imgSize2[0];
		
    }
    
    function makeMouseover(a) {
    
         $$(a).addEvent('mouseenter', function() {
   
		  //aseta hover
    	  $(this.id).setStyle('background-color',"orange"); 
    	  $(this.id).setStyle('color',"#000");
       
        
          $(this.id).addEvent('mouseleave', function() {
        
        	//pistä  linkki perustyyleille
    		$(this.id).setStyle('background-color',"#000"); 
    		$(this.id).setStyle('color',"#fff");
       
        	});
        
          });
    
    }
    
    // vaihda kuvaa
		  
	function changeImage(image) {
		  
		  var changePic = new Fx.Style('dragger', 'opacity', {duration:300});
 
		  changePic.start(1,0).chain(function(){
    	  
    	  $('dragger').setHTML("<img class='galleryPic' name='galleryPic' src='" + image + "'/>");
    	  getImagePosition(image);
		  $('dragger').setStyle('top',"-" + topPos + "px");
		  $('dragger').setStyle('left',"-" + leftPos + "px"); 
		  
    	  changePic.start(0,0.1);
    	   
		  }).chain(function(){
		  
		  changePic.start(0.1,1);
 		  		  
		  });		  
		  
		  }
		  
    function showImage(image) {
		  
		  var changePic = new Fx.Style('dragger', 'opacity', {duration:200});
 
		  changePic.start(0,0).chain(function(){
    	  
    	  $('dragger').setHTML("<img class='galleryPic' name='galleryPic' src='" + image + "'/>");
    	  getImagePosition(image);
		  $('dragger').setStyle('top',"-" + topPos + "px");
		  $('dragger').setStyle('left',"-" + leftPos + "px"); 
		  
    	  changePic.start(0,0.1);
    	   
		  }).chain(function(){
		  
		  changePic.start(0.1,1);
 		  		  
		  });		  
		  
		  }
    
    function makeMouseonclick(a, clicked) {

		$(clicked).removeEvents('mouseleave');
		$(clicked).removeEvents('mouseenter');
		
		//pistä kaikki linkit perustyyleille
    	$$(a).setStyle('background-color',"#000"); 
    	$$(a).setStyle('color',"#fff");
    
		//aseta klikattu linkin tyylit
    	$(clicked).setStyle('background-color',"#87cc2d"); 
    	$(clicked).setStyle('color',"#000");
    	}

    function makeCase() {
    
		$('dragger').setStyle("opacity", "0");
    	window.scrollTo(0,0);
    	
        
        
        var str = document["galleryPic"].src.toString();
        showImage(str);
       
        new Drag.Move('dragger');
        
               
        makeMouseover('.changePic');
        
       
        
       		
		$$('.changePic').addEvent('click', function(e) {
		
		  e = new Event(e).stop();
		
		  makeMouseover('.changePic');
		
		  makeMouseonclick('.changePic', this.id);
		  
		  var str = this.toString();
		  
		  changeImage(str);
		  
		  
		  
		
		  mySlide.slideIn();
		
		
				

		});

		//---
        
    	var showCase = new Fx.Style('case', 'opacity', {duration:1000});
		showCase.start(1);
		
				
		var closeCase = $('closeCase');
   
    	if(closeCase != null) {	
    	
    	$('closeCase').addEvent('click', function() {
		mySlide.slideOut();
		
		var hideGallery = new Fx.Style('picContainer', 'opacity', {duration:500});
		hideGallery.start(0);
		
		//$$('.picContainer').setStyle('display','none');
		});
		
		

		//tee seuraava  - edellinen nappuloiden toiminnallisuus
		
		$$('.nextCase').addEvent('click', function(e) {
		
		  e = new Event(e).stop();
		  var url = "/cases/case.php?pID=" + this; 
          
          
		  new Ajax(url, {
			method: 'get',
			update: $('caseContainer'),
			onComplete: makeCase
		  }).request();

        });
        
        }
	
    }
    
    // rakenna case

    

    var caseContainer = $('caseContainer');
    
    
    if((caseContainer != null)) {
		mySlide = new Fx.Slide('caseContainer');
		
		//urlissa case => avaa
		if ($('case')) {
		makeCase();
		}
		else
	    mySlide.hide();
	    
	    caseContainer.setStyle('height','550px');
	}

		
	$$('.openCase').addEvent('click', function(e) {
		
		e = new Event(e).stop();
		var url = "/cases/case.php?pID=" + this; 
		 

		new Ajax(url, {
			method: 'get',
			update: $('caseContainer'),
			onComplete: makeCase
		}).request();
		
		mySlide.slideIn();

	});
	


	
	
});
/*
function sendSignupForm(form, message) {
	if(form.nimi.value == '' || form.yritys.value == '') {
		alert(message);
		return;
	}
	
	$(form).send({ onComplete: function() {
		$(form).style.display = 'none';
		$('signupThanks').style.display = 'block';
	} });
}
*/

// Contact Form
var contactForm = null;
var cSlide = null;

function sendContactForm(formelement, message) {
	if(formelement.nimi.value == '' || formelement.puh.value == '' || formelement.email.value == '') {
		alert(message);
		return;
	}
	
	$(formelement).send({ onComplete: function() {
		$('cthx').setHTML(this.response.text).style.display = 'block';
		$('cfrm').style.display = 'none';
		
		if(cSlide != null)
			setTimeout('cSlide.slideOut()', 3000);
	} });

}

function showContactForm(firstname, personID) {
	$$('.toContact').setHTML(firstname);

	if(contactForm != null)
		contactForm.getElementById('contactRecipient').value = personID;
		
	$('cthx').style.display = 'none';
	$('cfrm').style.display = 'block';
	cSlide.slideIn();
}

window.addEvent('domready', function(){

	contactForm = $('contactForm');
    
    if((contactForm != null)) {
    	contactForm.style.display = 'block';
		cSlide = new Fx.Slide(contactForm);
		cSlide.hide();
	}
	
	$$('.closeContact').addEvent('click', function() {
		cSlide.slideOut();
	});
	
/*
	
	$$('.contactLink').addEvent('click', function(e) {
		
		  e = new Event(e).stop();
		  
		  var str = this.toString();
		  
		  var to = this.hash.split("#");
		  
		   $$('.toContact').setHTML(to[1]);
		  
		
		  cSlide.slideIn();
		  
		  

		});
*/	
	
});




/**
 * Etusivun navi oletuksena piilossa, 
 * tulee näkyviin really-logoa klikkaamalla
 */

var navShown = false;
function toggleNav()
{
	// slider is created in the domready function below
	if (false === navShown) {
		try {
			nSlide.slideIn();
		} catch( e ) {
			return false;
		}	
		navShown = true;
	} else {
		nSlide.slideOut();
		navShown = false;
	}
	
	return false;
}

window.addEvent('domready', function(){

	// the div around navTop
	indexNav = $('indexNavTop');
	
	// create the slider and hide it
    if((indexNav != null)) {
    	indexNav.style.display = 'block';
		nSlide = new Fx.Slide(indexNav);
		nSlide.hide();
	}

});
