//============================================================================
//TODO: fix spacing on packaging and look at clam price
//============================================================================

var QTY_MIN = 1;
var QTY_MAX = 999999999;

var PAGE_TYPE = 'pagTyp';
var PAGE_PACKAGING = 'pagPkg';
var PAGE_FINISHING = 'pagFin';
var PAGE_TOTAL = 'pagTot';
var PAGE_NONE = 'pagNone';

var TYPE_DVD = 'typDvd';
var TYPE_CD = 'typCd';
var TYPE_MDISC = 'typMdisc';
var TYPE_NONE = 'typNone';

var FACEART_COLOR = 'farClr';
var FACEART_BLACK = 'farBlk';
var FACEART_NONE = 'farNone';

var PACKAGING_BLACK = 'pkgBlk';
var PACKAGING_CLEAR = 'pkgClr';
var PACKAGING_SLIM_BLACK = 'pkgSlmBlk';
var PACKAGING_SLIM_CLEAR = 'pkgSlmClr';
var PACKAGING_DVD = 'pkgDvd';
var PACKAGING_CLAM = 'pkgClm';
var PACKAGING_PAPER = 'pkgPpr';
var PACKAGING_NONE = 'pkgNone';

var INSERT_2PANEL0 = 'insF2P0';
var INSERT_4PANEL0 = 'insF4P0';
var INSERT_4PANEL4 = 'insF4P4';
var INSERT_DVD_2PANEL0 = 'insD2P0';
var INSERT_DVD_2PANEL4 = 'insD2P4';
var INSERT_DVD_4PANEL0 = 'insD4P0';
var INSERT_DVD_4PANEL4 = 'insD4P4';
var INSERT_NONE = 'insNone';

var TRAY_CARD0 = 'tryC0';
var TRAY_CARD4 = 'tryC4';
var TRAY_NONE = 'insNone';

var ENTRAPMENT_DVD = 'entDvd';
var ENTRAPMENT_NONE = 'insNone';

var FINISH_SHRINK = 'finShrink';
var FINISH_OVER = 'finOver';
var FINISH_NONE = 'finNone';

var SHIP_DAYS_23 = 'shpDay23';
var SHIP_DAYS_35 = 'shpDay35';
var SHIP_DAYS_57 = 'shpDay57';
var SHIP_DAYS_NONE = 'shpDayNone';
var SHIP_SPINDLE = 'shpSpindle';
var SHIP_PAPER = 'shpPaper';
var SHIP_PACKAGED = 'shpPackaged';
var SHIP_NONE = 'shpNone';

//=======================================
// Pricing Object
//=======================================
function UnitPriceList( )
{
    this.sorted = true;
    this.list = [];
    
    this.add = function( qty, price )
    {
        var ndx = this.list.length;
        this.list[ ndx ] = {};
        this.list[ ndx ][ 'qty' ] = qty;
        this.list[ ndx ][ 'price' ] = price;
        this.sorted = false;
    }
    
    this.addList = function( list )
    {
        var cnt = list.length;
        for( var i = 0; i < cnt; i++ )
        {
            var item = list[ i ];
            this.add( item.qty, item.price );
        }
    }
    
    this.sort = function( )
    {
        if( !this.sorted )
        {
            this.list.sort( function( a, b ){ return a.qty - b.qty; } );
            this.sorted = true;
        }
    }
    
    this.get = function( qty )
    {
        this.sort( );
        
        var price = 0;
        var cnt = this.list.length;
        for( var i = 0; i < cnt; i++ )
        {
            var item = this.list[ i ];
            if( qty >= item.qty )
            {
                price = item.price;
            }
            else
            {
                break;
            }
        }
        
        return price;
    }
    
    this.set = function( qty, price )
    {
        var setPrice = false;
        var cnt = this.list.length;
        for( var i = 0; i < cnt; i++ )
        {
            var item = this.list[ i ];
            if( qty == item.qty )
            {
                item.price = price;
                setPrice = true;
                break;
            }
        }
        
        if( !setPrice )
        {
            this.add( qty, price );
        }
    }
}

//=======================================
// Finishing Object
//=======================================
function Finishing( id )
{
    this.objectId = id;
    this.price = new UnitPriceList( );
    
    this.getTotal = function( qty )
    {
        var unit = this.price.get( qty );
        var total = ( unit * qty );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the packaging total
        var unit = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( unit, 2 ) + ' \\each' );
    }
}

//=======================================
// Entrapment Object
//=======================================
function Entrapment( id )
{
    this.objectId = id;
    this.price = new UnitPriceList( );
    
    this.getTotal = function( qty )
    {
        var total = this.price.get( qty );
        var unit = ( qty == 0 ? total / qty : 0 );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the packaging total
        var total = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( total, 2 ) );
    }
}

//=======================================
// Tray Object
//=======================================
function Tray( id )
{
    this.objectId = id;
    this.price = new UnitPriceList( );
    
    this.getTotal = function( qty )
    {
        var total = this.price.get( qty );
        var unit = ( qty == 0 ? total / qty : 0 );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the packaging total
        var total = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( total, 2 ) );
    }
}

//=======================================
// Insert Object
//=======================================
function Insert( id )
{
    this.objectId = id;
    this.price = new UnitPriceList( );
    
    this.getTotal = function( qty )
    {
        var total = this.price.get( qty );
        var unit = ( qty == 0 ? total / qty : 0 );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the packaging total
        var total = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( total, 2 ) );
    }
}

//=======================================
// Packaging Object
//=======================================
function Packaging( id )
{
    this.entrapment = {};
    this.insert = {};
    this.objectId = id;
    this.price = new UnitPriceList( );
    this.selectedEntrapment = ENTRAPMENT_NONE;
    this.selectedInsert = INSERT_NONE;
    this.selectedTray = TRAY_NONE;
    this.tray = {};
    
    this.addEntrapment = function( name, obj )
    {
        if( !( obj instanceof Entrapment ) )
        {
            this.entrapment[ name ] = new Entrapment( name );
        }
        else
        {
            this.entrapment[ name ] = obj;
        }
    }
    
    this.addInsert = function( name, obj )
    {
        if( !( obj instanceof Insert ) )
        {
            this.insert[ name ] = new Insert( name );
        }
        else
        {
            this.insert[ name ] = obj;
        }
    }
    
    this.addTray = function( name, obj )
    {
        if( !( obj instanceof Tray ) )
        {
            this.tray[ name ] = new Tray( name );
        }
        else
        {
            this.tray[ name ] = obj;
        }
    }
    
    this.getBaseTotal = function( qty )
    {
        var unit = this.price.get( qty );
        var total = ( unit * qty );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.getEntrapment = function( name )
    {
        return this.entrapment[ name ];
    }
    
    this.getEntrapmentTotal = function( qty )
    {
        return ( ( this.getSelectedEntrapment( ) ).getTotal( qty ) );
    }
    
    this.getInsert = function( name )
    {
        return this.insert[ name ];
    }
    
    this.getInsertTotal = function( qty )
    {
        return ( ( this.getSelectedInsert( ) ).getTotal( qty ) );
    }
    
    this.getSelectedEntrapment = function( )
    {
        if( typeof this.entrapment[ this.selectedEntrapment ] == 'undefined' )
        {
            this.selectedEntrapment = ENTRAPMENT_NONE;
        }
        
        return this.getEntrapment( this.selectedEntrapment );
    }
    
    this.getSelectedInsert = function( )
    {
        if( typeof this.insert[ this.selectedInsert ] == 'undefined' )
        {
            this.selectedInsert = INSERT_NONE;
        }
        
        return this.getInsert( this.selectedInsert );
    }
    
    this.getSelectedTray = function( )
    {
        if( typeof this.tray[ this.selectedTray ] == 'undefined' )
        {
            this.selectedTray = TRAY_NONE;
        }
        
        return this.getTray( this.selectedTray );
    }
    
    this.getTotal = function( qty )
    {
        var base = this.getBaseTotal( qty );
        var insert = this.getInsertTotal( qty );
        var tray = this.getTrayTotal( qty );
        var entrapment = this.getEntrapmentTotal( qty );
        var unit = ( base.unit + ( ( insert.total + tray.total + entrapment.total ) / qty ) );
        var total = ( base.total + insert.total + tray.total + entrapment.total );
        
        var result = { 'unit': unit, 'total': total, 'breakout': {} };
        result.breakout.base = base;
        result.breakout.insert = insert;
        result.breakout.tray = tray;
        result.breakout.entrapment = entrapment;
        
        return result;
    }
    
    this.getTray = function( name )
    {
        return this.tray[ name ];
    }
    
    this.getTrayTotal = function( qty )
    {
        return ( ( this.getSelectedTray( ) ).getTotal( qty ) );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.selectEntrapment = function( name )
    {
        //validate the specified entrapment
        if( typeof this.entrapment[ name ] == 'undefined' )
        {
            name = ENTRAPMENT_NONE;
        }
        
        //process all the entrapments
        for( var i in this.entrapment )
        {
            var entrapment = this.entrapment[ i ];
            //validate the objects
            if( entrapment instanceof Entrapment )
            {
                //select the entrapment if we have a match
                if( name == i )
                {
                    if( name == ENTRAPMENT_NONE )
                    {
                        //only select the none entrapment if the insert and tray are also none
                        var selected = ( this.selectedInsert == INSERT_NONE && this.selectedTray == TRAY_NONE );
                        entrapment.select( selected );
                    }
                    else
                    {
                        entrapment.select( true );
                    }
                    this.selectedEntrapment = name;
                }
                //deselect the insert if it doesn't match
                else
                {
                    entrapment.select( false );
                }
            }
        }
    }
    
    this.selectInsert = function( name )
    {
        //validate the specified insert
        if( typeof this.insert[ name ] == 'undefined' )
        {
            name = INSERT_NONE;
        }
        
        //process all the inserts
        for( var i in this.insert )
        {
            var insert = this.insert[ i ];
            //validate the objects
            if( insert instanceof Insert )
            {
                //select the insert if we have a match
                if( name == i )
                {
                    if( name == INSERT_NONE )
                    {
                        //only select the none insert if the entrapment and tray are also none
                        var selected = ( this.selectedEntrapment == ENTRAPMENT_NONE && this.selectedTray == TRAY_NONE );
                        insert.select( selected );
                    }
                    else
                    {
                        insert.select( true );
                    }
                    this.selectedInsert = name;
                }
                //deselect the insert if it doesnt match
                else
                {
                    insert.select( false );
                }
            }
        }
    }
    
    this.selectTray = function( name )
    {
        //validate the specified tray
        if( typeof this.tray[ name ] == 'undefined' )
        {
            name = TRAY_NONE;
        }
        
        //process all the trays
        for( var i in this.tray )
        {
            var tray = this.tray[ i ];
            //validate the objects
            if( tray instanceof Tray )
            {
                //select the tray if we have a match
                if( name == i )
                {
                    if( name == TRAY_NONE )
                    {
                        //only select the none tray if the entrapment and insert are also none
                        var selected = ( this.selectedEntrapment == ENTRAPMENT_NONE && this.selectedInsert == INSERT_NONE );
                        tray.select( selected );
                    }
                    else
                    {
                        tray.select( true );
                    }
                    this.selectedTray = name;
                }
                //deselect the tray if it doesnt match
                else
                {
                    tray.select( false );
                }
            }
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.showEntrapment = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the entrapment visibility
        var cnt = 0;
        var lastItem = undefined;
        for( var i in this.entrapment )
        {
            var isLast = ( i == ENTRAPMENT_NONE );
            lastItem = this.entrapment[ i ];
            lastItem.show( visible, isLast );
            cnt++;
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
        
        //if there is another entrapment defined other than none than show the header and spacer
        if( cnt > 1 )
        {
            if( visible )
            {
                $( '#entSpacer' ).css( 'padding-bottom', '16px' );
                $( '#entSpacer' ).show( );
                $( '#entHeader' ).show( );
            }
            else
            {
                $( '#entSpacer' ).css( 'padding-bottom', '0px' );
                $( '#entSpacer' ).hide( );
                $( '#entHeader' ).hide( );
            }
        }
    }
    
    this.showInsert = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the insert visibility
        var lastItem = undefined;
        for( var i in this.insert )
        {
            var isLast = ( i == INSERT_NONE );
            lastItem = this.insert[ i ];
            lastItem.show( visible, isLast );
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
    }
    
    this.showTray = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the tray visibility
        var cnt = 0;
        var lastItem = undefined;
        for( var i in this.tray )
        {
            var isLast = ( i == TRAY_NONE );
            lastItem = this.tray[ i ];
            lastItem.show( visible, isLast );
            cnt++;
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
        
        //if there is another tray defined other than none than show the header and spacer
        if( cnt > 1 )
        {
            if( visible )
            {
                $( '#trySpacer' ).css( 'padding-bottom', '16px' );
                $( '#trySpacer' ).show( );
                $( '#tryHeader' ).show( );
            }
            else
            {
                $( '#trySpacer' ).css( 'padding-bottom', '0px' );
                $( '#trySpacer' ).hide( );
                $( '#tryHeader' ).hide( );
            }
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the packaging total
        var unit = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( unit, 2 ) + ' \\each' );
        
        //update all the entrapment totals
        for( var i in this.entrapment )
        {
            var entrapment = this.entrapment[ i ];
            if( entrapment instanceof Entrapment )
            {
                entrapment.updateTotal( qty );
            }
        }
        //update all the insert totals
        for( var i in this.insert )
        {
            var insert = this.insert[ i ];
            if( insert instanceof Insert )
            {
                insert.updateTotal( qty );
            }
        }
        //update all the tray totals
        for( var i in this.tray )
        {
            var tray = this.tray[ i ];
            if( tray instanceof Tray )
            {
                tray.updateTotal( qty );
            }
        }
    }
    
    //Add default none objects
    this.addInsert( INSERT_NONE );
    this.addTray( TRAY_NONE );
    this.addEntrapment( ENTRAPMENT_NONE );
}

//=======================================
// FaceArt Object
//=======================================
function FaceArt( id )
{
    this.objectId = id;
    this.price = new UnitPriceList( );
    
    this.getTotal = function( qty )
    {
        var unit = this.price.get( qty );
        var total = ( unit * qty );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( qty )
    {
        //update the item total
        var unit = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( unit, 2 ) + ' \\each' );
    }
}

//=======================================
// Disc Object
//=======================================
function Disc( id )
{
    this.faceArt = {};
    this.finishing = {};
    this.max = QTY_MAX;
    this.min = QTY_MIN;
    this.objectId = id;
    this.packaging = {};
    this.price = new UnitPriceList( );
    this.selectedFaceArt = undefined;
    this.selectedFinishing = undefined;
    this.selectedPackaging = undefined;
    
    this.addFaceArt = function( name, obj )
    {
        if( !( obj instanceof FaceArt ) )
        {
            this.faceArt[ name ] = new FaceArt( name );
        }
        else
        {
            this.faceArt[ name ] = obj;
        }
    }
    
    this.addFinishing = function( name, obj )
    {
        if( !( obj instanceof Finishing ) )
        {
            this.finishing[ name ] = new Finishing( name );
        }
        else
        {
            this.finishing[ name ] = obj;
        }
    }
    
    this.addPackaging = function( name, obj )
    {
        if( !( obj instanceof Packaging ) )
        {
            this.packaging[ name ] = new Packaging( name );
        }
        else
        {
            this.packaging[ name ] = obj;
        }
    }
    
    this.getBaseTotal = function( qty )
    {
        var unit = this.price.get( qty );
        var total = ( unit * qty );
        return ( { 'unit': unit, 'total': total } );
    }
    
    this.getFaceArt = function( name )
    {
        return this.faceArt[ name ];
    }
    
    this.getFaceArtTotal = function( qty )
    {
        return ( ( this.getSelectedFaceArt( ) ).getTotal( qty ) );
    }
    
    this.getFinishing = function( name )
    {
        return this.finishing[ name ];
    }
    
    this.getFinishingTotal = function( qty )
    {
        return ( ( this.getSelectedFinishing( ) ).getTotal( qty ) );
    }
    
    this.getPackaging = function( name )
    {
        return this.packaging[ name ];
    }
    
    this.getPackagingTotal = function( qty )
    {
        return ( ( this.getSelectedPackaging( ) ).getTotal( qty ) );
    }
    
    this.getSelectedFaceArt = function( )
    {
        if( typeof this.faceArt[ this.selectedFaceArt ] == 'undefined' )
        {
            this.selectFaceArt( FACEART_NONE );
        }
        
        return this.getFaceArt( this.selectedFaceArt );
    }
    
    this.getSelectedFinishing = function( )
    {
        if( typeof this.finishing[ this.selectedFinishing ] == 'undefined' )
        {
            this.selectedFinishing = FINISH_NONE;
        }
        
        return this.getFinishing( this.selectedFinishing );
    }
    
    this.getSelectedPackaging = function( )
    {
        if( typeof this.packaging[ this.selectedPackaging ] == 'undefined' )
        {
            this.selectedPackaging = PACKAGING_NONE;
        }
        
        return this.getPackaging( this.selectedPackaging );
    }
    
    this.getTotal = function( qty )
    {
        var base = this.getBaseTotal( qty );
        var faceArt = this.getFaceArtTotal( qty );
        var packaging = this.getPackagingTotal( qty );
        var finishing = this.getFinishingTotal( qty );
        var unit = ( base.unit + faceArt.unit + packaging.unit + finishing.unit );
        var total = ( base.total + faceArt.total + packaging.total + finishing.total );
        
        var result = { 'unit': unit, 'total': total, 'breakout': {} };
        result.breakout.base = base;
        result.breakout.faceArt = faceArt;
        result.breakout.packaging = packaging;
        result.breakout.finishing = finishing;
        
        return result;
    }
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId;
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.selectFaceArt = function( name )
    {
        //validate the specified faceArt
        if( typeof this.faceArt[ name ] == 'undefined' )
        {
            name = FACEART_NONE;
        }
        
        //process all the faceArt
        for( var i in this.faceArt )
        {
            var art = this.faceArt[ i ];
            //validate the objects
            if( art instanceof FaceArt )
            {
                //select the faceArt if we have a match
                if( name == i )
                {
                    art.select( true );
                    this.selectedFaceArt = name;
                }
                //deselect the faceArt if it doesnt match
                else
                {
                    art.select( false );
                }
            }
        }
    }
    
    this.selectFinishing = function( name )
    {
        //validate the specified finishing
        if( typeof this.finishing[ name ] == 'undefined' )
        {
            name = FINISH_NONE;
        }
        
        //process all the finishing
        for( var i in this.finishing )
        {
            var finish = this.finishing[ i ];
            //validate the objects
            if( finish instanceof Finishing )
            {
                //select the finishing if we have a match
                if( name == i )
                {
                    finish.select( true );
                    this.selectedFinishing = name;
                }
                //deselect the finishing if it doesnt match
                else
                {
                    finish.select( false );
                }
            }
        }
    }
    
    this.selectPackaging = function( name )
    {
        //validate the specified packaging
        if( typeof this.packaging[ name ] == 'undefined' )
        {
            name = PACKAGING_NONE;
        }
        
        //process all the packaging
        for( var i in this.packaging )
        {
            var packaging = this.packaging[ i ];
            //validate the objects
            if( packaging instanceof Packaging )
            {
                //select the packaging if we have a match
                if( name == i )
                {
                    packaging.select( true );
                    this.selectedPackaging = name;
                }
                //deselect the packaging if it doesnt match
                else
                {
                    packaging.select( false );
                }
            }
        }
    }
    
    this.show = function( visible, isLast )
    {
        var element = '#' + this.objectId + 'Container';
        
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        //set default to not last in the list
        if( isLast === undefined )
        {
            isLast = false;
        }
        
        //update the element to account for being last
        if( isLast && !( $( element ).hasClass( 'last' ) ) )
        {
            $( element ).addClass( 'last' );
        }
        else if( !isLast && $( element ).hasClass( 'last' ) )
        {
            $( element ).removeClass( 'last' );
        }
        //show the element
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.showFaceArt = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the face art visibility
        var lastItem = undefined;
        for( var i in this.faceArt )
        {
            var isLast = ( i == FACEART_NONE );
            lastItem = this.faceArt[ i ];
            lastItem.show( visible, isLast );
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
    }
    
    this.showFinishing = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the finishing visibility
        var lastItem = undefined;
        for( var i in this.finishing )
        {
            var isLast = ( i == FINISH_NONE );
            lastItem = this.finishing[ i ];
            lastItem.show( visible, isLast );
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
    }
    
    this.showPackaging = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        //set the packaging visibility
        var lastItem = undefined;
        for( var i in this.packaging )
        {
            var isLast = ( i == PACKAGING_NONE );
            lastItem = this.packaging[ i ];
            lastItem.show( visible, isLast );
        }
        if( typeof lastItem != 'undefined' )
        {
            lastItem.show( visible, true );
        }
    }
    
    this.updateTotal = function( qty, selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        //update the item total
        var unit = this.price.get( qty );
        var element = '#' + this.objectId + 'Total';
        $( element ).html( '$' + round_number( unit, 2 ) + ' \\each' );
         
        //update child data if we are the selected item
        if( selected )
        {
            //update all the faceArt totals
            for( var i in this.faceArt )
            {
                var faceArt = this.faceArt[ i ];
                if( faceArt instanceof FaceArt )
                {
                    faceArt.updateTotal( qty );
                }
            }
            //update all the finishing totals
            for( var i in this.finishing )
            {
                var finishing = this.finishing[ i ];
                if( finishing instanceof Finishing )
                {
                    finishing.updateTotal( qty );
                }
            }
            //update all the packaging totals
            for( var i in this.packaging )
            {
                var packaging = this.packaging[ i ];
                if( packaging instanceof Packaging )
                {
                    packaging.updateTotal( qty );
                }
            }
        }
    }
    
    //Create default none objects
    this.addFaceArt( FACEART_NONE );
    this.addPackaging( PACKAGING_NONE );
    this.addFinishing( FINISH_NONE );
}

//=======================================
// Page Object
//=======================================
function Page( id )
{
    this.objectId = id;
    
    this.select = function( selected )
    {
        //set the default to selected
        if( selected === undefined )
        {
            selected = true;
        }
        
        var element = '#' + this.objectId + 'Nav';
        if( selected && !( $( element ).hasClass( 'selected' ) ) )
        {
            $( element ).addClass( 'selected' );
        }
        else if( !selected && $( element ).hasClass( 'selected' ) )
        {
            $( element ).removeClass( 'selected' );
        }
    }
    
    this.show = function( visible )
    {
        //set the default to visible
        if( visible === undefined )
        {
            visible = true;
        }
        
        var element = '#' + this.objectId;
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateTotal = function( unit, total )
    {
        var element = '#' + this.objectId;
        $( element + 'Total' ).html( '$' + round_number( total, 2 ) );
        $( element + 'Unit' ).html( '$' + round_number( unit, 2 ) + ' per unit' );
    }
}

//=======================================
// Quantity Object
//=======================================
function Quantity( id )
{
    this.count = 0;
    this.min = QTY_MIN;
    this.max = QTY_MAX;
    this.objectId = id;
    this.onUpdate = undefined;//callback function
    this.repeat = false;
    this.timer = undefined;
    
    this.getInt = function( val )
    {
        val = parseInt( val );
        if( isNaN( val ) )
        {
            val = 0;
        }
        return val;
    }
    
    this.inc = function( qty, repeat )
    {
        qty = this.getInt( qty );
        this.repeat = repeat;
        
        if( repeat )
        {
            var self = this;
            var incFunc = function( ){ self.set( self.count + qty ); if( self.repeat ){ self.timer = setTimeout( incFunc, 40 ); } };
            this.timer = setTimeout( incFunc, 350 );
        }
        else
        {
            clearTimeout( this.timer );
            this.set( this.count + qty );
        }
    }
    
    this.set = function( qty, forceUpdate )
    {
        qty = this.getInt( qty );
        
        //only do something if the count has changed
        if( forceUpdate || this.count != qty )
        {
            //validate the qty is within the min/max range 
            if( qty >= this.min && qty < this.max )
            {
                this.count = qty;
            }
            else if( qty < this.min )
            {
                this.count = this.min;
            }
            else if( qty >= this.max )
            {
                this.count = this.max;
            }
            
            //call the onUpdate callback function
            if( typeof this.onUpdate == 'function' )
            {
                this.onUpdate( this );
            }
        }
    }
    
    this.setRange = function( min, max )
    {
        this.min = this.getInt( min );
        this.max = this.getInt( max );
        this.set( this.count, true );
    }
}

//=======================================
// QuoteCart Object
//=======================================
function QuoteCart( )
{
    var self = this;
    
    this.alertId = 'alert';
    this.item = {};
    this.page = {};
    this.qty = new Quantity( 'quantity' );
    this.selectedItem = undefined;
    this.selectedPage = undefined;
    
    this.addItem = function( name, obj )
    {
        if( !( obj instanceof Disc ) )
        {
            this.item[ name ] = new Disc( name );
        }
        else
        {
            this.item[ name ] = obj;
        }
    }
    
    this.addPage = function( name, obj )
    {
        if( !( obj instanceof Page ) )
        {
            this.page[ name ] = new Page( name );
        }
        else
        {
            this.page[ name ] = obj;
        }
    }
    
    this.alert = function( msg )
    {
        $( '#' + this.alertId ).html( msg );
        this.showAlert( true );
    }
    
    this.getItem = function( name )
    {
        return this.item[ name ];
    }
    
    this.getPage = function( name )
    {
        return this.page[ name ];
    }
    
    this.getSelectedItem = function( )
    {
        if( typeof this.item[ this.selectedItem ] == 'undefined' )
        {
            this.selectedItem = TYPE_NONE;
        }
        
        return this.getItem( this.selectedItem );
    }
    
    this.getSelectedPage = function( )
    {
        if( typeof this.page[ this.selectedPage ] == 'undefined' )
        {
            this.selectedPage = PAGE_TYPE;
        }
        
        return this.getPage( this.selectedPage );
    }
    
    this.getTotal = function( )
    {
        var count = this.qty.count;
        var selectedItem = this.getSelectedItem( );
        var total = selectedItem.getTotal( count );
        total.count = count;
        
        return total;
    }
    
    this.nextPage = function( )
    {
        var found = false;
        var next = this.selectedPage;
        for( var i in this.page )
        {
            //set the next page if we already found the selected page
            if( found )
            {
                next = i;
                break;
            }
            //check to see if we found the selected page
            if( ( i == this.selectedPage ) && ( this.page[ i ] instanceof Page ) )
            {
                found = true;
            }
        }
        this.selectPage( next );
    }
    
    this.previousPage = function( )
    {
        var previous = this.selectedPage;
        for( var i in this.page )
        {
            //set the previous page
            if( this.page[ i ] instanceof Page )
            {
                if( i == this.selectedPage )
                {
                    break;
                }
                else
                {
                    previous = i;
                }
            }
        }
        this.selectPage( previous );
    }
    
    this.selectEntrapment = function( entrapment, updateTotal )
    {
        //update the total by default
        if( updateTotal === undefined )
        {
            updateTotal = true;
        }
        //select the entrapment
        var selectedItem = this.getSelectedItem( );
        var selectedPackaging = selectedItem.getSelectedPackaging( );
        selectedPackaging.selectEntrapment( entrapment );
        //update the total
        if( updateTotal )
        {
            this.updateTotal( );
        }
    }
    
    this.selectFaceArt = function( faceArt, updateTotal )
    {
        //update the total by default
        if( updateTotal === undefined )
        {
            updateTotal = true;
        }
        //select the faceArt
        ( this.getSelectedItem( ) ).selectFaceArt( faceArt );
        //update the total
        if( updateTotal )
        {
            this.updateTotal( );
        }
    }
    
    this.selectFinishing = function( finishing, updateTotal )
    {
        //update the total by default
        if( updateTotal === undefined )
        {
            updateTotal = true;
        }
        //select the finishing
        ( this.getSelectedItem( ) ).selectFinishing( finishing );
        //update the total
        if( updateTotal )
        {
            this.updateTotal( );
        }
    }
    
    this.selectInsert = function( insert, updateTotal )
    {
        //update the total by default
        if( updateTotal === undefined )
        {
            updateTotal = true;
        }
        //select the insert
        var selectedItem = this.getSelectedItem( );
        var selectedPackaging = selectedItem.getSelectedPackaging( );
        selectedPackaging.selectInsert( insert );
        //update the total
        if( updateTotal )
        {
            this.updateTotal( );
        }
    }
    
    this.selectItem = function( item )
    {
        //make sure the item is defined and not already selected
        if( ( this.item[ item ] instanceof Disc ) && ( item != this.selectedItem ) )
        {
            //process the existing selected item
            var selectedItem = this.getSelectedItem( );
            //hide the item categories
            selectedItem.showFaceArt( false );
            selectedItem.showPackaging( false );
            selectedItem.showFinishing( false );
            //deselect the item
            selectedItem.select( false );
            
            //process the new selection
            this.selectedItem = item;
            selectedItem = this.getSelectedItem( );
            //select the defaults (delay the price updates)
            selectedItem.select( true );
            this.selectFaceArt( FACEART_NONE, false );
            this.selectPackaging( PACKAGING_NONE, false );
            this.selectFinishing( FINISH_NONE, false );
            //show the defaults
            selectedItem.showFaceArt( true );
            selectedItem.showPackaging( true );
            selectedItem.showFinishing( true );
            //update the limits and totals
            this.qty.setRange( selectedItem.min, selectedItem.max );
        }
    }
    
    this.selectPackaging = function( packaging, updateTotal )
    {
        //get the selected item
        var selectedItem = this.getSelectedItem( );
        //check to see if the specified package exists and its not already selected
        var newPkg = selectedItem.getPackaging( packaging );
        if( ( packaging != selectedItem.selectedPackaging ) && ( typeof newPkg != 'undefined' ) )
        {
            //update the total by default
            if( updateTotal === undefined )
            {
                updateTotal = true;
            }
            
            //process the existing selected packaging
            var selectedPackaging = selectedItem.getSelectedPackaging( );
            //hide the packaging categories
            selectedPackaging.showEntrapment( false );
            selectedPackaging.showInsert( false );
            selectedPackaging.showTray( false );
            //deselect the item
            selectedPackaging.select( false );
            
            //process the new selection
            selectedItem.selectPackaging( packaging );
            selectedPackaging = selectedItem.getSelectedPackaging( );
            //select the defaults
            this.selectEntrapment( ENTRAPMENT_NONE, false );
            this.selectInsert( INSERT_NONE, false );
            this.selectTray( TRAY_NONE, false );
            //show the defaults
            selectedPackaging.showEntrapment( true );
            selectedPackaging.showInsert( true );
            selectedPackaging.showTray( true );
            
            //update the total
            if( updateTotal )
            {
                this.updateTotal( );
            }
        }
    }
    
    this.selectPage = function( page )
    {
        //make sure the item is defined, not already selected and not the total page
        if( ( this.page[ page ] instanceof Page ) && ( page != this.selectedPage ) && ( page != PAGE_TOTAL ) )
        {
            //process the existing page
            var selectedPage = this.getSelectedPage( );
            selectedPage.select( false );
            selectedPage.show( false );
            
            //process the new selected page
            this.selectedPage = page;
            selectedPage = this.getSelectedPage( );
            selectedPage.select( true );
            selectedPage.show( true );
        }
    }
    
    this.selectTray = function( tray, updateTotal )
    {
        //update the total by default
        if( updateTotal === undefined )
        {
            updateTotal = true;
        }
        //select the tray
        var selectedItem = this.getSelectedItem( );
        var selectedPackaging = selectedItem.getSelectedPackaging( );
        selectedPackaging.selectTray( tray );
        //update the total
        if( updateTotal )
        {
            this.updateTotal( );
        }
    }
    
    this.send = function( )
    {
        var loader = 'order_loader';
        var error = 'order_error';
        var price = this.getTotal( );
        var selectedItem = this.getSelectedItem( );
        var selectedPackaging = selectedItem.getSelectedPackaging( );
        
        ajax({
                'method': 'sitefunctions',
                'action': 'sendQuote',
                'parameters': { 
                                'quantity': price.count,
                                'discType': selectedItem.objectId,
                                'faceArtType': ( selectedItem.getSelectedFaceArt( ) ).objectId,
                                'packagingType': selectedPackaging.objectId,
                                'insertType': ( selectedPackaging.getSelectedInsert( ) ).objectId,
                                'entrapmentType': ( selectedPackaging.getSelectedEntrapment( ) ).objectId,
                                'trayType': ( selectedPackaging.getSelectedTray( ) ).objectId,
                                'finishingType': ( selectedItem.getSelectedFinishing( ) ).objectId,
                                'discTotal': price.breakout.base.total,
                                'faceArtTotal': price.breakout.faceArt.total,
                                'packagingTotal': price.breakout.packaging.total,
                                'finishingTotal': price.breakout.finishing.total,
                                'total': price.total
                               },
                'callback': function( response )
                            {
                                if( response[ 'status' ] === true )
                                {
                                    href( _DIR[ 'TOP_LEVEL' ] + 'store/checkout/' );
                                }
                                else
                                {
                                    seterror( error, response[ 'error' ] );
                                    hideloader( loader );
                                }
                            },
                'class': 'site',
                'error': error,
                'loader': { 'div' : loader }
            });
    }
    
    this.showAlert = function( visible )
    {
        if( visible === undefined )
        {
            visible = true;
        }
        
        var element = '#' + this.alertId;
        if( visible )
        {
            $( element ).show( );
        }
        else
        {
            $( element ).hide( );
        }
    }
    
    this.updateItemTotal = function( qty )
    {
        var selectedItem = this.getSelectedItem( );
        for( var i in this.item )
        {
            var item = this.item[ i ];
            if( item instanceof Disc )
            {
                item.updateTotal( qty, ( item == selectedItem ) );
            }
        }
    }
    
    this.updateTotal = function( )
    {
        var price = this.getTotal( );
        var pageType = this.getPage( PAGE_TYPE );
        var pagePackaging = this.getPage( PAGE_PACKAGING );
        var pageFinishing = this.getPage( PAGE_FINISHING );
        var pageTotal = this.getPage( PAGE_TOTAL );
        
        //update page totals
        pageType.updateTotal( price.breakout.base.unit + price.breakout.faceArt.unit, price.breakout.base.total + price.breakout.faceArt.total );
        pagePackaging.updateTotal( price.breakout.packaging.unit, price.breakout.packaging.total );
        pageFinishing.updateTotal( price.breakout.finishing.unit, price.breakout.finishing.total );
        pageTotal.updateTotal( price.unit, price.total );
        //update item totals
        this.updateItemTotal( price.count );
    }
    
    //define the callback function for quantity updates
    this.qty.onUpdate = function( qtyObj )
    {  
        if( qtyObj.count >= qtyObj.max )
        {
            self.alert( 'Please call 1.800.829.0077 or email info@cdimedia.com for assistance with orders larger then ' + qtyObj.max + '.' );
        }
        else
        {
            self.showAlert( false );
        }
        
        $( '#' + qtyObj.objectId ).attr( 'value', qtyObj.count );
        self.updateTotal( );
    };
    
    //Create default none objects
    this.addItem( TYPE_NONE );
}

//=======================================
// Create the trays
//=======================================
var TrayCard0 = new Tray( TRAY_CARD0 );
TrayCard0.price.addList( [ { 'qty': 1, 'price': 38.00 }, { 'qty': 101, 'price': 52.50 }, { 'qty': 251, 'price': 80.00 } ] );
var TrayCard4 = new Tray( TRAY_CARD4 );
TrayCard4.price.addList( [ { 'qty': 1, 'price': 40.00 }, { 'qty': 101, 'price': 75.00 }, { 'qty': 251, 'price': 125.00 } ] );
//=======================================
// Create the entrapments
//=======================================
var EntrapmentDVD = new Entrapment( ENTRAPMENT_DVD );
EntrapmentDVD.price.addList( [ { 'qty': 1, 'price': 58.00 }, { 'qty': 101, 'price': 102.50 }, { 'qty': 251, 'price': 180.00 } ] );
//=======================================
// Create the finishings
//=======================================
var FinishShrinkWrap = new Finishing( FINISH_SHRINK );
FinishShrinkWrap.price.addList( [ { 'qty': 1, 'price': 0.20 } ] );
var FinishOverWrap = new Finishing( FINISH_OVER );
FinishOverWrap.price.addList( [ { 'qty': 1, 'price': 0.15 } ] );
//=======================================
// Create the inserts
//=======================================
var Insert2Panel0 = new Insert( INSERT_2PANEL0 );
Insert2Panel0.price.addList( [ { 'qty': 1, 'price': 40.00 }, { 'qty': 101, 'price': 55.00 }, { 'qty': 251, 'price': 90.00 } ] );
var Insert4Panel0 = new Insert( INSERT_4PANEL0 );
Insert4Panel0.price.addList( [ { 'qty': 1, 'price': 60.00 }, { 'qty': 101, 'price': 112.50 }, { 'qty': 251, 'price': 195.00 } ] );
var Insert4Panel4 = new Insert( INSERT_4PANEL4 );
Insert4Panel4.price.addList( [ { 'qty': 1, 'price': 80.00 }, { 'qty': 101, 'price': 157.00 }, { 'qty': 251, 'price': 290.00 } ] );
var InsertDVD2Panel0 = new Insert( INSERT_DVD_2PANEL0 );
InsertDVD2Panel0.price.addList( [ { 'qty': 1, 'price': 43.00 }, { 'qty': 101, 'price': 67.50 }, { 'qty': 251, 'price': 105.00 } ] );
var InsertDVD2Panel4 = new Insert( INSERT_DVD_2PANEL4 );
InsertDVD2Panel4.price.addList( [ { 'qty': 1, 'price': 55.00 }, { 'qty': 101, 'price': 100.00 }, { 'qty': 251, 'price': 175.00 } ] );
var InsertDVD4Panel0 = new Insert( INSERT_DVD_4PANEL0 );
InsertDVD4Panel0.price.addList( [ { 'qty': 1, 'price': 73.00 }, { 'qty': 101, 'price': 137.50 }, { 'qty': 251, 'price': 250.00 } ] );
var InsertDVD4Panel4 = new Insert( INSERT_DVD_4PANEL4 );
InsertDVD4Panel4.price.addList( [ { 'qty': 1, 'price': 98.00 }, { 'qty': 101, 'price': 205.00 }, { 'qty': 251, 'price': 380.00 } ] );
//=======================================
// Create the packaging
//=======================================
var PackagingBlack = new Packaging( PACKAGING_BLACK );
PackagingBlack.price.addList( [ { 'qty': 1, 'price': 0.30 } ] );
PackagingBlack.addInsert( INSERT_2PANEL0, Insert2Panel0 );
PackagingBlack.addInsert( INSERT_4PANEL0, Insert4Panel0 );
PackagingBlack.addInsert( INSERT_4PANEL4, Insert4Panel4 );
PackagingBlack.addTray( TRAY_CARD0, TrayCard0 );
var PackagingClear = new Packaging( PACKAGING_CLEAR );
PackagingClear.price.addList( [ { 'qty': 1, 'price': 0.32 } ] );
PackagingClear.addInsert( INSERT_2PANEL0, Insert2Panel0 );
PackagingClear.addInsert( INSERT_4PANEL0, Insert4Panel0 );
PackagingClear.addInsert( INSERT_4PANEL4, Insert4Panel4 );
PackagingClear.addTray( TRAY_CARD0, TrayCard0 );
PackagingClear.addTray( TRAY_CARD4, TrayCard4 );
var PackagingSlimBlack = new Packaging( PACKAGING_SLIM_BLACK );
PackagingSlimBlack.price.addList( [ { 'qty': 1, 'price': 0.30 } ] );
PackagingSlimBlack.addInsert( INSERT_2PANEL0, Insert2Panel0 );
var PackagingSlimClear = new Packaging( PACKAGING_SLIM_CLEAR );
PackagingSlimClear.price.addList( [ { 'qty': 1, 'price': 0.30 } ] );
PackagingSlimClear.addInsert( INSERT_2PANEL0, Insert2Panel0 );
var PackagingDVD = new Packaging( PACKAGING_DVD );
PackagingDVD.price.addList( [ { 'qty': 1, 'price': 0.40 } ] );
PackagingDVD.addInsert( INSERT_DVD_2PANEL0, InsertDVD2Panel0 );
PackagingDVD.addInsert( INSERT_DVD_2PANEL4, InsertDVD2Panel4 );
PackagingDVD.addInsert( INSERT_DVD_4PANEL0, InsertDVD4Panel0 );
PackagingDVD.addInsert( INSERT_DVD_4PANEL4, InsertDVD4Panel4 );
PackagingDVD.addEntrapment( ENTRAPMENT_DVD, EntrapmentDVD );
var PackagingClam = new Packaging( PACKAGING_CLAM );
PackagingClam.price.addList( [ { 'qty': 1, 'price': 0.30 } ] );
var PackagingPaper = new Packaging( PACKAGING_PAPER );
PackagingPaper.price.addList( [ { 'qty': 1, 'price': 0.12 } ] );
//=======================================
// Create the items (and faceart)
//=======================================
var DiscDVD = new Disc( TYPE_DVD );
DiscDVD.min = 5;
DiscDVD.max = 700;
DiscDVD.price.addList( [ { 'qty': 1, 'price': 2.10 }, { 'qty': 10, 'price': 1.80 }, { 'qty': 25, 'price': 1.65 }, { 'qty': 50, 'price': 1.60 }, { 'qty': 100, 'price': 1.55 }, { 'qty': 200, 'price': 1.50 }, { 'qty': 300, 'price': 1.45 }, { 'qty': 400, 'price': 1.40 }, { 'qty': 500, 'price': 1.35 } ] );
DiscDVD.addFaceArt( FACEART_COLOR );
DiscDVD.faceArt[ FACEART_COLOR ].price.addList( [ { 'qty': 1, 'price': 3.90 }, { 'qty': 10, 'price': 2.20 }, { 'qty': 25, 'price': 1.20 }, { 'qty': 50, 'price': 0.85 }, { 'qty': 100, 'price': 0.75 }, { 'qty': 200, 'price': 0.70 }, { 'qty': 300, 'price': 0.65 }, { 'qty': 400, 'price': 0.60 } ] );
DiscDVD.addFaceArt( FACEART_BLACK );
DiscDVD.faceArt[ FACEART_BLACK ].price.addList( [ { 'qty': 1, 'price': 1.45 }, { 'qty': 10, 'price': 0.85 }, { 'qty': 25, 'price': 0.45 }, { 'qty': 50, 'price': 0.35 }, { 'qty': 100, 'price': 0.30 } ] );
DiscDVD.addPackaging( PACKAGING_BLACK, PackagingBlack );
DiscDVD.addPackaging( PACKAGING_CLEAR, PackagingClear );
DiscDVD.addPackaging( PACKAGING_SLIM_BLACK, PackagingSlimBlack );
DiscDVD.addPackaging( PACKAGING_SLIM_CLEAR, PackagingSlimClear );
DiscDVD.addPackaging( PACKAGING_DVD, PackagingDVD );
DiscDVD.addPackaging( PACKAGING_CLAM, PackagingClam );
DiscDVD.addPackaging( PACKAGING_PAPER, PackagingPaper );
DiscDVD.addFinishing( FINISH_SHRINK, FinishShrinkWrap );
DiscDVD.addFinishing( FINISH_OVER, FinishOverWrap );
var DiscCD = new Disc( TYPE_CD );
DiscCD.min = 5;
DiscCD.max = 700;
DiscCD.price.addList( [ { 'qty': 1, 'price': 1.40 }, { 'qty': 10, 'price': 1.15 }, { 'qty': 25, 'price': 1.05 }, { 'qty': 50, 'price': 0.95 }, { 'qty': 100, 'price': 0.85 }, { 'qty': 200, 'price': 0.80 }, { 'qty': 300, 'price': 0.75 }, { 'qty': 400, 'price': 0.70 }, { 'qty': 500, 'price': 0.65 } ] );
DiscCD.addFaceArt( FACEART_COLOR );
DiscCD.faceArt[ FACEART_COLOR ].price.addList( [ { 'qty': 1, 'price': 3.85 }, { 'qty': 10, 'price': 2.15 }, { 'qty': 25, 'price': 1.05 }, { 'qty': 50, 'price': 0.75 }, { 'qty': 100, 'price': 0.65 }, { 'qty': 200, 'price': 0.60 } ] );
DiscCD.addFaceArt( FACEART_BLACK );
DiscCD.faceArt[ FACEART_BLACK ].price.addList( [ { 'qty': 1, 'price': 1.40 }, { 'qty': 10, 'price': 0.75 }, { 'qty': 25, 'price': 0.30 }, { 'qty': 50, 'price': 0.25 } ] );
DiscCD.addPackaging( PACKAGING_BLACK, PackagingBlack );
DiscCD.addPackaging( PACKAGING_CLEAR, PackagingClear );
DiscCD.addPackaging( PACKAGING_SLIM_BLACK, PackagingSlimBlack );
DiscCD.addPackaging( PACKAGING_SLIM_CLEAR, PackagingSlimClear );
DiscCD.addPackaging( PACKAGING_DVD, PackagingDVD );
DiscCD.addPackaging( PACKAGING_CLAM, PackagingClam );
DiscCD.addPackaging( PACKAGING_PAPER, PackagingPaper );
DiscCD.addFinishing( FINISH_SHRINK, FinishShrinkWrap );
DiscCD.addFinishing( FINISH_OVER, FinishOverWrap );
var DiscMDISC = new Disc( TYPE_MDISC );
DiscMDISC.price.addList( [ { 'qty': 1, 'price': 44.95 } ] );
DiscMDISC.addPackaging( PACKAGING_CLAM );
DiscMDISC.packaging[ PACKAGING_CLAM ].price.add( 1, 0.00 );
//=======================================
// Create the quote
//=======================================
var quote = new QuoteCart( );
quote.addPage( PAGE_TYPE );
quote.addPage( PAGE_PACKAGING );
quote.addPage( PAGE_FINISHING );
quote.addPage( PAGE_TOTAL );
quote.addItem( TYPE_DVD, DiscDVD );
quote.addItem( TYPE_CD, DiscCD );
quote.addItem( TYPE_MDISC, DiscMDISC );
