// "Klasse" fuer das DropCollection-Objekt

/*Konstruktor: erstellt ein neues DropCollection Objekt
 *param: umgebendes Div, das alle Tropfen-Divs enthält 
*/
function DropCollection(div_container_id){
	
	//------- Objekt-Attribute:  ---------
	this.arrDrops = new Array(); // Array zur Speicherung der Tropfen

	
	//------- Objekt-Methoden:  ---------
	this.getAllDrops = getAllDrops;
	/*die init-Methode "kuemmert sich" um alles: erstellt die tropfen, positioniert sie anhand des 2-dim-arrays, ...*/
	this.init = init;
	this.positionAllDrops = positionAllDrops;
	this.notifyOtherDrops = notifyOtherDrops;
	this.notifyOtherDropsToComeBack = notifyOtherDropsToComeBack;
	
	
	//------- Initialisierungen:  ---------
	this.init(div_container_id);	//beim Erstellen des DropCollection-Objekts muss uch gleich alles initialisiert werden
	//alle Tropfen wieder sichtbar machen: (werden VOR body.onload im css mit display:none unsichtbar gemacht
	for (var i=0;i<this.arrDrops.length;i++){
		this.arrDrops[i].div.style.display="block";
	}
}


/*  Die init-Methode erstellt die Tropfen, positioniert sie, usw...
 *  dazu wird sie dann im Konstruktor der DropCollection aufgerufen, damit beim erstellen eines neuen 
 * 	DropCollection-Objekts bereits alles initialisiert wurde.
 */
function init(div_container_id){
	this.getAllDrops(div_container_id);
	this.positionAllDrops();
}


/* holt sich alle Tropfen-Divs in 'div_container_id' und erstellt
*  fuer jedes gefundene Tropfen-Div ein Tropfen-Objekt und speichert dieses im Tropfen-Array
*/
function getAllDrops(div_container_id){
	var arrDropDivs = getElementsByClassName_inDiv("drop",div_container_id);
	for(var i=0;i<arrDropDivs.length;i++){
		var newDrop = new Drop(arrDropDivs[i].getAttribute("id"));		
		newDrop.collection = this; //dem neu angelegten Tropfen eine Referenz auf diese Kollektion (this) mitgeben
		this.arrDrops[this.arrDrops.length] = newDrop; //neuen Tropfen hinten in Tropfen-Array einfügen
	}
}


/*  positioniert anhand des 2-dimensionalen Arrays (aus dem html-header) alle Tropfen, 
 *  der Reihenfolge nach ! Dazu müssen gegebenenfalls die Tropfen-Divs im html-file richtig angeordnet werden
 *  damit die positionen stimmen
 */
function positionAllDrops(){
	for(var j=0;j<this.arrDrops.length;j++){
		this.arrDrops[j].setXandY(arrDropInfos[j + 1]['x'],arrDropInfos[j + 1]['y']);
		this.arrDrops[j].url = arrDropInfos[j + 1]['url'];
		if(!isMiniDrop(this.arrDrops[j]))
			this.arrDrops[j].initTransparentDiv(); // das transparente Div muss nun auch nochmal neu positioniert werden
		this.arrDrops[j].setOrigXandYPosition(arrDropInfos[j + 1]['x'],arrDropInfos[j + 1]['y']); //dem Tropfen Attribut mitgeben, damit er seine ursprüngliche x und y Position kennt
	}	
}


/* iteriert alle Tropfen im Tropfen-Array durch und ruft auf jedem Tropfen die eigene
 * Objektmethode 'checkPosition()' auf und uebergibt ihr 'changing_drop'. Die Tropfen
 * (bzw. die Methode 'checkPosition()') kümmern sich dann selbst darum, ob sie sich verschieben muessen
 */
function notifyOtherDrops(changing_drop){
	for(var s=0;s < this.arrDrops.length;s++){
		this.arrDrops[s].x_range=-1;  //wird gebraucht in 'moveBack', wird hier zuruekgesetzt, weil x_range nur fuer zoomOut benoetigt wird
		this.arrDrops[s].y_range=-1;
		
		if(this.arrDrops[s] != changing_drop) //soll sich natuerlich nicht selber ueberpruefen...
			this.arrDrops[s].checkPosition(changing_drop);
	}	
}

function notifyOtherDropsToComeBack(changing_drop){
	for (var i =0; i<this.arrDrops.length;i++){
		if(this.arrDrops[i] != changing_drop) //soll sich natuerlich nicht selber ueberpruefen...
			this.arrDrops[i].moveBack(changing_drop);
	}
}


function createCollection(cont_id){
     var coll = new DropCollection(cont_id);
}