Moods = {
    Instances: []
    ,VariantSwitcher: []
    ,DetailImgBluePrint: null
    
    ,Index: {}
    ,PidIndex: {}
    ,IndexStarted: false
    
    ,ActivePIDinModell: []
    ,PictureCache: []
    ,Caller: null
    ,preIndexed : {Pics: []}
    
    ,readPreIndex: function()
    {
        Moods.readIndex(Moods.preIndexed.Pics);
    }
    
    ,fillIndex: function(Type, Caller)
    {
        if (false == Moods.IndexStarted)
        {
            Moods.IndexStarted = true;
            Moods.Caller = Caller;
        }
    }
    
    ,responseIndex: function(Response)
    {
        eval('Response = ' + Response.responseText);
        Moods.readIndex(Pics);
    }
    
    ,readIndex: function(Pics)
    {
        if (!Moods.Caller)
		{
            return;
		}
        
        switch (Moods.Caller.BehviourType)
        {
            case 'modellinfo' :
                var TheImage = $(Moods.Caller.Name + '_pic1');
                break;
                
            default :
                var TheImage = $(Moods.Caller.Name);
                break;
        }
        
        if (TheImage)
        {
            for (var i = 0; Pic = Pics[i]; i ++)
            {
                if (!Moods.Index[Pic.modell])
				{
					Moods.Index[Pic.modell] = [];
				}
                    
                if (Pic.Url)
                {
                    Pic.Img = new Image();
                    Pic.Img.URL = Util.transferScalerOptions(TheImage.src, Pic.Url);
                    MTJax.Preloader.addStack(Pic.Img);
                }
                    
                Moods.Index[Pic.modell].push(Pic);
                Moods.PidIndex[Pic.pid] = Pic;
            }
        }
        
        for (things in Moods.Index)
        {
            console.log(things);
        }
    }
    
    ,getLast: function()
    {
        
    }
    
    ,replaceFileInURL: function(URL, File)
    {
        var OldSrc      = URL.split(/\//);
        var OlderSrc    = OldSrc.pop();
        var NewSrc      = [OldSrc.join('/')];
        
        OlderSrc = OlderSrc.split(/\./);
        OlderSrc.shift();
        OlderSrc.pop();
        File = File.split(/\./);
        
        NewSrc[0] += '/' + File.shift();
        NewSrc.push(OlderSrc.join('.'));
        NewSrc.push(File.shift());
        
        File = NewSrc.join('.');
        return File.replace(/:\/([^\/])/, '://$1');
    }
    
    ,getScalerOption: function(Str)
    {
        Str = Str.split(/\//).pop();
        Str = Str.split(/\./);
        Str.shift();
        Str.pop();
        return Str.join('.');
    }
    
    ,getFilenameFromURL: function(Str)
    {
        var FileName = '';
        Str = Str.split(/\//).pop();
        Str = Str.split(/\./);
        FileName += Str.shift();
        FileName += '.';
        FileName += Str.pop();
        return FileName;
    }
    
    ,getProtortionWidth: function(OHeight, Height, OWidth)
    {
        var Diff = OHeight / Height;
        return OWidth / Diff;
    }
    
    ,overlibTrigger: function(e)
    {
    	var File       = Moods.getFilenameFromURL(this.src);
    	var Options    = Moods.getScalerOption($(this.Mood.Name).src);
    	var Width      = /w(\d+)/.exec(Options)[1];
    	var Height     = /h(\d+)/.exec(Options)[1];
    	var NewSrc     = Moods.replaceFileInURL($(this.Mood.Name).src, File);
    	NewSrc         = Moods.replaceVariant(NewSrc, 'Full', this.UseVariant);
    	
    	Width          = Moods.getProtortionWidth(this.OHeight, Height, this.OWidth);
    	Width          = Math.round(Width);
    	NewSrc         = NewSrc.replace(/w(\d+)/, 'w' + Width);

    	var DetailImg = '<img src="' + NewSrc + '" />';
    	return overlib(e, DetailImg, {Height: Height, Width: Width}, this);
    }
    
    ,replaceVariant: function(Src, Type, Variant, ClosingSlash)
    {
        if (!arguments[3])
            ClosingSlash = true;

        if (true == ClosingSlash)
            ClosingSlash = '/';
        else
            ClosingSlash = '';


        var WVariant    = new RegExp('Mood/' + Type + '/.+' + ClosingSlash);
        var WOVariant   = new RegExp('Mood/' + Type + ClosingSlash);

        if (Variant)
        {
            if (WVariant.exec(Src))
            {
                Src = Src.replace(WVariant, 'Mood/' + Type + '/' + Variant + ClosingSlash);
            }
            else
            {
                Src = Src.replace(WOVariant, 'Mood/' + Type + '/' + Variant + ClosingSlash);
            }
        }
        else
        {
            if (WVariant.exec(Src))
            {
                Src = Src.replace(WVariant, 'Mood/' + Type + ClosingSlash);
            }
        }
        
        return Src;
    }
};

Moodbind = {
    switchVariant: function()
    {
        var Err;
        
        try
        {
            if (!this.toVariant || !this.Mood.toModell)
            {
                this.Mood.toVariant = this.toVariant = /\btoVariant_([\w;]*)\b/.exec(this.className)[1];
                this.Mood.toModell  = /\btoModell_(\w*)\b/.exec(this.className)[1];
            }
            else
            {
                this.Mood.toVariant = this.toVariant;
            }
    
            this.Mood.toModell = this.Mood.toModell.toLowerCase();
            this.Mood.clearSmallImages();
    
            if (!Moods.PictureCache[this.Mood.toVariant])
            {
                new ajax ('/plugin/de.masstisch.ajax/Galerie/getImages.php', {
                	postBody: 'PID=' + encodeURIComponent(this.Mood.toVariant) + '&PicRec=' + this.Mood.BehviourType, 
                	onComplete: this.Mood.chgModell.bind(this.Mood)
                });   
            }
            else
            {
                this.Mood.chgModell(Moods.PictureCache[this.Mood.toVariant]);
            }
        }
        catch (e)
        {
            Err = e;
        }
        
        if (Err)
        {
            console.log(Err);   
            console.trace();
        }
        
        return false;
    }

    ,switchVariantPrev: function()
    {
        try
        {
            if (!this.toVariant || !this.Mood.toModell)
            {
                this.Mood.toVariant = this.toVariant = /\btoVariant_([\w;]*)\b/.exec(this.className)[1];
                this.Mood.toModell  = /\btoModell_(\w*)\b/.exec(this.className)[1];
            }
            else
            {
                this.Mood.toVariant = this.toVariant;
            }
    
            this.Mood.toModell = this.Mood.toModell.toLowerCase();
            this.Mood.clearSmallImages();
    
    
            new ajax ('/plugin/de.masstisch.ajax/Galerie/getImages.php', {
            	postBody: 'PID=' + encodeURIComponent(this.Mood.toVariant), 
            	onComplete: this.Mood.chgModell.bind(this.Mood)
            });
        }
        catch (e)
        {
            Err = e;
        }
        
        if (Err)
        {
            console.log(Err);   
            console.trace();
        }
        
        return false;
    }

    ,previewBigImage: function()
    {
        var Err;
        
        try
        {
            var TheImage = $(this.Mood.Name);
            TheImage.oldSrc = TheImage.src;
    
            var ModellSearch = /modell_([\w;]*)\b/;
            var Modell = ModellSearch.exec(this.className)[1];
            Modell = Modell.split(/;/)[1].toLowerCase();
            
            if (!Moods.Index[Modell])
            {
                return false;
            }
    
            var PID = Moods.ActivePIDinModell[Modell];
            if (PID)
            {
                TheImage.src = Moods.PidIndex[PID].Img.src;
            }
            else
            {
                TheImage.src = Util.transferScalerOptions(TheImage.src, Moods.Index[Modell][0].Url);
            }
        }
        catch (e)
        {
            Err = e;
        }
        
        if (Err)
        {
            console.log(Err);
        }
    }

    ,resetBigImage: function()
    {
        try
        {
            var TheImage = $(this.Mood.Name);
            TheImage.src = TheImage.oldSrc;
        }
        catch (e)
        {
            
        }
    } 
    
    ,modellTrigger: function()
    {
        try
        {
            var ModellSearch = /modell_([\w;]*)\b/;
            var Modell = ModellSearch.exec(this.className)[1];
            Modell = Modell.split(/;/)[1].toLowerCase();
            
            if (!Moods.Index[Modell])
			{
                return false;
			}
            
    
            var PID = Moods.ActivePIDinModell[Modell];
            if (PID)
			{
                this.Mood.toVariant = PID;
			}
            else
			{
                this.Mood.toVariant = Moods.Index[Modell][0].pid;
			}
            
            this.Mood.toModell = Modell;
            this.Mood.clearSmallImages();
         
            // Changing selected List-Entry   
            var Selector = '#' + this.Mood.Name + '_table .modelltrigger';
            $S(Selector).each(
                this.Mood.unselectTrigger.bind(this.Mood)
            );
//            Element.addClassName(this, 'active');
            this.style.backgroundColor = 'black';
            this.style.color = 'white';
         
    
            if (!Moods.PictureCache[this.Mood.toVariant])
            {
                new ajax ('/plugin/de.masstisch.ajax/Galerie/getImages.php', {
                	postBody: 'PID=' + encodeURIComponent(this.Mood.toVariant) + '&PicRec=' + this.Mood.BehviourType, 
                	onComplete: this.Mood.chgModell.bind(this.Mood)
                });   
            }
            else
            {
                this.Mood.chgModell(Moods.PictureCache[this.Mood.toVariant]);
            }
        }
        catch (e)
        {
            throw 'Error while Triggering a Model ( ' + e + ')';
        }
        
        return false;
    }
};

Mood = new Class();
Mood.prototype = {
    /**
     * Prototype Constructur
     * Nimmt einen Namen entgegen. Die ID der Mood-Instanz
     */
    initialize: function(Name)
    {
        this.Name = Name;
        
        var Table = $(this.Name + '_table');

        if (Table.hasClass('single'))
        {
            this.BehviourType = 'single';
        }
        else if (Table.hasClass('quintett'))
        {
            this.BehviourType = 'quintett';
        }
        else if (Table.hasClass('presenting'))
        {
            this.BehviourType = 'presenting';
        }
        else if (Table.hasClass('modellinfo'))
        {
            this.BehviourType = 'modellinfo';
        }
        
        console.log(this.BehviourType);
           
        Moods.fillIndex(this.BehviourType, this); 
            
        var Selector = '#' + this.Name + '_table .modelltrigger';
        Table.getElements('.modelltrigger').each(function(el)
        {
            this.prepareModellTriggers(el);
        }.bind(this));
//        documnt.getElementsBySelector(Selector).each(
//            this.prepareModellTriggers.bind(this)
//        );
        
        var Selector = '#' + this.Name + '_table .details';
        Table.getElements('.details').each(function(el)
        {
            this.hookDetailContainer(el);
        }.bind(this));
//        document.getElementsBySelector(Selector).each(
//            this.hookDetailContainer.bind(this)
//        );
        
        this.VariantSwitchPrev = $(this.Name + '_variantswitch_prev');
        this.VariantSwitchNext = $(this.Name + '_variantswitch_next');
        if (this.VariantSwitchPrev && this.VariantSwitchNext)
        {
            this.VariantSwitchPrev.onclick = Moodbind.switchVariantPrev;
            this.VariantSwitchNext.onclick = Moodbind.switchVariant;
            this.VariantSwitchPrev.Mood = this;
            this.VariantSwitchNext.Mood = this;
        }

        var Probe = $(this.Name);
        if (Probe)
        {
            Probe.OriginalSrc = Probe.src;
        }
                        
        var Pic1Img = $(this.Name + '_pic1');
        if (Pic1Img)
        {
            Pic1Img.OriginalSrc = Pic1Img.src;
        }
        var Pic2Img = $(this.Name + '_pic2');
        if (Pic2Img)
        {
            Pic2Img.OriginalSrc = Pic2Img.src;
        }
        var Pic4Img = $(this.Name + '_pic4');
        if (Pic4Img)
        {
            Pic4Img.OriginalSrc = Pic4Img.src;
        }
    }

    ,OriginalSrc: null
    ,VariantSwitchNext: null
    ,VariantSwitchPrev: null
    ,Name: ''
    ,toModell: ''
    ,toVariant: ''
    ,DetailContainer: []
    ,BehviourType: 'default'
    
    ,chgModell: function(Response)
    {
        var Err;
        try
        {

            if (Response.responseText)
            {
                eval('Response = ' + Response.responseText);
            }

    
            Moods.PictureCache[this.toVariant] = Response;
            Moods.ActivePIDinModell[this.toModell] = this.toVariant;
            
            var VSwitch = $(this.Name + '_variantswitch');
            if (!VSwitch.FetchedDisplay)
            {
                VSwitch.OldDisplay = VSwitch.style.display;
                VSwitch.FetchedDisplay = true;   
            }
            VSwitch.style.display = 'none';
    
            if (Response.Pics)
            {
                switch (this.BehviourType)
                {
                    case 'single' :
                        var Tmp = [];
                        for (var i = 0; Pic = Response.Pics[i]; i ++)
                        {
                            var Probe = Pic.Url.split(/\//).pop();
                            console.log(Pic);
                            if (Probe == 'pic2.jpg')
                            {
                                this.setBigImage(this.Name, Pic);
                            }
                            else
                            {
                                Tmp.push(Pic);
                            }
                        }
                        Tmp.length = 3;
                        this.setSmallImages(Tmp);
                        this.setDescription(Response.Config, Response.NfoHead);
//                        Moods.index[this.mo]
                        break;
    
                    case 'cfgr' :
                        Response.Pics.length = 4;
                        this.setSmallImages(Response.Pics); 
                        this.setDescription(Response.Config, Response.NfoHead);
                        break;
    
                    case 'quintett' :
                        this.setBigImage(this.Name, Response.Pics.shift());
                        Response.Pics.length = 4;
                        this.setSmallImages(Response.Pics); 
                        this.setDescription(Response.Config, Response.NfoHead);
                        break;
    
                    case 'presenting' :
                        this.setBigImage(this.Name, Response.Pics.shift());
                        this.setSmallImages(Response.Pics.splice(0, 3)); 
                        this.setDescription(Response.Config, Response.NfoHead);
                        break;
    
                    case 'modellinfo' :
                        var Pic1 = this.getPic('pic1', Response.Pics);
                        var Pic2 = this.getPic('pic2', Response.Pics);
                        var Pic4 = this.getPic('pic4', Response.Pics);
                        
                        var Pic1Img = $(this.Name + '_pic1');
                        var Pic2Img = $(this.Name + '_pic2');
                        var Pic4Img = $(this.Name + '_pic4');
                        

                        Pic1Img.style.width = parseInt(Pic1Img.style.width) + 'px';
                        Pic2Img.style.width = (Pic2Img.offsetWidth - 8) + 'px';
                        Pic4Img.style.width = parseInt(Pic4Img.style.width) + 'px';

                        Pic1Img.style.height = Math.floor(Pic1.Height / (Pic1.Width / parseInt(Pic1Img.style.width))) + 'px';
                        Pic2Img.style.height = Math.floor(Pic2.Height / (Pic2.Width / parseInt(Pic2Img.style.width))) + 'px';
                        Pic4Img.style.height = Math.floor(Pic4.Height / (Pic4.Width / parseInt(Pic4Img.style.width))) + 'px';

                        this.setBigImage(Pic1Img, Pic1);
                        this.setBigImage(Pic2Img, Pic2);
                        this.setBigImage(Pic4Img, Pic4);
                        break;
    
                    default :
                        var Set = Response.Pics.slice(0, 6);
    
                        this.setBigImage(this.Name, Set.shift());
                        this.setSmallImages(Set); 
                        this.setDescriptionOL(Response.Config, Response.NfoHead);
                        break;
                }
    
                this.setVariantSwitches(Response.Variants, Response.LinkText);
                this.setLink(this.toVariant);
                
            }
        }
        catch (e)
        {
            Err = e;
        }
        
        if (Err)
        {
            console.log(Err);   
            console.trace();
        }
    }
    
    ,getPic: function(Picname, Pics)
    {
        for (var i = 0; Pic = Pics[i]; i++)
        {
            if (Picname + '.jpg' == Pic.Url.split('/').pop())
                return Pic;
        }
    }
    
    ,setLink: function(Config)
    {
        if (!$(this.Name + '_config_a'))
            return;

        // Changing Cofig-Link
        $(this.Name + '_config_a').href =
            $(this.Name + '_config_a').href.replace(/Template,.*$/, 'Template,' + Config.split(/;/)[0]);
    }
    
    ,setDescriptionOL: function(Config, NfoHead)
    {
        if (!Overlibs.Pre[this.Name + '_showdescription'])
            return;

        if (Config.Nfo)
            Overlibs.Pre[this.Name + '_showdescription'].Content = '<h3>' + NfoHead + '</h3>' + '<div>' + Config.Nfo.Title + '<br />' + Config.Nfo.Description + '</div>';
        else
            Overlibs.Pre[this.Name + '_showdescription'].Content = '<h3>' + NfoHead + '</h3>' + '<div>...</div>';
    }
    
    ,setDescription: function(Config, NfoHead)
    {
        var Descript = $(this.Name + '_descript');
        
        if (Descript)
            Descript.innerHTML = '<h3>' + NfoHead + '</h3>' + '<div>' + Config.Nfo.Title + '<br />' + Config.Nfo.Description + '</div>';
    }
    
    ,clearSmallImages: function()
    {
        if (this.DetailContainer[this.Name])
        {
            var i = 0;
            for (i = 0; Container = this.DetailContainer[this.Name][i]; i ++)
            {
                while (Child = Container.childNodes[0])
                {
                    Container.removeChild(Child);
                }
            }   
        }
        
        switch (this.BehviourType)
        {
            case 'modellinfo' :
                this.clearBigImage(this.Name + '_pic1');
                this.clearBigImage(this.Name + '_pic2');
                this.clearBigImage(this.Name + '_pic4');
                break;

            default :
                this.clearBigImage(this.Name);
                break;
        }
    }
    
    ,clearBigImage: function(ID)
    {
        var TheImage                        = $(ID);
        TheImage.style.width    = TheImage.offsetWidth + 'px';
        TheImage.style.height   = TheImage.offsetHeight + 'px';
        if (TheImage && -1 == TheImage.src.search(/Icons\/blind.gif/)
        && !Moods.PictureCache[this.toVariant])
        {
            if (Moods.PidIndex[this.toVariant] && Moods.PidIndex[this.toVariant].Img)
            {
                TheImage.src = Moods.PidIndex[this.toVariant].Img.src;
                TheImage.oldSrc                     = TheImage.src;
            }
            else
            {
                TheImage.oldSrc                     = TheImage.src;
                TheImage.src                        = '/media/Image/Icons/blind.gif';
                TheImage.style.backgroundImage      = 'url(/media/Image/Icons/ajax/indicator_medium.gif)';
                TheImage.style.backgroundPosition   = 'center center';
                TheImage.style.backgroundRepeat     = 'no-repeat';   
            }
        }
//        $(this.Name + '_debug').innerHTML += 'offSetWidth ' + TheImage.offsetWidth+ '<br />';
    }
    
    ,setSmallImages: function(Images)
    {
        try
        {
            if (!this.DetailContainer[this.Name])
            {
                return;
            }

	        var i = 0;
	        var SnapTo = null;
	        
	        var ToContainer = 0;
	        var ChildOffset = 0;
	        for (i = 0; Src = Images[i]; i ++)
	        {
	            if (i >= 2)
	            {
	                if (this.DetailContainer[this.Name][1])
	                {
	                    ToContainer = 1;
	                    ChildOffset = 2;   
	                }
	            }
	
	            if (!this.DetailContainer[this.Name][ToContainer].childNodes[i - ChildOffset])
	            {
	                var Child = this.DetailContainer[this.Name][ToContainer].appendChild(Moods.DetailImgBluePrint.cloneNode(true));   
	            }
	        }
	
	        var Num = 0;
	        for (i = 0; Container = this.DetailContainer[this.Name][i]; i ++)
	        {
	            for (c = 0; Child = Container.childNodes[c]; c ++)
	            {
	                if (i <= 2)
	                    SnapTo = Child;
	                Num++;
	            }
	        }
	        
	        var ToContainer = 0;
	        var ChildOffset = 0;
	        for (i = 0; Src = Images[i]; i ++)
	        {
	            if (i >= 2)
	            {
	                if (this.DetailContainer[this.Name][1])
	                {
	                    ToContainer = 1;
	                    ChildOffset = 2;   
	                }
	            }
	
	            var Child          = this.DetailContainer[this.Name][ToContainer].childNodes[i - ChildOffset];
	
	            Child.src           = Util.transferScalerOptions(Moods.DetailImgBluePrint.oldSrc, Src.Url);
	            Child.UseVariant    = this.toVariant;
	            
	            
	            
	        	var File       = Moods.getFilenameFromURL(Child.src);
	        	var Width      = 290;
	        	var Height     = 290;
	
	            var PID = this.toVariant.split(/;/)[0];
	            Child.className = Child.className.replace(/pid_\d+\b/, 'pid_' + PID);
	        	Width          = Moods.getProtortionWidth(Src.Height, Height, Src.Width);
	        	Width          = Math.round(Width);
	
	            Child.SnapTo = SnapTo;
	            
	            Child.Overlib = new OverlibImg(
	                 Child
	                ,'w' + Width + '.h' + Height
	            );
	        }
        }
        catch (e)
        {
            throw 'Error while setting Detailspics ' + e;
        }
    }
    
    ,setVariantSwitches: function(LinkText)
    {
        console.log('IN : setVariantSwitches : ' +this.toModell.toLowerCase());
        for (thing in Moods.Index)
        {
            console.log(thing);
        }
        
        if (!Moods.Index[this.toModell.toLowerCase()] || Moods.Index[this.toModell.toLowerCase()].length < 2)
        {
            return;
        }

        var Variants        = Moods.Index[this.toModell.toLowerCase()].slice(0);
        var VariantsPrev    = Moods.Index[this.toModell.toLowerCase()].slice(0);

        var LinkTo = Variants[0].pid;
        while (Variant = Variants.pop())
        {
            if (Variant.pid == this.toVariant)
                break;

            LinkTo = Variant.pid;
        }
        var LinkToPrev = VariantsPrev.pop().pid;
        while (Variant = VariantsPrev.shift())
        {
            if (Variant.pid == this.toVariant)
                break;

            LinkToPrev = Variant.pid;
        }
        
        var Tag             = $(this.Name + '_variantswitch');
        Tag.style.display   = Tag.OldDisplay;
        
        var Tag         = this.VariantSwitchNext;
        Tag.Mood        = this;
        Tag.toVariant   = LinkTo;
        Tag.onclick     = Moodbind.switchVariant;
        
        var Tag         = this.VariantSwitchPrev;
        Tag.Mood        = this;
        Tag.toVariant   = LinkToPrev;
        Tag.onclick     = Moodbind.switchVariant;
    }
    
    ,setBigImage: function(Name, Src)
    {
        var Err;
        
        try
        {
            var TheImage = $(Name);
            if (!TheImage)
            {
                 return;
            }
            
            TheImage.src = Util.transferScalerOptions(TheImage.OriginalSrc, Src.Url);
            var Options = Util.stripScalerOptions(TheImage.OriginalSrc);
            TheImage.oldSrc = TheImage.src;
            

            var PID = this.toVariant.split(/;/)[0];
            TheImage.className = TheImage.className.replace(/pid_\d+\b/, 'pid_' + PID);
            var JB = Jax_BrowserUtil.getInstance();
            JB.prepareImageTrigger(TheImage);
        }
        catch (e)
        {
            Err = 'Error while setting BigImage:: ' + e;
        }
        
        if (Err)
        {
            console.log(Err);
        }
    }
    
    ,hookDetailContainer: function(Obj)
    {
        if (!this.DetailContainer[this.Name])
            this.DetailContainer[this.Name] = [];
        this.DetailContainer[this.Name].push(Obj);
//        $(this.Name + '_debug').innerHTML += 'Hooking Container<br />';
//        $(this.Name + '_debug').innerHTML += 'ContainerNum ' + this.DetailContainer[this.Name].length + '<br />';
        
        /* Cleanup von Text-elementen (generell gehören in den Container nur <img/>-Tags
         * 
         */
        for (i = 0; Child = Obj.childNodes[i]; i ++)
        {
            if (!Child.src)
            {
//                Obj.removeChild(Child);   
//                i--;                
            }
            else
            {
                Moods.DetailImgBluePrint = Child.cloneNode(true);
            }
        }
        
        Moods.DetailImgBluePrint.oldSrc                     = Moods.DetailImgBluePrint.src;
        Moods.DetailImgBluePrint.src                        = '/media/Image/Icons/blind.gif';
        Moods.DetailImgBluePrint.style.backgroundImage      = 'url(/media/Image/Icons/ajax/indicator.gif)';
        Moods.DetailImgBluePrint.style.backgroundPosition   = 'center center';
        Moods.DetailImgBluePrint.style.backgroundRepeat     = 'no-repeat';
    }
    
    ,unselectTrigger: function(Obj)
    {
//        Element.removeClassName(Obj, 'active');
        
        Obj.style.backgroundColor = 'white';
        Obj.style.color = 'black';
    }
    
    ,prepareModellTriggers: function(Obj)
    {
        Obj.Mood        = this;
        Obj.onclick     = Moodbind.modellTrigger;
        Obj.onmouseover = Moodbind.previewBigImage;
        Obj.onmouseout  = Moodbind.resetBigImage;        
    }
};

//Behaviour.register(Moodbind.Behaviours);
window.addEvent('domready', function()
{
    document.getElements('.mood').each(function(Elem)
    {
        console.log(Elem);
        Item = Elem;
        var ID = Item.id.split(/_/);
        ID.pop();
        var newMood = new Mood(ID.join('_'));
        console.log(newMood);
    });
    
    
    Moods.readPreIndex();
});



