
/**
 * Datei : fsz_main.js
 * Autor : Hans Hamm
 * Datum : 20.11.2006 
 */

var vAnimal = new Array("hund", "katze", "katze2", "maus", "maus2");
var vDirection = new Array("left", "right");
var vBalloon = new Array("blase01", "blase02", "blase03", "blase04", "blase05", "blase06", "blase07", "blase08", 
	"blase09", "blase10", "blase11", "blase12", "blase13");
var vBalloonDir = new Array("rechts", "links");
var vBalloonLink = new Array("95", "100", "99", "101", "101", "102", "105", "107", "108", "109", "", "111", "110")
var vVersion = new Array("01", "02");
var srcPath = "grafiken/tiere/";
var basisPath = "";

/**********************
 * HELPER FUNCTIONS
 **********************/
 
 // random integer value between a and b 
function rndi(a, b)
{
	return parseInt (Math.random()* ( b-a )+ a, 10);
}

// preload an image to prevent flickering
var gPreLoadedImages=new Array();
function preLoadImage(fileName)
{
  if (!gPreLoadedImages[fileName])
  {
    var img = new Image();
    img.src = fileName;    
    gPreLoadedImages[fileName]= img;    
  }
}

/**********************
 * ANIMALS
 **********************/ 
// animate animal 
function changeAnimalPicture(i, v, d, a, space)
{
	var id = "headerPictures_"+i;
	if (v == 0)
	{
		v = 1;
	}	
	else{
		v = 0;
	}
	var img = generateAnimalImage(i, v, d, a, space);
	
	try
	{		
		$(id).innerHTML = img;
	}catch(e){alert(e);}
}

// generate random animal images
function generateRandomImages()
{	
	var text = "";
	var nrOfAnimals = 25;	
	var i;
	var old_a;
	var old_d;
	var old_v;
	var space;

	for (i=0; i<nrOfAnimals; ++i)
	{
		var a = rndi(0,vAnimal.length);
		var d = rndi(0,vDirection.length);
		var v = rndi(0,vVersion.length);
		var balloon="";
			
		if (d != old_d)
		{
			if (d == 0) //   old->[space]<-current
			{
				space= rndi(0,10);
			}
			else //  pleft old <-[space]-> current pright
			{
				space= 64;
			}
		}
		else
		{
			space = 128 - 85; //85: Breite der Sprechblase
			var ballSpace=space;
			if (d = 0) { // Linke Blase
				ballSpace=0;
			} else {
				space=0;
			}
			text += "<span id='balloonImg_"+i+"'>";
			text += generateRandomBalloon(d, ballSpace);
			text += "</span>";
		}
		old_d = d;
		old_a = a;
		old_v = v;
		var id = "headerPictures_"+i;
		text += "<span id='"+id+"'>";
		text +=generateAnimalImage(i, v, d, a, space);
		text += "</span>";
	}
	try{
		$("headerPictures").innerHTML = text;	
	} catch (e){} 	
}

// generates an animal image from v = version, d=direction, a=animal, space=leftspace
function generateAnimalImage(i, v, d, a, space)
{
	var img = basisPath + srcPath + vDirection[d] + "_" + vVersion[v] + "_" + vAnimal[a] + ".gif";	
	
	var style = "margin-left:"+space+"px; margin-right:"+0+"px;";			
	
	var link = 'javascript:changeAnimalPicture('+i +', '+ v +', '+ d +', '+ a +', '+space+')';
	var text = "";
	
	text += "<a onFocus='this.blur();' href='"+link+"'>";
	text += "<img style='"+ style +"' src='" + img + "' alt='"+ img +"'>";
	text += "</a>";
	preLoadImage(img);
	return text;
}

function generateRandomBalloon(d, space)
{
	var i = rndi(0,vBalloon.length);
	var style = "margin-left:"+space+"px; margin-right:"+0+"px;";			
 	var img =  basisPath + srcPath + vBalloon[i] + "_" + vBalloonDir[d] + ".gif";
	var text = "<img style='"+ style +"' src='" + img + "' alt='"+ img +"'>";

	if (vBalloonLink[i] != "") {
		text = "<a href='" + vBalloonLink[i] + ".0.html'>" + text + "</a>";
	}
	preLoadImage(img);
	return text;
}

/**********************
 * INIT
 **********************/
function init(path) 
{
  basisPath = path; // "my/Path/" or "";
	generateRandomImages();
	//initFadeEffect();
  //alert("init");
	//new Fx.Font($$('body'),$('dynamicFonts_small'),$('dynamicFonts_middle'),0.1);
}

  
  




function initFadeEffect() {
  //var fadeEffect = $('wrap').effects();
    //alert(textEffect);
    //var fontSize = document.getElementsByTagName("body")[0].getStyle('font-size').toInt()
    
    //alert($('dynamicFonts_small'));
    //var textEffect;
    //$('dynamicFonts_small').onclick = function(){textEffect.custom(10,200)}.bind(this);
    
    //$('dynamicFonts_small').onclick = function(){textEffect.custom(10,20)}.bind(this);
  //var fontSize = document.getElementsByTagName("body")[0].style.fontSize;
  
      //'opacity': [1,0.3],
      //'height': [40, 100],
      //'margin-left': [0, 300],
  
  /*
  $('dynamicFonts_big').addEvent('click', function(){
    fadeEffect.custom({
      'opacity': [0,1],
      'font-size': [fontSize, 0.9,{duration:300,unit'em'}]
    });
  });
  
  $('dynamicFonts_middle').addEvent('click', function(){



    fadeEffect.custom({
      'opacity': [0,1],
      'font-size': [fontSize, 0.85,{duration:300,unit'em'}]
    });
  });
  */
  
  //$('dynamicFonts_small').addEvent('click', function(){
  //  textEffect.custom(10,20);
    
    
    /*fadeEffect.custom({
      'opacity': [0,1],
      'font-size': [fontSize, 10]
    });
    */
    //fadeEffect.effect('font-size',{duration:300,unit:'px'}).custom(fontSize, fontSize+0.1);
//  });
 
  
};


/*
Fx.Font = new Class({
  initialize: function(elements, sid, gid, growsize){
    //default growsize is 2px
    this.growsize = (growsize) ? growsize : 2;
    this.elements = [];
	
    //store each element with it's original font-size
    //in an array of arrays [<element>,<element-font-size>]
    elements.each(function(el){
      this.elements.push([el,el.getStyle('font-size').toInt()]);
    },this);
    
    //set the onclick function of the grow button
    $(gid).onclick = function(){this.grow()}.bind(this);
	
    //set the onclick function of the shrink button
    $(sid).onclick = function(){this.shrink()}.bind(this);
  },
  grow: function(){
    this.elements.each(function(el){
      //only grow when the font-size is the original font-size
      if(el[0].getStyle('font-size').toInt() == el[1])
        el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1],el[1]+this.growsize);
    },this);
  },
  shrink: function(){
    this.elements.each(function(el){
      //only shrink when the font-size is the grown font-size 	
      if(el[0].getStyle('font-size').toInt() == el[1]+this.growsize)
        el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growsize, el[1]);
    },this);
  }
});
*/


