--[[
    Sets Image Number sort as default for stills.

	James Zhang Oct 06, 2010   Created from GroupUS_ImageNumberSort.tls
--]]

function Execute()
    -- If this is the wrong script for the supplied image...
    if (not SanityOK("US")) then
        return
    end

    local temp = GetAttr(DEVICE_MANUFACTURER_TAG)
    if (temp ~= nil and BestWordMatchInAttr(temp, "Philips Medical Systems")) then 
        temp = ValueForTag(DEVICE_MODEL_TAG, "Any")
        if ("EPIQ 5G" ~= temp) then
            return
        end
    else
        return
    end
    
  	if (not HasAttr(INSTANCE_NUMBER_TAG)) then
        return
    end

    local seqNameStr = nil
    
	local frameTypeAttr = GetAttr(FRAME_TYPE_PROP)
	if(frameTypeAttr) then
        local sFrameType = frameTypeAttr:Get(1)
        if("Still" == sFrameType) then -- don't care about cines
            if ("Yes" == ValueForTag(COLOR_PROP)) then
                seqNameStr = "*Color Stills*" -- const string since now
            else
                seqNameStr = "*All Stills* US" -- const string since now
            end
        end
    else -- something went wrong when extracting common props
        seqNameStr = "US Sequence" -- const string since now
    end
    
    if (seqNameStr) then
        local sortHintSet = GetSortingHintSet4Sequence(seqNameStr)
        local grpHint = GetGroupingHint4Sequence(seqNameStr)

        -- Can't continue if these don't exist
        if (sortHintSet ~= nil and grpHint ~= nil) then	
            local tempSortHint = sortHintSet:GetHint("IMAGE NUMBER SORT")
            if (tempSortHint) then
                -- Re-add it as default sort hint
                sortHintSet:AddHint(tempSortHint, true)
            end
            print("works")
            -- Overwrite the sort hint set previously added
            AddImage2Sequence(seqNameStr, grpHint, sortHintSet)
        else
            ReportError("GroupUSC_ImageNumberSort:Line 48", "Sort hint set or group hint is absent.")
        end
    end
end