
WHRRI.Event = function(pId, pName, pStartDate, pEndDate) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    
    this.id = pId;
    this.name = pName;
    if (pStartDate) {
        this.startDate = Date.parse(pStartDate);
        if (pEndDate) {
            this.endDate = Date.parse(pEndDate);
        } else {
            this.endDate = this.startDate;
        }
    }
    this.photoSets = [];
    
    this.isClubRace = function() {
        return this.name.match(/^Race /i);
    };
    this.isOTD = function() {
        return this.name.match(/^OTD /i) || this.name.match(/^Open Track Day /i);
    };
    this.isVintage = function() {
        return this.name.match(/Vintage/i);
    };
    this.isOnTrack = function() {
        return (this.isClubRace() || this.isVintage() || this.isOTD());
    };
    this.isOver = function() {
        var over = false;
        if (this.endDate) {
            over = this.endDate.isBefore(new Date());
        }
        return over;
    };
    this.addPhotoSet = function(pPhotoSet) {
        this.photoSets.push(pPhotoSet);
    };
    this.getPhotoSets = function() {
        return this.photoSets;
    };
};


WHRRI.NewsItem = function(pTitle, pAuthor, pPublishedDate, pContentSnippet, pContent, pLink) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");

    this.title = pTitle;
    this.author = pAuthor;
    if (pPublishedDate instanceof Date) {
        this.publishedDate = pPublishedDate;
    } else {
        this.publishedDate = Date.parse(pPublishedDate);
    }
    this.contentSnippet = pContentSnippet;
    this.content = pContent;
    this.link = pLink;
};



WHRRI.Person = function(pId, pFirstName, pMiddleName, pLastName, pNameSuffix, pEmail, pPhone, pIsBoardMember) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    
    this.id = pId;
    this.lastName = pLastName;
    this.firstName = pFirstName;
    this.middleName = pMiddleName;
    this.nameSuffix = pNameSuffix;
    this.emailAddress = pEmail;
    this.workPhone = pPhone;
    //this.homePhone = 
    //this.cellPhone = 
    //this.membership = 
    //this.license = 
    //this.primaryRole = 
    //this.birthDate = 
    //this.deceasedDate = 
    //this.postalAddress = 
    //this.occupation = 
    //this.employer = 
    //this.position = 
    //this.byLaws = 
    //this.doNotPublish = 
    //this.inGoodStanding = 
    //this.notes = 
    //this.photoFilename = 
    //this.modifiedDate = 
    //this.affiliatedDriver = 
    this.isBoardMember = pIsBoardMember;
    
    this.getFullName = function() {
        var fullname = "";
        if (this.firstName) fullname += this.firstName + " ";
        if (this.middleName) {
            fullname += this.middleName;
            if (this.middleName.length == 1) fullname += ".";
            fullname += " ";
        }
        if (this.lastName) fullname += this.lastName;
        if (this.nameSuffix) {
            fullname += ", " + this.nameSuffix;
        }
        return fullname;
    };
};



WHRRI.Contact = function(pRole, pPerson, pEmail, pPhone, pNotes) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    
    this.role = pRole;
    this.person = pPerson;
    this.notes = pNotes;
    if (pEmail) {
        this.email = pEmail;
    } else {
        this.email = pPerson.emailAddress;
    }
    if (pPhone) {
        this.phone = pPhone;
    } else {
        if (pPerson.cellPhone) {
            this.phone = pPerson.cellPhone;
        } else if (pPerson.homePhone) {
            this.phone = pPerson.homePhone;
        } else if (pPerson.workPhone) {
            this.phone = pPerson.workPhone;
        }
    }
};



WHRRI.Photographer = function(pId, pName, pWebsite, pEmail, pPhone, pPhotoServiceAccounts) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    
    this.id = pId;
    this.name = pName;
    this.website = pWebsite;
    this.email = pEmail;
    this.phone = pPhone;
    this.photoServicesAccounts = pPhotoServiceAccounts;
    this.getId = function() {
        return this.id;
    };
    this.getPhotoServiceAccount = function(pServiceName) {
        for (var i in this.photoServicesAccounts) {
            var serviceAccount = this.photoServicesAccounts[i];
            if (serviceAccount.name == pServiceName) {
                return serviceAccount;
            }
        }
    };
};



WHRRI.PhotoSet = function(pEventId, pPhotographer, pServiceName, pServiceSetId, pServiceSetKey) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    this.eventId = pEventId;
    this.photographer = pPhotographer;
    this.serviceName = pServiceName;
    this.serviceSetId = pServiceSetId;
    this.serviceSetKey = pServiceSetKey;
    
    this.getId = function() {
        return this.eventId + "_" + this.photographer.getId().toLowerCase();
    };
    
    this.getExternalPhotoSetURL = function() {
        //console.log("building external photo set URL (for " + this.getId() + ")");
        var url = "";
        var serviceAccountId = this.photographer.getPhotoServiceAccount(this.serviceName).userId;
        switch (this.serviceName) {
        case WHRRI.PHOTO_SERVICE_NAMES.FLICKR:
            url = "http://www.flickr.com/photos/" + serviceAccountId + "/sets/" + this.serviceSetId + "/";
            break;
        case WHRRI.PHOTO_SERVICE_NAMES.SMUGMUG:
            url = "http://" + serviceAccountId + ".smugmug.com/";
            break;
        case WHRRI.PHOTO_SERVICE_NAMES.LOCAL:
            // no place to link to in this case.  wysiwyg.
            break;
        default:
            break;
        }
        return url;
    };
};



WHRRI.PhotoServiceAccount = function(pName, pUserId) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    this.name = pName;
    this.userId = pUserId;
};



WHRRI.Sponsor = function(pName, pLinkUrl, pImageSrcUrl) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    this.name = pName;
    this.linkUrl = pLinkUrl;
    this.imageSrcUrl = pImageSrcUrl;
};


WHRRI.Class = function(pName, pAbbreviation) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
	this.name = pName;
	this.abbreviation = pAbbreviation;
    this.equals = function(other) {
    	return (this.klass.abbreviation == other.klass.abbreviation);
    };
};

WHRRI.TrackRecord = function(pClassAbbreviation, pLapTime, pDriverName, pMarque, pDate) {
    if (!(this instanceof arguments.callee)) throw new Error("Constructor called as a function");
    this.classAbbreviation = pClassAbbreviation;
    this.lapTime = pLapTime;
    this.driverName = pDriverName;
    this.marque = pMarque;
    this.date = Date.parse(pDate);
};

