/*
 * homepage navigation brunel using jquery
 * Author: Carsten Meyer
 * HMMH AG
 * carsten.meyer@hmmh.de
 * 
 */


var PlusMinus = function(p,m)

{
    var property = {
    		
    'from': 62,
    'tomax':124,
    'on': false,
    'nr': 0,
    'obj': null,
    'remoteMethod': null,
    '_self':this,
    'instances': new Array()

    }
    property.plus = new Image();
    property.minus = new Image();
    property.plus.src = p;
    property.minus.src = m;
    
    this.setInstances = function(inst)
    {
    	property.instances = inst;
    }
    
    
    this.setParentObject = function(obj){
    
    	property.obj = obj;
    }
    
    this.setNumber = function(nr)
    {
    	property.nr = nr;
    }
    
    this.setRemoteMethod = function(f)
    {
    	property.remoteMethod = f;
    }
    
    this.getProperties  = function()
	{
		return property;
	}
    	    
	var img = document.createElement('img');
	    img.src = property.plus.src;     
	    
        $(img).css('float','right');
        $(img).css('margin','5px');
        $(img).css('cursor','pointer');
	
	$(img).click(function(){
		
		var imgself = this;
		$(property.instances).each(function(nr,obj){
			
			o = obj.getProperties();
			if(o.on && (o.img != imgself)){
				
				o.on = false;
				$(o.obj).animate({height: property.from+'px'});
				$(o.img).attr('src',o.plus.src);
			}
			
		});
	
		if(property.on)property.on = false;
		else if(!property.on) property.on = true;
	
	
	   	if(property.on)
			{$(this).attr('src',property.minus.src); $(property.obj).animate({height: property.tomax+'px'});}
		else
		    {$(this).attr('src',property.plus.src); $(property.obj).animate({height: property.from+'px'});}

	    
	});
	

	property.img = img;
	this.getImage = function()
	{
		return img;  
	} 
}
  
  
var HomeNavigation = function(selector,p,m)
{
  
	var menues = new Array(); 

	$(selector).each(function(nr,obj){
		
		var sw = new PlusMinus(p,m);
		var options = sw.getProperties();
        sw.setNumber(nr); 
        sw.setParentObject(obj);
        sw.setRemoteMethod(open);
        menues.push(sw);
        sw.setInstances(menues);
        $(obj).css('height',options.from+'px');
		$(obj).prepend(sw.getImage());
		
	});


}






