﻿// JScript File
/************************
 * This class will load the face parts from the productlist.aspx page.  
 *
 * Usage: Create a new faces object passing in the facepart code you want to access, 
 * and web root (ResolveUrl("~") in .net).  Once the object is instanciated you can access 
 * paint the makeup on the models by calling the paintMakeup method passing in a FaceMakeup
 * object.  You can also clear the makeup by calling the ClearMakeup method.
 *
 * Example:
 * var faces = new Faces("C", "/JouerWeb/");
 * var makeup = new FaceMakeup( "C", "mysku-green", "/JouerWeb/");
 * // TO Paint
 * faces.paintMakeup(makeup);
 * // To Clear
 * faces.clearMakeup();
 *
 * NOTE: This object has a dependancy to getElementsByClassName-1.0.1.js file and it must also
 * be loaded into the browser.
 *************************/
function Faces(facePart, webRoot)
{
    /* Methods */        
    this.getFacePart = function(type, part)
    {
        var facePart = getElementsByClassName(type.toLowerCase() + "_face_" + part.toLowerCase())[0];
        
        return facePart;
    };
    
    this.getFaceResetUrl = function(model)
    {
        return this.webRoot + "images/makeup/" + model.toLowerCase() + "_face_" + this.facePart.toLowerCase() + "_normal.jpg";
    };
    
    this.paintMakeup = function( makeup )
    {
        this.asianFace.src = makeup.asianMakeup;
        this.africanFace.src = makeup.africanMakeup;
        this.blondeFace.src = makeup.blondeMakeup;
        this.brunetteFace.src = makeup.brunetteMakeup;
    };
    
    this.clearMakeup = function()
    {
        this.asianFace.src = this.getFaceResetUrl("as");
        this.africanFace.src = this.getFaceResetUrl("bk");
        this.blondeFace.src = this.getFaceResetUrl("bd");
        this.brunetteFace.src = this.getFaceResetUrl("bt");
    }
    
    /* Properties */
    this.webRoot = webRoot;
    this.facePart = facePart;
    this.asianFace = this.getFacePart("as", this.facePart);
    this.blondeFace = this.getFacePart("bd", this.facePart);
    this.africanFace = this.getFacePart("bk", this.facePart);
    this.brunetteFace = this.getFacePart("bt", this.facePart);
} 
